Multi-Polar World
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © EsIstTurnt

//@version=5
indicator("Multi-Polar World")
string1=input.string("ED",'Statistic 1',options=['GDP','GDPPC','GD','ED','M0','M1','M2','EXP','IMP','GRES','EMP',
  'ME','POP','BOT','CBBS','CPI','INTR','BLR','OE','DPI','PS','CS'],group='Statistic')
Combine=input.bool(false,'Enable (Breaks w/ Some Combinations)'   ,group='Combine Values')
Average=input.bool(false,'Combine via Average instead of Addition',group='Combine Values')
calc=input.bool(false,title='Enable Custom Formuala Calculation'  ,group='Custom Formulas')
string2=input.string("POP",'Statistic 2 (Enable "Custom Formula Calculation" Below)',
  options=['GDP','GDPPC','GD','ED','M0','M1','M2','EXP','IMP','GRES','EMP',
  'ME','POP','BOT','CBBS','CPI','INTR','BLR','OE','DPI','PS','CS'],group='Statistic')
math=input.string("/",'Math Operation'  ,options=['+','-','*','/'],group='Custom Formulas')
West=input.bool(true,'Show West'                                  ,group='Plot')
Rest=input.bool(true,'Show BRICSS'                                ,group='Plot')
Custom=input.bool(false,'Show User Selected Group of Countries'   ,group='Plot')
C1=input.string("",' Country #1of Custom Group '                  ,group='User Selected Group',tooltip='2 Character Prefix Used by TradingView, example="CA","US","EU" etc.')
C2=input.string("",' Country #2 of Custom Group'                  ,group='User Selected Group',tooltip='2 Character Prefix Used by TradingView, example="CA","US","EU" etc.')
C3=input.string("",' Country #3 of Custom Group'                  ,group='User Selected Group',tooltip='2 Character Prefix Used by TradingView, example="CA","US","EU" etc.')
C4=input.string("",' Country #4 of Custom Group'                  ,group='User Selected Group',tooltip='2 Character Prefix Used by TradingView, example="CA","US","EU" etc.')
C5=input.string("",' Country #5 of Custom Group'                  ,group='User Selected Group',tooltip='2 Character Prefix Used by TradingView, example="CA","US","EU" etc.')
C6=input.string("",' Country #6 of Custom Group'                  ,group='User Selected Group',tooltip='2 Character Prefix Used by TradingView, example="CA","US","EU" etc.')

var string Brazil       =calc? "BR"+string1+math+"BR"+string2:"BR"+string1
var string Russia       =calc? "RU"+string1+math+"RU"+string2:"RU"+string1
var string India        =calc? "IN"+string1+math+"IN"+string2:"IN"+string1
var string China        =calc? "CN"+string1+math+"CN"+string2:"CN"+string1
var string SouthAfrica  =calc? "ZA"+string1+math+"ZA"+string2:"ZA"+string1
var string SaudiArabia  =calc? "SA"+string1+math+"SA"+string2:"SA"+string1
var string Australia    =calc? "AU"+string1+math+"AU"+string2:"AU"+string1
var string Canada       =calc? "CA"+string1+math+"CA"+string2:"CA"+string1
var string NewZealand   =calc? "NZ"+string1+math+"NZ"+string2:"NZ"+string1
var string Britain      =calc? "GB"+string1+math+"GB"+string2:"GB"+string1
var string UnitedStates =calc? "US"+string1+math+"US"+string2:"US"+string1
var string EuropeanUnion=calc? "EU"+string1+math+"EU"+string2:"EU"+string1

var string Custom1=calc? C1+string1+math+C1+string2:C1+string1
var string Custom2=calc? C2+string1+math+C2+string2:C2+string1
var string Custom3=calc? C3+string1+math+C3+string2:C3+string1
var string Custom4=calc? C4+string1+math+C4+string2:C4+string1
var string Custom5=calc? C5+string1+math+C5+string2:C5+string1
var string Custom6=calc? C6+string1+math+C6+string2:C6+string1

//BRICSS
BR=request.security(Brazil       ,timeframe.period,close,ignore_invalid_symbol = true)
RU=request.security(Russia       ,timeframe.period,close,ignore_invalid_symbol = true)
IN=request.security(India        ,timeframe.period,close,ignore_invalid_symbol = true)
CN=request.security(China        ,timeframe.period,close,ignore_invalid_symbol = true)
ZA=request.security(SouthAfrica  ,timeframe.period,close,ignore_invalid_symbol = true)
SA=request.security(SaudiArabia  ,timeframe.period,close,ignore_invalid_symbol = true)
BRICSS=Average?math.avg(BR,RU,IN,CN,ZA,SA):BR+RU+IN+CN+ZA+SA

//West
AU=request.security(Australia    ,timeframe.period,close,ignore_invalid_symbol = true)
CA=request.security(Canada       ,timeframe.period,close,ignore_invalid_symbol = true)
NZ=request.security(NewZealand   ,timeframe.period,close,ignore_invalid_symbol = true)
GB=request.security(Britain      ,timeframe.period,close,ignore_invalid_symbol = true)
US=request.security(UnitedStates ,timeframe.period,close,ignore_invalid_symbol = true)
EU=request.security(EuropeanUnion,timeframe.period,close,ignore_invalid_symbol = true)
WEST=Average?math.avg(AU,CA,NZ,GB,US,EU):AU+CA+NZ+GB+US+EU

//Custom
cSym1=Custom?request.security(Custom1,timeframe.period,close, ignore_invalid_symbol = true):na
cSym2=Custom?request.security(Custom2,timeframe.period,close, ignore_invalid_symbol = true):na
cSym3=Custom?request.security(Custom3,timeframe.period,close, ignore_invalid_symbol = true):na
cSym4=Custom?request.security(Custom4,timeframe.period,close, ignore_invalid_symbol = true):na
cSym5=Custom?request.security(Custom5,timeframe.period,close, ignore_invalid_symbol = true):na
cSym6=Custom?request.security(Custom6,timeframe.period,close, ignore_invalid_symbol = true):na
CustomAvg=Average?math.avg(cSym1,cSym2,cSym3,cSym4,cSym5,cSym6):cSym1+cSym2+cSym3+cSym4+cSym5+cSym6

transpW=input.int(0,'WEST Plot Transparency'                                                    ,group='Appearance')
transpB=input.int(0,'BRICSS Plot Transparency'                                                  ,group='Appearance')
transpC=input.int(0,'User Selected Group Plot Transparency'                                     ,group='Appearance')

plot(Combine?BRICSS:na,title='BRICSS'   ,color=color.new(input.color(#ff0a0a ,'BRICSS'        ,group='Appearance'),transpB))
plot(Combine?na:Rest?BR:na,title='BR'   ,color=color.new(input.color(#ee0038 ,'BRAZIL'        ,group='Appearance'),transpB))
plot(Combine?na:Rest?RU:na,title='RU'   ,color=color.new(input.color(#d40051 ,'RUSSIA'        ,group='Appearance'),transpB))
plot(Combine?na:Rest?IN:na,title='IN'   ,color=color.new(input.color(#b20062 ,'INDIA '        ,group='Appearance'),transpB))
plot(Combine?na:Rest?CN:na,title='CN'   ,color=color.new(input.color(#8d1b68 ,'CHINA '        ,group='Appearance'),transpB))
plot(Combine?na:Rest?ZA:na,title='ZA'   ,color=color.new(input.color(#672765 ,'SOUTH AFRICA'  ,group='Appearance'),transpB))
plot(Combine?na:Rest?SA:na,title='SA'   ,color=color.new(input.color(#452a58 ,'SAUDI ARABIA'  ,group='Appearance'),transpB))
plot(Combine?WEST:na      ,title='WEST' ,color=color.new(input.color(#01bd1b ,'WEST  '        ,group='Appearance'),transpW))
plot(Combine?na:West?AU:na,title='AU'   ,color=color.new(input.color(#00b766 ,'AUSTRALIA'     ,group='Appearance'),transpW))
plot(Combine?na:West?CA:na,title='CA'   ,color=color.new(input.color(#00adad ,'CANADA'        ,group='Appearance'),transpW))
plot(Combine?na:West?NZ:na,title='NZ'   ,color=color.new(input.color(#00a0f0 ,'NEW ZEALAND'   ,group='Appearance'),transpW))
plot(Combine?na:West?GB:na,title='GB'   ,color=color.new(input.color(#008eff ,'GREAT BRITAIN' ,group='Appearance'),transpW))
plot(Combine?na:West?US:na,title='US'   ,color=color.new(input.color(#0072ff ,'UNITED STATES' ,group='Appearance'),transpW))
plot(Combine?na:West?EU:na,title='EU'   ,color=color.new(input.color(#0d3bff ,'EUROPEAN UNION',group='Appearance'),transpW))  



plot(Custom?Combine?CustomAvg:na:na,'Custom Alliance',color=color.new(input.color(#ee6600,'Color for User Selected Group',group='Appearance'),transpC))
plot(Combine?na:Custom?cSym1:na    ,'1'              ,color=color.new(input.color(#c33600,'Color for User Selection #1'  ,group='Appearance'),transpC))
plot(Combine?na:Custom?cSym2:na    ,'2'              ,color=color.new(input.color(#a94400,'Color for User Selection #2'  ,group='Appearance'),transpC))
plot(Combine?na:Custom?cSym3:na    ,'3'              ,color=color.new(input.color(#914b00,'Color for User Selection #3'  ,group='Appearance'),transpC))
plot(Combine?na:Custom?cSym4:na    ,'4'              ,color=color.new(input.color(#7b4e0c,'Color for User Selection #4'  ,group='Appearance'),transpC))
plot(Combine?na:Custom?cSym5:na    ,'5'              ,color=color.new(input.color(#684e1c,'Color for User Selection #5'  ,group='Appearance'),transpC))
plot(Combine?na:Custom?cSym6:na    ,'6'              ,color=color.new(input.color(#584b2a,'Color for User Selection #6'  ,group='Appearance'),transpC))
