Trend Trading with Currency Strength Meter
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © exlux99

//@version=5

indicator('Strong Weak Analysis', shorttitle='Currency Strength Analysis', overlay=true)

// -----------------------------------------------------------------------------


// === INPUTS ===

fast = input.int(10, minval=1, maxval=50, title='TSI slow MA period', group="Parameters Inputs")
slow = input.int(25, minval=2, maxval=50, title='TSI slow MA period', group="Parameters Inputs")
src = input(hl2, title='Index Source', group="Parameters Inputs")

length_ema = input.int(200, title="Baseline EMA Length", group="Parameters Inputs")
out_ema = ta.ema(src, length_ema)

// === /INPUTS ===

// === SERIES ===
// Current source from each indice
USD = request.security('DXY', timeframe.period, src, barmerge.gaps_off, barmerge.lookahead_on)
EUR = request.security('EXY', timeframe.period, src, barmerge.gaps_off, barmerge.lookahead_on)
NZD = request.security('ZXY', timeframe.period, src, barmerge.gaps_off, barmerge.lookahead_on)
AUD = request.security('AXY', timeframe.period, src, barmerge.gaps_off, barmerge.lookahead_on)
JPY = request.security('JXY', timeframe.period, src, barmerge.gaps_off, barmerge.lookahead_on)
CHF = request.security('SXY', timeframe.period, src, barmerge.gaps_off, barmerge.lookahead_on)
CAD = request.security('CXY', timeframe.period, src, barmerge.gaps_off, barmerge.lookahead_on)
GBP = request.security('BXY', timeframe.period, src, barmerge.gaps_off, barmerge.lookahead_on)
// Use True Strength Index, to calculate Currency Strength.
eur = ta.tsi(EUR, fast, slow)
gbp = ta.tsi(GBP, fast, slow)
jpy = ta.tsi(JPY, fast, slow)
usd = ta.tsi(USD, fast, slow)
aud = ta.tsi(AUD, fast, slow)
cad = ta.tsi(CAD, fast, slow)
chf = ta.tsi(CHF, fast, slow)
nzd = ta.tsi(NZD, fast, slow)


i_position = input.string(title = "Table Placement", defval = "Bottom Right", 
 options = ["Top Right", "Middle Right", "Bottom Right"], group = "Table Characteristics")

position = i_position == "Top Right" ? position.top_right : i_position == "Middle Right" ? position.middle_right : position.bottom_right

i_w = 10
i_h = 3
i_text_size = input.string( title = "Text Size", defval = "Normal", 
 options = ["Auto", "Tiny", "Small", "Normal", "Large", "Huge"], group = "Table Characteristics")

text_size = i_text_size == "Normal" ? size.normal : i_text_size == "Auto" ? size.auto : i_text_size == "Auto" ? size.auto : i_text_size == "Tiny" ? size.tiny
  : i_text_size == "Small" ? size.small : i_text_size == "Large" ? size.large : size.huge


var table currencyTable = table.new(position, 2, 9, border_width = 1)

aud_green = aud > cad and aud > chf and aud > eur and aud > gbp and aud > jpy and aud > nzd and aud > usd
aud_red = aud < cad and aud < chf and aud < eur and aud < gbp and aud < jpy and aud < nzd and aud < usd

cad_green = cad > aud and cad > chf and cad > eur and cad > gbp and cad > jpy and cad > nzd and cad > usd
cad_red = cad < aud and cad < chf and cad < eur and cad < gbp and cad < jpy and cad < nzd and cad < usd

chf_green = chf > cad and chf > aud and chf > eur and chf > gbp and chf > jpy and chf > nzd and chf > usd
chf_red = chf < cad and chf < aud and chf < eur and chf < gbp and chf < jpy and chf < nzd and chf < usd

eur_green = eur > chf and eur > cad and eur > aud and eur > gbp and eur > jpy and eur > nzd and eur > usd
eur_red = eur < chf and eur < cad and eur < aud and eur < gbp and eur < jpy and eur < nzd and eur < usd

gbp_green = gbp > eur and gbp > chf and gbp > cad and gbp > aud and gbp > jpy and gbp > nzd and gbp > usd
gbp_red = gbp < eur and gbp < chf and gbp < cad and gbp < aud and gbp < jpy and gbp < nzd and gbp < usd

jpy_green = jpy > gbp and jpy > eur and jpy > chf and jpy > cad and jpy > aud and jpy > nzd and jpy > usd
jpy_red = jpy < gbp and jpy < eur and jpy < chf and jpy < cad and jpy < aud and jpy < nzd and jpy < usd

nzd_green = nzd > jpy and nzd > gbp and nzd > eur and nzd >chf and nzd > cad and nzd > aud and nzd > usd
nzd_red = nzd < jpy and nzd < gbp and nzd < eur and nzd <chf and nzd < cad and nzd < aud and nzd < usd

usd_green = usd > nzd and usd > jpy and usd > gbp and usd > eur and usd > chf and usd > cad and usd > aud 
usd_red = usd < nzd and usd < jpy and usd < gbp and usd < eur and usd < chf and usd< cad and usd < aud 


table.cell(currencyTable, 0, 0, "CURRENCY", bgcolor = color.new(color.yellow,50), text_color = color.new(color.silver, 0), width = i_w, height = i_h, text_size = text_size)
table.cell(currencyTable, 0, 1, "AUD", bgcolor = aud_green? color.new(color.green,25) : aud_red? color.new(color.red,25) : color.blue, text_color = color.new(color.silver, 0), width = i_w, height = i_h, text_size = text_size)
table.cell(currencyTable, 0, 2, "CAD", bgcolor = cad_green? color.new(color.green,25) : cad_red? color.new(color.red,25) : color.blue, text_color = color.new(color.silver, 0), width = i_w, height = i_h, text_size = text_size)
table.cell(currencyTable, 0, 3, "CHF", bgcolor = chf_green? color.new(color.green,25) : chf_red? color.new(color.red,25) : color.blue, text_color = color.new(color.silver, 0), width = i_w, height = i_h, text_size = text_size)
table.cell(currencyTable, 0, 4, "EUR", bgcolor = eur_green? color.new(color.green,25) : eur_red? color.new(color.red,25) : color.blue, text_color = color.new(color.silver, 0), width = i_w, height = i_h, text_size = text_size)
table.cell(currencyTable, 0, 5, "GBP", bgcolor = gbp_green? color.new(color.green,25) : gbp_red? color.new(color.red,25) : color.blue, text_color = color.new(color.silver, 0), width = i_w, height = i_h, text_size = text_size)
table.cell(currencyTable, 0, 6, "JPY", bgcolor = jpy_green? color.new(color.green,25) : jpy_red? color.new(color.red,25) : color.blue, text_color = color.new(color.silver, 0), width = i_w, height = i_h, text_size = text_size)
table.cell(currencyTable, 0, 7, "NZD", bgcolor = nzd_green? color.new(color.green,25) : nzd_red? color.new(color.red,25) : color.blue, text_color = color.new(color.silver, 0), width = i_w, height = i_h, text_size = text_size)
table.cell(currencyTable, 0, 8, "USD", bgcolor = usd_green? color.new(color.green,25) : usd_red? color.new(color.red,25) : color.blue, text_color = color.new(color.silver, 0), width = i_w, height = i_h, text_size = text_size)

table.cell(currencyTable, 1, 0, "Strength Power TSI",bgcolor= color.new(color.yellow,50), text_color = color.new(color.silver, 0), width = i_w, height = i_h, text_size = text_size)
table.cell(currencyTable, 1, 1, str.tostring(aud), bgcolor = aud_green? color.new(color.green,25) : aud_red? color.new(color.red,25) : color.blue, text_color = color.new(color.silver, 0), width = i_w, height = i_h, text_size = text_size)
table.cell(currencyTable, 1, 2, str.tostring(cad), bgcolor = cad_green? color.new(color.green,25) : cad_red? color.new(color.red,25) : color.blue, text_color = color.new(color.silver, 0), width = i_w, height = i_h, text_size = text_size)
table.cell(currencyTable, 1, 3, str.tostring(chf), bgcolor = chf_green? color.new(color.green,25) : chf_red? color.new(color.red,25) : color.blue, text_color = color.new(color.silver, 0), width = i_w, height = i_h, text_size = text_size)
table.cell(currencyTable, 1, 4, str.tostring(eur), bgcolor = eur_green? color.new(color.green,25) : eur_red? color.new(color.red,25) : color.blue, text_color = color.new(color.silver, 0), width = i_w, height = i_h, text_size = text_size)
table.cell(currencyTable, 1, 5, str.tostring(gbp), bgcolor = gbp_green? color.new(color.green,25) : gbp_red? color.new(color.red,25) : color.blue, text_color = color.new(color.silver, 0), width = i_w, height = i_h, text_size = text_size)
table.cell(currencyTable, 1, 6, str.tostring(jpy), bgcolor = jpy_green? color.new(color.green,25) : jpy_red? color.new(color.red,25) : color.blue, text_color = color.new(color.silver, 0), width = i_w, height = i_h, text_size = text_size)
table.cell(currencyTable, 1, 7, str.tostring(nzd), bgcolor = nzd_green? color.new(color.green,25) : nzd_red? color.new(color.red,25) : color.blue, text_color = color.new(color.silver, 0), width = i_w, height = i_h, text_size = text_size)
table.cell(currencyTable, 1, 8, str.tostring(usd), bgcolor = usd_green? color.new(color.green,25) : usd_red? color.new(color.red,25) : color.blue, text_color = color.new(color.silver, 0), width = i_w, height = i_h, text_size = text_size)


plot(out_ema)
