Crypto Index (DXY) Candles
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// @ esistturnt
// Credit to @loxx for the stock DXY in pinescript


//@version=5
indicator("Crypto Index (CXY) Candles",shorttitle="CXY",overlay = false,timeframe='', timeframe_gaps = true)


greencolor = #ACFB00
redcolor = #FF0000
DXYCXY=input.bool(false,'Show Standard DXY')

sym1=DXYCXY?"EURUSD":input.string("BTCUSDTPERP",group='Symbol 1'),weight1=input.float(0.576,group='Symbol 1')
sym2=DXYCXY?"USDJPY":input.string("ETHUSDTPERP",group='Symbol 2'),weight2=input.float(0.136,group='Symbol 2')
sym3=DXYCXY?"GBPUSD":input.string("ADAUSDTPERP",group='Symbol 3'),weight3=input.float(0.119,group='Symbol 3')
sym4=DXYCXY?"USDCAD":input.string("SOLUSDTPERP",group='Symbol 4'),weight4=input.float(0.091,group='Symbol 4')
sym5=DXYCXY?"USDSEK":input.string("BNBUSDTPERP",group='Symbol 5'),weight5=input.float(0.042,group='Symbol 5')
sym6=DXYCXY?"USDCHF":input.string("XMRUSDTPERP",group='Symbol 6'),weight6=input.float(0.036,group='Symbol 6')


eurc = request.security(sym1, timeframe.period, close) 
euro = request.security(sym1, timeframe.period, open ) 
eurh = request.security(sym1, timeframe.period, high ) 
eurl = request.security(sym1, timeframe.period, low  ) 

jpyc = request.security(sym2, timeframe.period, close) 
jpyo = request.security(sym2, timeframe.period, open ) 
jpyh = request.security(sym2, timeframe.period, high ) 
jpyl = request.security(sym2, timeframe.period, low  ) 

gbpc = request.security(sym3, timeframe.period, close) 
gbpo = request.security(sym3, timeframe.period, open ) 
gbph = request.security(sym3, timeframe.period, high ) 
gbpl = request.security(sym3, timeframe.period, low  ) 

cadc = request.security(sym4, timeframe.period, close) 
cado = request.security(sym4, timeframe.period, open ) 
cadh = request.security(sym4, timeframe.period, high ) 
cadl = request.security(sym4, timeframe.period, low  ) 

sekc = request.security(sym5, timeframe.period, close) 
seko = request.security(sym5, timeframe.period, open ) 
sekh = request.security(sym5, timeframe.period, high ) 
sekl = request.security(sym5, timeframe.period, low  ) 

chfc = request.security(sym6, timeframe.period, close) 
chfo = request.security(sym6, timeframe.period, open ) 
chfh = request.security(sym6, timeframe.period, high ) 
chfl = request.security(sym6, timeframe.period, low  ) 

dxyClose =DXYCXY? 50.14348112 * math.pow(eurc, -1*weight1) *math.pow(jpyc, weight2) *
  math.pow(gbpc, -1*weight3)  * math.pow(cadc, weight4)    *
  math.pow(sekc, weight5)     * math.pow(chfc, weight6)
  :  50.14348112 * math.pow(eurc, weight1) * math.pow(jpyc, weight2) *
  math.pow(gbpc, weight3)                  * math.pow(cadc, weight4) *
  math.pow(sekc, weight5)                  * math.pow(chfc, weight6)
dxyOpen = DXYCXY? 50.14348112 * math.pow(euro, -1*weight1) * math.pow(jpyo, weight2) *
  math.pow(gbpo, -1*weight3)  * math.pow(cado, weight4)    *
  math.pow(seko, weight5)     * math.pow(chfo, weight6)
  :  50.14348112 * math.pow(euro, weight1) * math.pow(jpyo, weight2) *
  math.pow(gbpo, weight3)                  * math.pow(cado, weight4) *
  math.pow(seko, weight5)                  * math.pow(chfo, weight6)
dxyHigh = DXYCXY? 50.14348112 * math.pow(eurh, -1*weight1) * math.pow(jpyh, weight2) *
  math.pow(gbph, -1*weight3)  * math.pow(cadh, weight4)    * 
  math.pow(sekh, weight5)     * math.pow(chfh, weight6)
  :  50.14348112 * math.pow(eurh, weight1) * math.pow(jpyh, weight2) *
  math.pow(gbph, weight3)                  * math.pow(cadh, weight4) *
  math.pow(sekh, weight5)                  * math.pow(chfh, weight6)
dxyLow =  DXYCXY? 50.14348112 * math.pow(eurl, -1*weight1) * math.pow(jpyl, weight2) * 
  math.pow(gbpl, -1*weight3)  * math.pow(cadl, weight4)    * 
  math.pow(sekl, weight5)     * math.pow(chfl, weight6)
  :  50.14348112 * math.pow(eurl, weight1) * math.pow(jpyl, weight2) *
  math.pow(gbpl, weight3)                  * math.pow(cadl, weight4) *
  math.pow(sekl, weight5)                  * math.pow(chfl, weight6)
color= dxyOpen < dxyClose ? greencolor : redcolor
plotcandle(dxyOpen, dxyHigh, dxyLow, dxyClose, title='Title', color =color,bordercolor=color, wickcolor=color)