Currency Strength Index by zdmre
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © zdmre

//@version=5
indicator("Currency Strength Index by zdmre")

// INPUTs
sym8 = input.symbol("FX_IDC:TRYUSD",title = "Your Symbol", tooltip='must be xxxUSD')
ShowEUR   = input(true,"EUR")
ShowGBP   = input(true,"GBP")
ShowAUD   = input(true,"AUD")
ShowNZD   = input(true,"NZD")
ShowJPY   = input(true,"JPY")
ShowCNY   = input(true,"CNY")
ShowCAD   = input(true,"CAD")
ShowYOURs = input(true,"Your Symbol")
opt_textsize = input.string(size.small, 'Text Size', options=[size.auto, size.tiny, size.small, size.normal, size.large, size.huge])

// CALC
rma = ta.rma(close, 200)
rq_sym1 = 1 / request.security("FX_IDC:USDEUR", "240", close , barmerge.gaps_off, barmerge.lookahead_off)
sym1_rma = 1 / request.security("FX_IDC:USDEUR", "240", rma, barmerge.gaps_off, barmerge.lookahead_off)
rq_sym2 = 1 / request.security("FX_IDC:USDGBP", "240", close, barmerge.gaps_off, barmerge.lookahead_off)
sym2_rma = 1 / request.security("FX_IDC:USDGBP", "240", rma, barmerge.gaps_off, barmerge.lookahead_off)
rq_sym3 = 1 / request.security("FX_IDC:USDAUD", "240", close, barmerge.gaps_off, barmerge.lookahead_off)
sym3_rma = 1 / request.security("FX_IDC:USDAUD", "240", rma, barmerge.gaps_off, barmerge.lookahead_off)
rq_sym4 = 1 / request.security("FX_IDC:USDNZD", "240", close, barmerge.gaps_off, barmerge.lookahead_off)
sym4_rma = 1 / request.security("FX_IDC:USDNZD", "240", rma, barmerge.gaps_off, barmerge.lookahead_off)
rq_sym5 = 1 / request.security("FOREXCOM:USDJPY", "240", close, barmerge.gaps_off, barmerge.lookahead_off)
sym5_rma = 1 / request.security("FOREXCOM:USDJPY", "240", rma, barmerge.gaps_off, barmerge.lookahead_off)
rq_sym6 = 1 / request.security("FX_IDC:USDCNY", "240", close, barmerge.gaps_off, barmerge.lookahead_off)
sym6_rma = 1 / request.security("FX_IDC:USDCNY", "240", rma, barmerge.gaps_off, barmerge.lookahead_off)
rq_sym7 = 1 / request.security("FOREXCOM:USDCAD", "240", close, barmerge.gaps_off, barmerge.lookahead_off)
sym7_rma = 1 / request.security("FOREXCOM:USDCAD", "240", rma, barmerge.gaps_off, barmerge.lookahead_off)
rq_sym8 = request.security(sym8, "240", close, barmerge.gaps_off, barmerge.lookahead_off)
sym8_rma = request.security(sym8, "240", rma, barmerge.gaps_off, barmerge.lookahead_off)

str_sym1 = (rq_sym1 - sym1_rma)/rq_sym1 * 100
str_sym2 = (rq_sym2 - sym2_rma)/rq_sym2 * 100
str_sym3 = (rq_sym3 - sym3_rma)/rq_sym3 * 100
str_sym4 = (rq_sym4 - sym4_rma)/rq_sym4 * 100
str_sym5 = (rq_sym5 - sym5_rma)/rq_sym5 * 100
str_sym6 = (rq_sym6 - sym6_rma)/rq_sym6 * 100
str_sym7 = (rq_sym7 - sym7_rma)/rq_sym7 * 100
str_sym8 = (rq_sym8 - sym8_rma)/rq_sym8 * 100

// LABELs
ShowLabels = input(true, "Show Labels")
if (ShowLabels)
    style = label.style_label_left
    size = opt_textsize
    if (ShowEUR)
        label EUR_lbl = label.new(bar_index+1, str_sym1, "EUR", color=color.yellow,   style=style, textcolor=color.black, size=size), label.delete(EUR_lbl[1])
    if (ShowGBP)
        label GBP_lbl = label.new(bar_index+1, str_sym2, "GBP", color=color.green,  style=style, textcolor=color.black, size=size), label.delete(GBP_lbl[1])
    if (ShowAUD)
        label AUD_lbl = label.new(bar_index+1, str_sym3, "AUD", color=color.purple,    style=style, textcolor=color.black, size=size), label.delete(AUD_lbl [1])
    if (ShowNZD)
        label NZD_lbl = label.new(bar_index+1, str_sym4, "NZD", color=color.blue, style=style, textcolor=color.white, size=size), label.delete(NZD_lbl[1])
    if (ShowJPY)
        label JPY_lbl = label.new(bar_index+1, str_sym5, "JPY", color=color.red,   style=style, textcolor=color.black, size=size), label.delete(JPY_lbl[1])
    if (ShowCNY)
        label CNY_lbl = label.new(bar_index+1, str_sym6, "CNY", color=color.orange,   style=style, textcolor=color.black, size=size), label.delete(CNY_lbl[1])
    if (ShowCAD)
        label CAD_lbl = label.new(bar_index+1, str_sym7, "CAD", color=color.teal,style=style, textcolor=color.black, size=size), label.delete(CAD_lbl[1])
    if (ShowYOURs)
        label YOURs_lbl = label.new(bar_index+1, str_sym8, syminfo.ticker(sym8), color=color.aqua, style=style, textcolor=color.black, size=size), label.delete(YOURs_lbl[1])

// TABLE
var tbis = table.new(position.middle_right, 3, 9, frame_color=color.black, frame_width=0, border_width=1, border_color=color.black)

table.cell(tbis, 0, 0, 'Currency', bgcolor = color.blue, text_size=opt_textsize, text_color=color.white)
table.cell(tbis, 1, 0, 'Index', bgcolor = color.blue, text_size=opt_textsize, text_color=color.white)
table.cell(tbis, 2, 0, 'Day', bgcolor = color.blue, text_size=opt_textsize, text_color=color.white)
table.cell(tbis, 0, 1, 'EUR', bgcolor = color.yellow, text_size=opt_textsize, text_color=color.black)
table.cell(tbis, 0, 2, 'GBP', bgcolor = color.green, text_size=opt_textsize, text_color=color.black)
table.cell(tbis, 0, 3, 'AUD', bgcolor = color.purple, text_size=opt_textsize, text_color=color.black)
table.cell(tbis, 0, 4, 'NZD', bgcolor = color.blue, text_size=opt_textsize, text_color=color.white)
table.cell(tbis, 0, 5, 'JPY', bgcolor = color.red, text_size=opt_textsize, text_color=color.black)
table.cell(tbis, 0, 6, 'CNY', bgcolor = color.orange, text_size=opt_textsize, text_color=color.black)
table.cell(tbis, 0, 7, 'CAD', bgcolor = color.teal, text_size=opt_textsize, text_color=color.black)
table.cell(tbis, 0, 8, syminfo.ticker(sym8), bgcolor = color.aqua, text_size=opt_textsize, text_color=color.black)

table.cell(tbis, 1, 1, str.tostring(str_sym1[0], '#,##0.00'), text_color=str_sym1[0] > 0 ? color.black : color.white, text_size=opt_textsize, bgcolor= str_sym1[0] < 0 ? color.red : str_sym1[0] > 0 ? color.lime : color.black)
table.cell(tbis, 1, 2, str.tostring(str_sym2[0], '#,##0.00'), text_color=str_sym2[0] > 0 ? color.black : color.white, text_size=opt_textsize, bgcolor= str_sym2[0] < 0 ? color.red : str_sym2[0] > 0 ? color.lime : color.black)
table.cell(tbis, 1, 3, str.tostring(str_sym3[0], '#,##0.00'), text_color=str_sym3[0] > 0 ? color.black : color.white, text_size=opt_textsize, bgcolor= str_sym3[0] < 0 ? color.red : str_sym3[0] > 0 ? color.lime : color.black)
table.cell(tbis, 1, 4, str.tostring(str_sym4[0], '#,##0.00'), text_color=str_sym4[0] > 0 ? color.black : color.white, text_size=opt_textsize, bgcolor= str_sym4[0] < 0 ? color.red : str_sym4[0] > 0 ? color.lime : color.black)
table.cell(tbis, 1, 5, str.tostring(str_sym5[0], '#,##0.00'), text_color=str_sym5[0] > 0 ? color.black : color.white, text_size=opt_textsize, bgcolor= str_sym5[0] < 0 ? color.red : str_sym5[0] > 0 ? color.lime : color.black)
table.cell(tbis, 1, 6, str.tostring(str_sym6[0], '#,##0.00'), text_color=str_sym6[0] > 0 ? color.black : color.white, text_size=opt_textsize, bgcolor= str_sym6[0] < 0 ? color.red : str_sym6[0] > 0 ? color.lime : color.black)
table.cell(tbis, 1, 7, str.tostring(str_sym7[0], '#,##0.00'), text_color=str_sym7[0] > 0 ? color.black : color.white, text_size=opt_textsize, bgcolor= str_sym7[0] < 0 ? color.red : str_sym7[0] > 0 ? color.lime : color.black)
table.cell(tbis, 1, 8, str.tostring(str_sym8[0], '#,##0.00'), text_color=str_sym8[0] > 0 ? color.black : color.white, text_size=opt_textsize, bgcolor= str_sym8[0] < 0 ? color.red : str_sym8[0] > 0 ? color.lime : color.black)

table.cell(tbis, 2, 1, str.tostring((str_sym1[0]-str_sym1[1]), '#,##0.00'), text_color=(str_sym1[0]-str_sym1[1]) > 0 ? color.black : color.white, text_size=opt_textsize, bgcolor= (str_sym1[0]-str_sym1[1]) < 0 ? color.red : (str_sym1[0]-str_sym1[1]) > 0 ? color.lime : color.black)
table.cell(tbis, 2, 2, str.tostring((str_sym2[0]-str_sym2[1]), '#,##0.00'), text_color=(str_sym2[0]-str_sym2[1]) > 0 ? color.black : color.white, text_size=opt_textsize, bgcolor= (str_sym2[0]-str_sym2[1]) < 0 ? color.red : (str_sym2[0]-str_sym2[1]) > 0 ? color.lime : color.black)
table.cell(tbis, 2, 3, str.tostring((str_sym3[0]-str_sym3[1]), '#,##0.00'), text_color=(str_sym3[0]-str_sym3[1]) > 0 ? color.black : color.white, text_size=opt_textsize, bgcolor= (str_sym3[0]-str_sym3[1]) < 0 ? color.red : (str_sym3[0]-str_sym3[1]) > 0 ? color.lime : color.black)
table.cell(tbis, 2, 4, str.tostring((str_sym4[0]-str_sym4[1]), '#,##0.00'), text_color=(str_sym4[0]-str_sym4[1]) > 0 ? color.black : color.white, text_size=opt_textsize, bgcolor= (str_sym4[0]-str_sym4[1]) < 0 ? color.red : (str_sym4[0]-str_sym4[1]) > 0 ? color.lime : color.black)
table.cell(tbis, 2, 5, str.tostring((str_sym5[0]-str_sym5[1]), '#,##0.00'), text_color=(str_sym5[0]-str_sym5[1]) > 0 ? color.black : color.white, text_size=opt_textsize, bgcolor= (str_sym5[0]-str_sym5[1]) < 0 ? color.red : (str_sym5[0]-str_sym5[1]) > 0 ? color.lime : color.black)
table.cell(tbis, 2, 6, str.tostring((str_sym6[0]-str_sym6[1]), '#,##0.00'), text_color=(str_sym6[0]-str_sym6[1]) > 0 ? color.black : color.white, text_size=opt_textsize, bgcolor= (str_sym6[0]-str_sym6[1]) < 0 ? color.red : (str_sym6[0]-str_sym6[1]) > 0 ? color.lime : color.black)
table.cell(tbis, 2, 7, str.tostring((str_sym7[0]-str_sym7[1]), '#,##0.00'), text_color=(str_sym7[0]-str_sym7[1]) > 0 ? color.black : color.white, text_size=opt_textsize, bgcolor= (str_sym7[0]-str_sym7[1]) < 0 ? color.red : (str_sym7[0]-str_sym7[1]) > 0 ? color.lime : color.black)
table.cell(tbis, 2, 8, str.tostring((str_sym8[0]-str_sym8[1]), '#,##0.00'), text_color=(str_sym8[0]-str_sym8[1]) > 0 ? color.black : color.white, text_size=opt_textsize, bgcolor= (str_sym8[0]-str_sym8[1]) < 0 ? color.red : (str_sym8[0]-str_sym8[1]) > 0 ? color.lime : color.black)

// LINEs
plot(ShowEUR ? str_sym1 : na, title="EUR", color=color.yellow)
plot(ShowGBP ? str_sym2 : na, title="GBP", color=color.green)
plot(ShowAUD ? str_sym3 : na, title="AUD", color=color.purple)
plot(ShowNZD ? str_sym4 : na, title="NZD", color=color.blue)
plot(ShowJPY ? str_sym5 : na, title="JPY", color=color.red)
plot(ShowCNY ? str_sym6 : na, title="CNY", color=color.orange)
plot(ShowCAD ? str_sym7 : na, title="CAD", color=color.teal)
plot(ShowYOURs ? str_sym8 : na, title="Your Symbol", color=color.aqua)

bandh = hline(5, title= "Upper Band", color=color.new(#787B86, 50), display=display.none)
band0 = hline(0, title= "USD", color=color.new(#787B86, 0))
bandl = hline(-5, title= "Lower Band", color=color.new(#787B86, 50), display=display.none)