Indicator · Pine Script v5 · Own pane

Currency Strength Chart

by itmakesyousick· code credited to boitoki

This indicator calculates and visualizes the relative strength of major forex currencies in a separate pane.

View on GitHub

GitHub stars3on the repository
Pine versionv5runs as is
Lines of code645
Settings40inputs
LicenceNone statedfile: MPL-2.0
Last update4 years ago5 Aug 2022

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

645 lines of Pine Script v5 from v34.0.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

v34.0.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © boitoki

//@version=5
//@see https://currency-strength.com/
//@see https://currency-strength.com/about.html
indicator('Currency Strength Chart', overlay=false, precision=2, max_labels_count=100, max_lines_count=100)

// import
import boitoki/AwesomeColor/3 as ac
import boitoki/ma_function/3 as ma

////////////////////
// Defines
////////////////////
noneColor = color.new(color.black, 100)
GP1 = 'General:'
GP2 = 'Display:'
GP3 = 'Colors:'
GP4 = 'Panel:'
GP5 = 'Source:'
GP6 = 'Options:'
GP7 = 'Line style:'
GP8 = 'Label style:'
GP9 = 'Currency pair strength:'
EUR_FLAG = '🇪🇺'
USD_FLAG = '🇺🇸'
JPY_FLAG = '🇯🇵'
CHF_FLAG = '🇨🇭'
GBP_FLAG = '🇬🇧'
AUD_FLAG = '🇦🇺'
CAD_FLAG = '🇨🇦'
NZD_FLAG = '🇳🇿'
t_reso_customize = 'Resolution'
t_reso_lookback = 'Lookback periods'
t_reso_auto = 'Auto'
t_calc_every = 'every ticks'
t_calc_after = 'after the bar closed'
t_histogram_option1 = 'Lines only'
t_histogram_option2 = 'Histogram'
t_histogram_option3 = 'Without lines'

////////////////////
// Functions
////////////////////
f_reso (_mode, _auto, _input) => 
    switch _mode
        t_reso_auto => _auto
        t_reso_lookback => timeframe.period
        t_reso_customize => _input
        => _input

f_calculated_by (_type, _source, _length, _smooth) =>
    switch _type
        'RSI' => ta.rsi(_source, _length)
        'CCI' => ta.cci(_source, _length) + 1000
        'Stochastics' => ta.sma(ta.stoch(_source, high, low, _length), _smooth)
        => _source

f_color (_name, _a, _b, _c, _d, _e) =>
    switch _name
        'monokai' => _a
        'monokaipro' => _b
        'panda' => _c
        'trading view' => _d
        => _e

f_matched_currency_a_by_ticker (_name) => str.startswith(syminfo.ticker, _name)

f_matched_name_by_ticker (_name) => str.contains(syminfo.ticker, _name)

////////////////////
// Inputs
////////////////////
reso_autovalue = not timeframe.isintraday ? '12M' : timeframe.multiplier >= 60 ? 'W' : timeframe.multiplier >= 240 ? 'M' : 'D'
i_reso_mode = input.string(defval=t_reso_auto, title='Mode', options=[t_reso_auto, t_reso_customize, t_reso_lookback], group=GP1)
i_reso_value = input.timeframe(defval='D', title='Resolution', group=GP1, tooltip='When you choose the "Resolution" on the mode.')
i_reso_lookback = i_reso_mode == t_reso_lookback ? input.int(defval=100, title='Lookback periods', minval=1, group=GP1, tooltip='When you choose the "Lookback periods" on the mode.') : 1
i_broker = input.string(title='Brokers', options=['OANDA', 'FOREXCOM', 'SAXO', 'FX_IDC', 'FX'], defval='OANDA', group=GP1)
i_calclate = input.string(defval=t_calc_after, title='Calculated on', options=[t_calc_after, t_calc_every], group=GP1)

reso = f_reso(i_reso_mode, reso_autovalue, i_reso_value)
should_be_calclated = i_calclate == t_calc_after ? barstate.isconfirmed : true

////////////////////
// Source
////////////////////
i_source = input.source(defval=close, title='Source', group=GP5)
i_calc = input.string(defval='Price', title='Calculated by', options=['Price', 'RSI', 'CCI', 'Stochastics'], inline='calc', group=GP5)
i_length = input.int(defval=7, title='', inline='calc', group=GP5, tooltip='A value that is valid for non `Price`.')
i_smoothtype = input.string(defval='SMA', title='Smoothing', options=['SMA', 'EMA', 'RMA', 'WMA', 'VWMA', 'HMA', 'LSMA', 'ALMA', 'SWMA', 'TMA', 'DEMA', 'TEMA', 'MAV', 'KAMA', 'ZLEMA', 'AMA'], inline='smooth', group=GP5)
i_smooth = input.int(defval=1, title='', minval=1, inline='smooth', group=GP5)
source = f_calculated_by(i_calc, i_source, i_length, 3)

////////////////////
// Display
////////////////////
is_autoSelect = input.string(defval='No', title='Auto selected', options=['Yes', 'No'], inline='10', group=GP2) == 'Yes'
is_histogram = input.string(t_histogram_option1, title='', options=[t_histogram_option1, t_histogram_option2, t_histogram_option3], inline='10', group=GP2)
is_histogram_without_lines = is_histogram == t_histogram_option3

show_lines = not is_histogram_without_lines
show_fill = show_lines and is_autoSelect
show_histogram = is_histogram != t_histogram_option1

show_EUR    = input.bool(title='EUR', defval=true, group=GP2, inline='eur')
c_eur       = input.color(title='', defval=color.red, group=GP2, inline='eur')
i_eur_width = input.int(title='', defval=2, options=[1,2,3,4,5,6,7,8,9,10], group=GP2, inline='eur')
show_USD    = input.bool(title='USD', defval=true, group=GP2, inline='usd')
c_usd       = input.color(title='', defval=color.orange, group=GP2, inline='usd')
i_usd_width = input.int(title='', defval=2, options=[1,2,3,4,5,6,7,8,9,10], group=GP2, inline='usd')
show_JPY    = input.bool(title='JPY', defval=true, group=GP2, inline='jpy')
c_jpy       = input.color(title='', defval=color.aqua, group=GP2, inline='jpy')
i_jpy_width = input.int(title='', defval=2, options=[1,2,3,4,5,6,7,8,9,10], group=GP2, inline='jpy')
show_GBP    = input.bool(title='GBP', defval=true, group=GP2, inline='gbp')
c_gbp       = input.color(title='', defval=color.green, group=GP2, inline='gbp')
i_gbp_width = input.int(title='', defval=2, options=[1,2,3,4,5,6,7,8,9,10], group=GP2, inline='gbp')
show_CHF    = input.bool(title='CHF', defval=true, group=GP2, inline='chf')
c_chf       = input.color(title='', defval=color.maroon, group=GP2, inline='chf')
i_chf_width = input.int(title='', defval=2, options=[1,2,3,4,5,6,7,8,9,10], group=GP2, inline='chf')
show_AUD    = input.bool(title='AUD', defval=true, group=GP2, inline='aud')
c_aud       = input.color(title='', defval=color.blue, group=GP2, inline='aud')
i_aud_width = input.int(title='', defval=2, options=[1,2,3,4,5,6,7,8,9,10], group=GP2, inline='aud')
show_CAD    = input.bool(title='CAD', defval=true, group=GP2, inline='cad')
c_cad       = input.color(title='', defval=color.purple, group=GP2, inline='cad')
i_cad_width = input.int(title='', defval=2, options=[1,2,3,4,5,6,7,8,9,10], group=GP2, inline='cad')
show_NZD    = input.bool(title='NZD', defval=true, group=GP2, inline='nzd')
c_nzd       = input.color(title='', defval=color.fuchsia, group=GP2, inline='nzd')
i_nzd_width = input.int(title='', defval=2, options=[1,2,3,4,5,6,7,8,9,10], group=GP2, inline='nzd')
show_XAU    = input.bool(title='XAU', defval=false,group=GP2, inline='xau')
c_xau       = input.color(title='', defval=#D7BE69, group=GP2, inline='xau')
i_xau_width = input.int(title='', defval=2, options=[1,2,3,4,5,6,7,8,9,10], group=GP2, inline='xau')
show_XAG    = input.bool(title='XAG', defval=false, group=GP2, inline='xag')
c_xag       = input.color(title='', defval=color.silver, group=GP2, inline='xag')
i_xag_width = input.int(title='', defval=2, options=[1,2,3,4,5,6,7,8,9,10], group=GP2, inline='xag')
show_OIL    = input.bool(title='OIL', defval=false, group=GP2, inline='oil')
c_oil       = input.color(title='', defval=#745433, group=GP2, inline='oil')
i_oil_width = input.int(title='', defval=2, options=[1,2,3,4,5,6,7,8,9,10], group=GP2, inline='oil')

i_theme = input.string(title="Color theme", defval="monokai", options=["monokai", "monokai pro", "panda", "trading view", "customize"], group=GP2)
i_histogram_color = input.string(defval="Flat", title="Histogram color is", options=['Flat', 'Depth'], group=GP2)
should_be_text_black = (i_theme == 'monokai' or i_theme == 'monokai pro' or i_theme == 'panda')

if is_autoSelect
    show_EUR := f_matched_name_by_ticker('EUR'), show_USD := f_matched_name_by_ticker('USD'), show_JPY := f_matched_name_by_ticker('JPY')
    show_GBP := f_matched_name_by_ticker('GBP'), show_CHF := f_matched_name_by_ticker('CHF'), show_AUD := f_matched_name_by_ticker('AUD')
    show_CAD := f_matched_name_by_ticker('CAD'), show_NZD := f_matched_name_by_ticker('NZD')
    show_XAU := false, show_XAG := false, show_OIL := false


var float v1_EURUSD = na, var float v2_EURUSD = na
var float v1_USDJPY = na, var float v2_USDJPY = na
var float v1_USDCHF = na, var float v2_USDCHF = na
var float v1_GBPUSD = na, var float v2_GBPUSD = na
var float v1_AUDUSD = na, var float v2_AUDUSD = na
var float v1_USDCAD = na, var float v2_USDCAD = na
var float v1_NZDUSD = na, var float v2_NZDUSD = na
var float v1_XAUUSD = na, var float v2_XAUUSD = na
var float v1_XAGUSD = na, var float v2_XAGUSD = na
var float v1_OILUSD = na, var float v2_OILUSD = na

v1_EURUSD := should_be_calclated ? request.security(i_broker + ':EURUSD', timeframe.period, source) : v1_EURUSD[1]
v1_USDJPY := should_be_calclated ? request.security(i_broker + ':USDJPY', timeframe.period, source) : v1_USDJPY[1]
v1_USDCHF := should_be_calclated ? request.security(i_broker + ':USDCHF', timeframe.period, source) : v1_USDCHF[1]
v1_GBPUSD := should_be_calclated ? request.security(i_broker + ':GBPUSD', timeframe.period, source) : v1_GBPUSD[1]
v1_AUDUSD := should_be_calclated ? request.security(i_broker + ':AUDUSD', timeframe.period, source) : v1_AUDUSD[1]
v1_USDCAD := should_be_calclated ? request.security(i_broker + ':USDCAD', timeframe.period, source) : v1_USDCAD[1]
v1_NZDUSD := should_be_calclated ? request.security(i_broker + ':NZDUSD', timeframe.period, source) : v1_NZDUSD[1]
v1_XAUUSD := should_be_calclated and show_XAU ? request.security(i_broker + ':XAUUSD', timeframe.period, source) : v1_XAUUSD[1]
v1_XAGUSD := should_be_calclated and show_XAG ? request.security(i_broker + ':XAGUSD', timeframe.period, source) : v1_XAGUSD[1]
v1_OILUSD := should_be_calclated and show_OIL ? request.security('USOIL', timeframe.period, source) : v1_OILUSD[1]

v2_EURUSD := should_be_calclated ? request.security(i_broker + ':EURUSD', reso, source[i_reso_lookback], barmerge.gaps_off, barmerge.lookahead_on) : v2_EURUSD[1]
v2_USDJPY := should_be_calclated ? request.security(i_broker + ':USDJPY', reso, source[i_reso_lookback], barmerge.gaps_off, barmerge.lookahead_on) : v2_USDJPY[1]
v2_USDCHF := should_be_calclated ? request.security(i_broker + ':USDCHF', reso, source[i_reso_lookback], barmerge.gaps_off, barmerge.lookahead_on) : v2_USDCHF[1]
v2_GBPUSD := should_be_calclated ? request.security(i_broker + ':GBPUSD', reso, source[i_reso_lookback], barmerge.gaps_off, barmerge.lookahead_on) : v2_GBPUSD[1]
v2_AUDUSD := should_be_calclated ? request.security(i_broker + ':AUDUSD', reso, source[i_reso_lookback], barmerge.gaps_off, barmerge.lookahead_on) : v2_AUDUSD[1]
v2_USDCAD := should_be_calclated ? request.security(i_broker + ':USDCAD', reso, source[i_reso_lookback], barmerge.gaps_off, barmerge.lookahead_on) : v2_USDCAD[1]
v2_NZDUSD := should_be_calclated ? request.security(i_broker + ':NZDUSD', reso, source[i_reso_lookback], barmerge.gaps_off, barmerge.lookahead_on) : v2_NZDUSD[1]
v2_XAUUSD := should_be_calclated and show_XAU ? request.security(i_broker + ':XAUUSD', reso, source[i_reso_lookback], barmerge.gaps_off, barmerge.lookahead_on) : v2_XAUUSD[1]
v2_XAGUSD := should_be_calclated and show_XAU ? request.security(i_broker + ':XAGUSD', reso, source[i_reso_lookback], barmerge.gaps_off, barmerge.lookahead_on) : v2_XAGUSD[1]
v2_OILUSD := should_be_calclated and show_OIL ? request.security('USOIL', reso, source[i_reso_lookback], barmerge.gaps_off, barmerge.lookahead_on) : v2_OILUSD[1]

////////////////////
// Other settings
////////////////////

// Labels
show_labels = input.bool(title='Name label', defval=true, group=GP8)
i_label_size = input.string(title='Label size', options=[size.auto, size.tiny, size.small, size.normal, size.large, size.huge], defval=size.normal, group=GP8)
i_label_offset = input.int(title='Label offset', defval=5, minval=0, group=GP8, inline='connected line')
i_label_style = label.style_label_left
i_line_style = input.string(title='', defval=line.style_dotted, options=[line.style_solid, line.style_dotted, line.style_dashed], group=GP8, inline="connected line")

x1_label = bar_index + i_label_offset
x1_line = bar_index
x2_line = x1_label

// Panel
show_panel = input.bool(title='Panel', defval=true, group=GP4)
i_tableYpos = input.string('top', title='Position', options = ['top', 'middle', 'bottom'], inline='11', group=GP4)
i_tableXpos = input.string('right', title='', options=['left', 'center', 'right'], inline='11', group=GP4)
i_panel_position = i_tableYpos + '_' + i_tableXpos
i_panel_flagsize = input.string(title='Flag size', defval=size.large, options=[size.auto, size.tiny, size.small, size.normal, size.large, size.huge], group=GP4)
i_panel_textsize = input.string(title='Text size', defval=size.normal, options=[size.auto, size.tiny, size.small, size.normal, size.large, size.huge], group=GP4)
i_panel_theme = 'multi'     // input.string(title='Color', defval='multi', options=['multi', 'green', 'blue', 'orange', 'red', 'black', 'white', 'night', 'carbon'], group=GP4)

// Currency pair strength
show_pair = input.bool(title="Currency pair strength", defval=false, group=GP9)
i_pair_offset = show_pair ? input.int(defval=100, title="Position offset", options=[0,20,40,60,80,100,120,140,160,180,200], group=GP9) : 0
i_pair_margin = input.int(defval=4, title="Position margin", options=[0,2,4,6,8,10,16,20], group=GP9)
i_pair_labelcolor = input.color(defval=color.gray, title="Label color", group=GP9)

// Options
show_levels = input.bool(title='Level lines', defval=false, group=GP6)
i_levels = input.int(title='Level (±)', minval=1, defval=10, group=GP6)
c_levels = show_levels ? color.gray : na


// Color themes
c_green = ac.tradingview('green')
c_red   = ac.tradingview('red')
c_black = ac.tradingview('black')
c_eur   := f_color(i_theme, ac.monokai('pink'), ac.monokaipro('pink'), ac.panda('red'), ac.tradingview_flag('red'), c_eur)
c_usd   := f_color(i_theme, ac.monokai('orange'), ac.monokaipro('orange'), ac.panda('orange'), ac.tradingview_flag('orange'), c_usd)
c_jpy   := f_color(i_theme, c_jpy, c_jpy, c_jpy, ac.tradingview_flag('cyan'), c_jpy)
c_gbp   := f_color(i_theme, ac.monokai('green'), ac.monokaipro('green'), ac.panda('green'), ac.tradingview_flag('green'), c_gbp)
c_cad   := f_color(i_theme, ac.monokai('purple'), ac.monokaipro('purple'), ac.panda('purple'), ac.tradingview_flag('purple'), c_cad)
c_aud   := f_color(i_theme, ac.monokai('blue'), ac.monokaipro('blue'), ac.panda('blue'), ac.tradingview_flag('blue'), c_aud)
c_green := f_color(i_theme, ac.monokai('green'), ac.monokaipro('green'), ac.panda('green'), ac.tradingview_flag('green'), c_green)
c_red   := f_color(i_theme, ac.monokai('pink'), ac.monokaipro('pink'), ac.panda('red'), ac.tradingview_flag('red'), c_red)
c_black := f_color(i_theme, ac.monokai('black'), ac.monokaipro('black'), ac.panda('very-dark-gray'), c_black, c_black)

////////////////////
// Functions
////////////////////
get_value_by_name (v, _EUR, _USD, _JPY, _CHF, _GBP, _AUD, _CAD, _NZD) =>
    v == 'EUR' ? _EUR : v == 'USD' ? _USD : v == 'JPY' ? _JPY : v == 'CHF' ? _CHF : v == 'GBP' ? _GBP : v == 'AUD' ? _AUD : v == 'CAD' ? _CAD : v == 'NZD' ? _NZD : na

get_name_by_value(v, _EUR, _USD, _JPY, _CHF, _GBP, _AUD, _CAD, _NZD) =>
    v == _EUR ? 'EUR' : v == _USD ? 'USD' : v == _JPY ? 'JPY' : v == _CHF ? 'CHF' : v == _GBP ? 'GBP' : v == _AUD ? 'AUD' : v == _CAD ? 'CAD' : v == _NZD ? 'NZD' : na

get_color_by_value(v, _EUR, _USD, _JPY, _CHF, _GBP, _AUD, _CAD, _NZD) =>
    v == _EUR ? c_eur : v == _USD ? c_usd : v == _JPY ? c_jpy : v == _CHF ? c_chf : v == _GBP ? c_gbp : v == _AUD ? c_aud : v == _CAD ? c_cad : v == _NZD ? c_nzd : na

get_flag_by_value(v, _EUR, _USD, _JPY, _CHF, _GBP, _AUD, _CAD, _NZD) =>
    v == _EUR ? EUR_FLAG : v == _USD ? USD_FLAG : v == _JPY ? JPY_FLAG : v == _CHF ? CHF_FLAG : v == _GBP ? GBP_FLAG : v == _AUD ? AUD_FLAG : v == _CAD ? CAD_FLAG : v == _NZD ? NZD_FLAG : na

get_pair_by_value (_v, _EURUSD, _USDJPY, _USDCHF, _GBPUSD, _AUDUSD , _USDCAD, _NZDUSD, _GBPJPY) =>
    _v == _EURUSD ? 'EUR\nUSD' : _v == _USDJPY ? 'USD\nJPY' : _v == _USDCHF ? 'USD\nCHF' : _v == _GBPUSD ? 'GBP\nUSD' : _v == _AUDUSD ? 'AUD\nUSD' : _v == _USDCAD ? 'USD\nCAD' : _v == _NZDUSD ? 'NZD\nUSD' : _v == _GBPJPY ? 'GBP\nJPY' : na

get_val(_v1, _v2) =>
    float res = 0

    if _v2 == 0
        res := 0
        res
    else
        res := math.log(_v1 / _v2) * 10000
        res

    res

get_val_m(_v1, _v2, _v3, _v4) =>
    float res = 0
    float v1 = _v1 * _v3
    float v2 = _v2 * _v4

    if _v2 == 0
        res := 0
        res
    else
        res := math.log(v1 / v2) * 10000
        res

    res

get_val_d(_v1, _v2, _v3, _v4) =>
    float res = 0

    if _v3 == 0 or _v4 == 0
        res := 0
        res
    else
        float v1 = _v1 / _v3
        float v2 = _v2 / _v4

        if v2 == 0
            res := 0
            res
        else
            res := math.log(v1 / v2) * 10000
            res

    res


////////////////////
// Calculating
////////////////////
var float EURUSD = na
var float USDJPY = na
var float USDCHF = na
var float GBPUSD = na
var float AUDUSD = na
var float USDCAD = na
var float NZDUSD = na
var float XAUUSD = na
var float XAGUSD = na
var float OILUSD = na
var float EURJPY = na
var float EURCHF = na
var float EURGBP = na
var float EURCAD = na
var float EURAUD = na
var float EURNZD = na
var float EURXAU = na
var float EURXAG = na
var float EUROIL = na
var float GBPCHF = na
var float GBPJPY = na
var float GBPCAD = na
var float GBPAUD = na
var float GBPNZD = na
var float AUDCHF = na
var float AUDJPY = na
var float AUDCAD = na
var float AUDNZD = na
var float NZDCAD = na
var float NZDCHF = na
var float NZDJPY = na
var float CADJPY = na
var float CADCHF = na
var float CHFJPY = na
var float XAUJPY = na
var float XAUCHF = na
var float XAUGBP = na
var float XAUCAD = na
var float XAUAUD = na
var float XAUNZD = na
var float XAGJPY = na
var float XAGCHF = na
var float XAGGBP = na
var float XAGCAD = na
var float XAGAUD = na
var float XAGNZD = na
var float OILJPY = na
var float OILCHF = na
var float OILGBP = na
var float OILCAD = na
var float OILAUD = na
var float OILNZD = na
var float OILXAU = na

EURUSD := should_be_calclated ? get_val(v1_EURUSD, v2_EURUSD) : EURUSD[1]
USDJPY := should_be_calclated ? get_val(v1_USDJPY, v2_USDJPY) : USDJPY[1]
USDCHF := should_be_calclated ? get_val(v1_USDCHF, v2_USDCHF) : USDCHF[1]
GBPUSD := should_be_calclated ? get_val(v1_GBPUSD, v2_GBPUSD) : GBPUSD[1]
AUDUSD := should_be_calclated ? get_val(v1_AUDUSD, v2_AUDUSD) : AUDUSD[1]
USDCAD := should_be_calclated ? get_val(v1_USDCAD, v2_USDCAD) : USDCAD[1]
NZDUSD := should_be_calclated ? get_val(v1_NZDUSD, v2_NZDUSD) : NZDUSD[1]
XAUUSD := should_be_calclated ? get_val(v1_XAUUSD, v2_XAUUSD) : XAUUSD[1]
XAGUSD := should_be_calclated ? get_val(v1_XAGUSD, v2_XAGUSD) : XAGUSD[1]
OILUSD := should_be_calclated ? get_val(v1_OILUSD, v2_OILUSD) : OILUSD[1]
EURJPY := should_be_calclated ? get_val_m(v1_EURUSD, v2_EURUSD, v1_USDJPY, v2_USDJPY) : EURJPY[1]
EURCHF := should_be_calclated ? get_val_m(v1_EURUSD, v2_EURUSD, v1_USDCHF, v2_USDCHF) : EURCHF[1]
EURGBP := should_be_calclated ? get_val_d(v1_EURUSD, v2_EURUSD, v1_GBPUSD, v2_GBPUSD) : EURGBP[1]
EURCAD := should_be_calclated ? get_val_m(v1_EURUSD, v2_EURUSD, v1_USDCAD, v2_USDCAD) : EURCAD[1]
EURAUD := should_be_calclated ? get_val_d(v1_EURUSD, v2_EURUSD, v1_AUDUSD, v2_AUDUSD) : EURAUD[1]
EURNZD := should_be_calclated ? get_val_d(v1_EURUSD, v2_EURUSD, v1_NZDUSD, v2_NZDUSD) : EURNZD[1]
EURXAU := should_be_calclated ? get_val_d(v1_EURUSD, v2_EURUSD, v1_XAUUSD, v2_XAUUSD) : EURXAU[1]
EURXAG := should_be_calclated ? get_val_d(v1_EURUSD, v2_EURUSD, v1_XAGUSD, v2_XAGUSD) : EURXAG[1]
EUROIL := should_be_calclated ? get_val_d(v1_EURUSD, v2_EURUSD, v1_OILUSD, v2_OILUSD) : EUROIL[1]
GBPCHF := should_be_calclated ? get_val_m(v1_GBPUSD, v2_GBPUSD, v1_USDCHF, v2_USDCHF) : GBPCHF[1]
GBPJPY := should_be_calclated ? get_val_m(v1_GBPUSD, v2_GBPUSD, v1_USDJPY, v2_USDJPY) : GBPJPY[1]
GBPCAD := should_be_calclated ? get_val_m(v1_GBPUSD, v2_GBPUSD, v1_USDCAD, v2_USDCAD) : GBPCAD[1]
GBPAUD := should_be_calclated ? get_val_d(v1_GBPUSD, v2_GBPUSD, v1_AUDUSD, v2_AUDUSD) : GBPAUD[1]
GBPNZD := should_be_calclated ? get_val_d(v1_GBPUSD, v2_GBPUSD, v1_NZDUSD, v2_NZDUSD) : GBPNZD[1]
AUDCHF := should_be_calclated ? get_val_m(v1_AUDUSD, v2_AUDUSD, v1_USDCHF, v2_USDCHF) : AUDCHF[1]
AUDJPY := should_be_calclated ? get_val_m(v1_AUDUSD, v2_AUDUSD, v1_USDJPY, v2_USDJPY) : AUDJPY[1]
AUDCAD := should_be_calclated ? get_val_m(v1_AUDUSD, v2_AUDUSD, v1_USDCAD, v2_USDCAD) : AUDCAD[1]
AUDNZD := should_be_calclated ? get_val_d(v1_AUDUSD, v2_AUDUSD, v1_NZDUSD, v2_NZDUSD) : AUDNZD[1]
NZDCAD := should_be_calclated ? get_val_m(v1_NZDUSD, v2_NZDUSD, v1_USDCAD, v2_USDCAD) : NZDCAD[1]
NZDCHF := should_be_calclated ? get_val_m(v1_NZDUSD, v2_NZDUSD, v1_USDCHF, v2_USDCHF) : NZDCHF[1]
NZDJPY := should_be_calclated ? get_val_m(v1_NZDUSD, v2_NZDUSD, v1_USDJPY, v2_USDJPY) : NZDJPY[1]
CADJPY := should_be_calclated ? get_val_d(v1_USDJPY, v2_USDJPY, v1_USDCAD, v2_USDCAD) : CADJPY[1]
CADCHF := should_be_calclated ? get_val_d(v1_USDCHF, v2_USDCHF, v1_USDCAD, v2_USDCAD) : CADCHF[1]
CHFJPY := should_be_calclated ? get_val_d(v1_USDJPY, v2_USDJPY, v1_USDCHF, v2_USDCHF) : CHFJPY[1]
XAUJPY := should_be_calclated ? get_val_m(v1_XAUUSD, v2_XAUUSD, v1_USDJPY, v2_USDJPY) : XAUJPY[1]
XAUCHF := should_be_calclated ? get_val_m(v1_XAUUSD, v2_XAUUSD, v1_USDCHF, v2_USDCHF) : XAUCHF[1]
XAUGBP := should_be_calclated ? get_val_d(v1_XAUUSD, v2_XAUUSD, v1_GBPUSD, v2_GBPUSD) : XAUGBP[1]
XAUCAD := should_be_calclated ? get_val_m(v1_XAUUSD, v2_XAUUSD, v1_USDCAD, v2_USDCAD) : XAUCAD[1]
XAUAUD := should_be_calclated ? get_val_d(v1_XAUUSD, v2_XAUUSD, v1_AUDUSD, v2_AUDUSD) : XAUAUD[1]
XAUNZD := should_be_calclated ? get_val_d(v1_XAUUSD, v2_XAUUSD, v1_NZDUSD, v2_NZDUSD) : XAUNZD[1]
XAGJPY := should_be_calclated ? get_val_m(v1_XAGUSD, v2_XAGUSD, v1_USDJPY, v2_USDJPY) : XAGJPY[1]
XAGCHF := should_be_calclated ? get_val_m(v1_XAGUSD, v2_XAGUSD, v1_USDCHF, v2_USDCHF) : XAGCHF[1]
XAGGBP := should_be_calclated ? get_val_d(v1_XAGUSD, v2_XAGUSD, v1_GBPUSD, v2_GBPUSD) : XAGGBP[1]
XAGCAD := should_be_calclated ? get_val_m(v1_XAGUSD, v2_XAGUSD, v1_USDCAD, v2_USDCAD) : XAGCAD[1]
XAGAUD := should_be_calclated ? get_val_d(v1_XAGUSD, v2_XAGUSD, v1_AUDUSD, v2_AUDUSD) : XAGAUD[1]
XAGNZD := should_be_calclated ? get_val_d(v1_XAGUSD, v2_XAGUSD, v1_NZDUSD, v2_NZDUSD) : XAGNZD[1]
OILJPY := should_be_calclated ? get_val_m(v1_OILUSD, v2_OILUSD, v1_USDJPY, v2_USDJPY) : OILJPY[1]
OILCHF := should_be_calclated ? get_val_m(v1_OILUSD, v2_OILUSD, v1_USDCHF, v2_USDCHF) : OILCHF[1]
OILGBP := should_be_calclated ? get_val_d(v1_OILUSD, v2_OILUSD, v1_GBPUSD, v2_GBPUSD) : OILGBP[1]
OILCAD := should_be_calclated ? get_val_m(v1_OILUSD, v2_OILUSD, v1_USDCAD, v2_USDCAD) : OILCAD[1]
OILAUD := should_be_calclated ? get_val_d(v1_OILUSD, v2_OILUSD, v1_AUDUSD, v2_AUDUSD) : OILAUD[1]
OILNZD := should_be_calclated ? get_val_d(v1_OILUSD, v2_OILUSD, v1_NZDUSD, v2_NZDUSD) : OILNZD[1]
OILXAU := should_be_calclated ? get_val_d(v1_OILUSD, v2_OILUSD, v1_XAUUSD, v2_XAUUSD) : OILXAU[1]

EUR = ma.calc(i_smoothtype, ( EURUSD + EURJPY + EURCHF + EURGBP + EURAUD + EURCAD + EURNZD) / 7, i_smooth)
USD = ma.calc(i_smoothtype, (-EURUSD + USDJPY + USDCHF - GBPUSD - AUDUSD + USDCAD - NZDUSD) / 7, i_smooth)
JPY = ma.calc(i_smoothtype, (-EURJPY - USDJPY - CHFJPY - GBPJPY - AUDJPY - CADJPY - NZDJPY) / 7, i_smooth)
CHF = ma.calc(i_smoothtype, (-EURCHF - USDCHF + CHFJPY - GBPCHF - AUDCHF - CADCHF - NZDCHF) / 7, i_smooth)
GBP = ma.calc(i_smoothtype, (-EURGBP + GBPUSD + GBPCHF + GBPJPY + GBPAUD + GBPCAD + GBPNZD) / 7, i_smooth)
AUD = ma.calc(i_smoothtype, (-EURAUD + AUDUSD + AUDJPY + AUDCHF - GBPAUD + AUDCAD + AUDNZD) / 7, i_smooth)
CAD = ma.calc(i_smoothtype, (-EURCAD - USDCAD + CADJPY + CADCHF - GBPCAD - AUDCAD - NZDCAD) / 7, i_smooth)
NZD = ma.calc(i_smoothtype, (-EURNZD + NZDUSD + NZDJPY + NZDCHF - GBPNZD + NZDCAD - AUDNZD) / 7, i_smooth)
XAU = ma.calc(i_smoothtype, (-EURXAU + XAUUSD + XAUJPY + XAUCHF + XAUGBP + XAUAUD + XAUCAD + XAUNZD) / 8, i_smooth)
XAG = ma.calc(i_smoothtype, (-EURXAG + XAGUSD + XAGJPY + XAGCHF + XAGGBP + XAGAUD + XAGCAD + XAGNZD) / 8, i_smooth)
OIL = ma.calc(i_smoothtype, (-EUROIL + OILUSD + OILJPY + OILCHF + OILGBP + OILAUD + OILCAD + OILNZD) / 8, i_smooth)

// Delta
//========
currency_a = str.substring(syminfo.ticker, 0, 3)
currency_b = str.substring(syminfo.ticker, 3)
currency_a_value = get_value_by_name(currency_a, EUR, USD, JPY, CHF, GBP, AUD, CAD, NZD)
currency_b_value = get_value_by_name(currency_b, EUR, USD, JPY, CHF, GBP, AUD, CAD, NZD)
currency_delta = currency_a_value - currency_b_value
chg_delta = ta.change(currency_delta)

c_currency_a = get_value_by_name(currency_a, c_eur, c_usd, c_jpy, c_chf, c_gbp, c_aud, c_cad, c_nzd)
c_currency_b = get_value_by_name(currency_b, c_eur, c_usd, c_jpy, c_chf, c_gbp, c_aud, c_cad, c_nzd)
c_delta = currency_delta > 0 ? c_currency_a : c_currency_b
c_delta_transparency = 40

if i_histogram_color == 'Depth'
    c_delta_transparency := (currency_delta > 0 and chg_delta < 0) or (currency_delta < 0 and chg_delta > 0) ? 65 : 40

////////////////////
// Plotting
////////////////////
// Backgrounds
hline(0, title='Base', linestyle=hline.style_solid)
hline( i_levels, color=c_levels, title='Level +', linestyle=hline.style_dotted)
hline(-i_levels, color=c_levels, title='Level -', linestyle=hline.style_dotted)

// Histogram
plot(show_histogram ? currency_delta : na, color=color.new(c_delta, c_delta_transparency), style=plot.style_columns, editable=false, show_last=i_pair_offset)

// Lines
plot(show_OIL and show_lines? OIL : na, title='OIL', color=c_oil, linewidth=i_oil_width, editable=false, show_last=i_pair_offset)
plot(show_XAG and show_lines? XAG : na, title='XAG', color=c_xag, linewidth=i_xag_width, editable=false, show_last=i_pair_offset)
plot(show_XAU and show_lines? XAU : na, title='XAU', color=c_xau, linewidth=i_xau_width, editable=false, show_last=i_pair_offset)
plot(show_NZD and show_lines? NZD : na, title='NZD', color=c_nzd, linewidth=i_nzd_width, editable=false, show_last=i_pair_offset)
plot(show_CAD and show_lines? CAD : na, title='CAD', color=c_cad, linewidth=i_cad_width, editable=false, show_last=i_pair_offset)
plot(show_CHF and show_lines? CHF : na, title='CHF', color=c_chf, linewidth=i_chf_width, editable=false, show_last=i_pair_offset)
plot(show_AUD and show_lines? AUD : na, title='AUD', color=c_aud, linewidth=i_aud_width, editable=false, show_last=i_pair_offset)
plot(show_GBP and show_lines? GBP : na, title='GBP', color=c_gbp, linewidth=i_gbp_width, editable=false, show_last=i_pair_offset)
plot(show_JPY and show_lines? JPY : na, title='JPY', color=c_jpy, linewidth=i_jpy_width, editable=false, show_last=i_pair_offset)
plot(show_EUR and show_lines? EUR : na, title='EUR', color=c_eur, linewidth=i_eur_width, editable=false, show_last=i_pair_offset)
plot(show_USD and show_lines? USD : na, title='USD', color=c_usd, linewidth=i_usd_width, editable=false, show_last=i_pair_offset)

plot(show_OIL and show_fill ? OIL : na, title='OIL', color=color.new(c_oil, 92), linewidth=0, style=plot.style_area, editable=false, show_last=i_pair_offset)
plot(show_XAG and show_fill ? XAG : na, title='XAG', color=color.new(c_xag, 92), linewidth=0, style=plot.style_area, editable=false, show_last=i_pair_offset)
plot(show_XAU and show_fill ? XAU : na, title='XAU', color=color.new(c_xau, 92), linewidth=0, style=plot.style_area, editable=false, show_last=i_pair_offset)
plot(show_NZD and show_fill ? NZD : na, title='NZD', color=color.new(c_nzd, 92), linewidth=0, style=plot.style_area, editable=false, show_last=i_pair_offset)
plot(show_CAD and show_fill ? CAD : na, title='CAD', color=color.new(c_cad, 92), linewidth=0, style=plot.style_area, editable=false, show_last=i_pair_offset)
plot(show_CHF and show_fill ? CHF : na, title='CHF', color=color.new(c_chf, 92), linewidth=0, style=plot.style_area, editable=false, show_last=i_pair_offset)
plot(show_AUD and show_fill ? AUD : na, title='AUD', color=color.new(c_aud, 92), linewidth=0, style=plot.style_area, editable=false, show_last=i_pair_offset)
plot(show_GBP and show_fill ? GBP : na, title='GBP', color=color.new(c_gbp, 92), linewidth=0, style=plot.style_area, editable=false, show_last=i_pair_offset)
plot(show_JPY and show_fill ? JPY : na, title='JPY', color=color.new(c_jpy, 92), linewidth=0, style=plot.style_area, editable=false, show_last=i_pair_offset)
plot(show_EUR and show_fill ? EUR : na, title='EUR', color=color.new(c_eur, 92), linewidth=0, style=plot.style_area, editable=false, show_last=i_pair_offset)
plot(show_USD and show_fill ? USD : na, title='USD', color=color.new(c_usd, 92), linewidth=0, style=plot.style_area, editable=false, show_last=i_pair_offset)

// Lines & Labels
line OIL_LINE = na, label OIL_LABEL = na
line XAG_LINE = na, label USD_LABEL = na
line XAU_LINE = na, label XAG_LABEL = na
line NZD_LINE = na, label XAU_LABEL = na
line CAD_LINE = na, label NZD_LABEL = na
line CHF_LINE = na, label CAD_LABEL = na
line AUD_LINE = na, label CHF_LABEL = na
line GBP_LINE = na, label AUD_LABEL = na
line JPY_LINE = na, label GBP_LABEL = na
line EUR_LINE = na, label JPY_LABEL = na
line USD_LINE = na, label EUR_LABEL = na


if barstate.islast and show_labels and show_lines
    line_extend = extend.none
    label_text_color = should_be_text_black ? c_black : color.white

    if show_OIL
        OIL_LINE := line.new(x1_line, OIL, x2_line, OIL, extend=line_extend, width=i_oil_width, style=i_line_style, color=c_oil), line.delete(OIL_LINE[1])
        OIL_LABEL := label.new(x1_label, OIL, 'OIL', color=c_oil, textcolor=label_text_color, style=i_label_style, size=i_label_size), label.delete(OIL_LABEL[1])

    if show_XAG
        XAG_LINE := line.new(x1_line, XAG, x2_line, XAG, extend=line_extend, width=i_xag_width, style=i_line_style, color=c_xag), line.delete(XAG_LINE[1])
        XAG_LABEL := label.new(x1_label, XAG, 'XAG', color=c_xag, textcolor=label_text_color, style=i_label_style, size=i_label_size), label.delete(XAG_LABEL[1])

    if show_XAU
        XAU_LINE := line.new(x1_line, XAU, x2_line, XAU, extend=line_extend, width=i_xau_width, style=i_line_style, color=c_xau), line.delete(XAU_LINE[1])
        XAU_LABEL := label.new(x1_label, XAU, 'XAU', color=c_xau, textcolor=label_text_color, style=i_label_style, size=i_label_size), label.delete(XAU_LABEL[1])

    if show_NZD
        NZD_LINE := line.new(x1_line, NZD, x2_line, NZD, extend=line_extend, width=i_nzd_width, style=i_line_style, color=c_nzd), line.delete(NZD_LINE[1])
        NZD_LABEL := label.new(x1_label, NZD, 'NZD', color=c_nzd, textcolor=label_text_color, style=i_label_style, size=i_label_size), label.delete(NZD_LABEL[1])

    if show_CAD
        CAD_LINE := line.new(x1_line, CAD, x2_line, CAD, extend=line_extend, width=i_cad_width, style=i_line_style, color=c_cad), line.delete(CAD_LINE[1])
        CAD_LABEL := label.new(x1_label, CAD, 'CAD', color=c_cad, textcolor=label_text_color, style=i_label_style, size=i_label_size), label.delete(CAD_LABEL[1])

    if show_CHF
        CHF_LINE := line.new(x1_line, CHF, x2_line, CHF, extend=line_extend, width=i_chf_width, style=i_line_style, color=c_chf), line.delete(CHF_LINE[1])
        CHF_LABEL := label.new(x1_label, CHF, 'CHF', color=c_chf, textcolor=label_text_color, style=i_label_style, size=i_label_size), label.delete(CHF_LABEL[1])

    if show_AUD
        AUD_LINE := line.new(x1_line, AUD, x2_line, AUD, extend=line_extend, width=i_aud_width, style=i_line_style, color=c_aud), line.delete(AUD_LINE[1])
        AUD_LABEL := label.new(x1_label, AUD, 'AUD', color=c_aud, textcolor=label_text_color, style=i_label_style, size=i_label_size), label.delete(AUD_LABEL[1])

    if show_GBP
        GBP_LINE := line.new(x1_line, GBP, x2_line, GBP, extend=line_extend, width=i_gbp_width, style=i_line_style, color=c_gbp), line.delete(GBP_LINE[1])
        GBP_LABEL := label.new(x1_label, GBP, 'GBP', color=c_gbp, textcolor=label_text_color, style=i_label_style, size=i_label_size), label.delete(GBP_LABEL[1])

    if show_JPY
        JPY_LINE := line.new(x1_line, JPY, x2_line, JPY, extend=line_extend, width=i_jpy_width, style=i_line_style, color=c_jpy), line.delete(JPY_LINE[1])
        JPY_LABEL := label.new(x1_label, JPY, 'JPY', color=c_jpy, textcolor=label_text_color, style=i_label_style, size=i_label_size), label.delete(JPY_LABEL[1])

    if show_EUR
        EUR_LINE := line.new(x1_line, EUR, x2_line, EUR, extend=line_extend, width=i_eur_width, style=i_line_style, color=c_eur), line.delete(EUR_LINE[1])
        EUR_LABEL := label.new(x1_label, EUR, 'EUR', color=c_eur, textcolor=label_text_color, style=i_label_style, size=i_label_size), label.delete(EUR_LABEL[1])

    if show_USD
        USD_LINE := line.new(x1_line, USD, x2_line, USD, extend=line_extend, width=i_usd_width, style=i_line_style, color=c_usd), line.delete(USD_LINE[1])
        USD_LABEL := label.new(x1_label, USD, 'USD', color=c_usd, textcolor=label_text_color, style=i_label_style, size=i_label_size), label.delete(USD_LABEL[1])


////////////////////
// Delta
////////////////////
DELTA_EURUSD = math.abs(EUR-USD)
DELTA_USDJPY = math.abs(USD-JPY)
DELTA_USDCHF = math.abs(USD-CHF)
DELTA_GBPUSD = math.abs(GBP-USD)
DELTA_AUDUSD = math.abs(AUD-USD)
DELTA_USDCAD = math.abs(USD-CAD)
DELTA_NZDUSD = math.abs(NZD-USD)
DELTA_GBPJPY = math.abs(GBP-JPY)

delta_pairs = array.from(DELTA_EURUSD, DELTA_USDJPY, DELTA_USDCHF, DELTA_GBPUSD, DELTA_AUDUSD, DELTA_USDCAD, DELTA_NZDUSD, DELTA_GBPJPY)
array.sort(delta_pairs, order.descending)

label delta_1 = na
label delta_2 = na
label delta_3 = na
label delta_4 = na
label delta_5 = na
label delta_6 = na
label delta_7 = na
label delta_8 = na

if barstate.islast and show_pair
    delta_positions = array.new_int(8)
    delta_labels = array.new_string(8)
    
    for i = 0 to 7
        array.set(delta_positions, i, i * -7)
        array.set(delta_labels, i, get_pair_by_value(array.get(delta_pairs, i), DELTA_EURUSD, DELTA_USDJPY, DELTA_USDCHF, DELTA_GBPUSD, DELTA_AUDUSD, DELTA_USDCAD, DELTA_NZDUSD, DELTA_GBPJPY))

    x1 = bar_index - (i_pair_offset + i_pair_margin)
    delta_1 := label.new(x1 + array.get(delta_positions, 0), 0, array.get(delta_labels, 0), style=label.style_label_up, size=size.small, color=noneColor, textcolor=i_pair_labelcolor), label.delete(delta_1[1])
    delta_2 := label.new(x1 + array.get(delta_positions, 1), 0, array.get(delta_labels, 1), style=label.style_label_up, size=size.small, color=noneColor, textcolor=i_pair_labelcolor), label.delete(delta_2[1])
    delta_3 := label.new(x1 + array.get(delta_positions, 2), 0, array.get(delta_labels, 2), style=label.style_label_up, size=size.small, color=noneColor, textcolor=i_pair_labelcolor), label.delete(delta_3[1])
    delta_4 := label.new(x1 + array.get(delta_positions, 3), 0, array.get(delta_labels, 3), style=label.style_label_up, size=size.small, color=noneColor, textcolor=i_pair_labelcolor), label.delete(delta_4[1])
    delta_5 := label.new(x1 + array.get(delta_positions, 4), 0, array.get(delta_labels, 4), style=label.style_label_up, size=size.small, color=noneColor, textcolor=i_pair_labelcolor), label.delete(delta_5[1])
    delta_6 := label.new(x1 + array.get(delta_positions, 5), 0, array.get(delta_labels, 5), style=label.style_label_up, size=size.small, color=noneColor, textcolor=i_pair_labelcolor), label.delete(delta_6[1])
    delta_7 := label.new(x1 + array.get(delta_positions, 6), 0, array.get(delta_labels, 6), style=label.style_label_up, size=size.small, color=noneColor, textcolor=i_pair_labelcolor), label.delete(delta_7[1])
    delta_8 := label.new(x1 + array.get(delta_positions, 7), 0, array.get(delta_labels, 7), style=label.style_label_up, size=size.small, color=noneColor, textcolor=i_pair_labelcolor), label.delete(delta_8[1])

plot(show_pair ? (array.get(delta_pairs, 0)) : na, style=plot.style_histogram, linewidth=12, show_last=1, editable=false, offset=-i_pair_offset-i_pair_margin-7*0, color=ac.gogh_cafeterrace('yellow'))
plot(show_pair ? (array.get(delta_pairs, 1)) : na, style=plot.style_histogram, linewidth=12, show_last=1, editable=false, offset=-i_pair_offset-i_pair_margin-7*1, color=ac.gogh_cafeterrace('yellow'))
plot(show_pair ? (array.get(delta_pairs, 2)) : na, style=plot.style_histogram, linewidth=12, show_last=1, editable=false, offset=-i_pair_offset-i_pair_margin-7*2, color=ac.gogh_cafeterrace('orange'))
plot(show_pair ? (array.get(delta_pairs, 3)) : na, style=plot.style_histogram, linewidth=12, show_last=1, editable=false, offset=-i_pair_offset-i_pair_margin-7*3, color=ac.gogh_cafeterrace('orange'))
plot(show_pair ? (array.get(delta_pairs, 4)) : na, style=plot.style_histogram, linewidth=12, show_last=1, editable=false, offset=-i_pair_offset-i_pair_margin-7*4, color=ac.gogh_cafeterrace('light-blue'))
plot(show_pair ? (array.get(delta_pairs, 5)) : na, style=plot.style_histogram, linewidth=12, show_last=1, editable=false, offset=-i_pair_offset-i_pair_margin-7*5, color=ac.gogh_cafeterrace('light-blue'))
plot(show_pair ? (array.get(delta_pairs, 6)) : na, style=plot.style_histogram, linewidth=12, show_last=1, editable=false, offset=-i_pair_offset-i_pair_margin-7*6, color=ac.gogh_cafeterrace('blue'))
plot(show_pair ? (array.get(delta_pairs, 7)) : na, style=plot.style_histogram, linewidth=12, show_last=1, editable=false, offset=-i_pair_offset-i_pair_margin-7*7, color=ac.gogh_cafeterrace('blue'))

////////////////////
// Analysis
////////////////////
sorted_by_ranking_names = array.new_string(8)
values = array.new_float(8)

if barstate.islast
    values := array.from(EUR, USD, JPY, CHF, GBP, AUD, CAD, NZD)
    array.sort(values, order.descending)
    

////////////////////
// Panel
////////////////////

// Table
if barstate.islast
    text_color      = c_black
    head_text_color = c_black

    table panel = table.new(i_panel_position, 4, 8, border_color=noneColor, border_width=0, frame_color=noneColor, frame_width=0)

    for i = 0 to array.size(values) - 1 by 1
        value = array.get(values, i)
        n = get_name_by_value(value, EUR, USD, JPY, CHF, GBP, AUD, CAD, NZD)
        f = get_flag_by_value(value, EUR, USD, JPY, CHF, GBP, AUD, CAD, NZD)
        c = get_color_by_value(value, EUR, USD, JPY, CHF, GBP, AUD, CAD, NZD)
        v = str.format('{0, number, #.#}', value)
        r = str.tostring(i + 1)
    
        if not na(n)
            array.set(sorted_by_ranking_names, i, n)
    
        if show_panel
            head_bgcolor = c
            bgcolor      = c
            table.cell(panel, 0, i, r, bgcolor=head_bgcolor, text_color=head_text_color, text_size=i_panel_textsize)
            table.cell(panel, 1, i, f, bgcolor=bgcolor, text_color=text_color, text_size=i_panel_flagsize)
            table.cell(panel, 2, i, n, bgcolor=bgcolor, text_color=text_color, text_size=i_panel_textsize, text_halign=text.align_left)
            table.cell(panel, 3, i, v, bgcolor=bgcolor, text_color=text_color, text_size=i_panel_textsize, text_halign=text.align_right)

////////////////////
// Alerts
////////////////////
string the_strongest_name = na
string the_weakest_name = na

if barstate.islast and barstate.isrealtime
    float max_value = array.max(values)
    float min_value = array.min(values)
    the_strongest_name := get_name_by_value(max_value, EUR, USD, JPY, CHF, GBP, AUD, CAD, NZD)
    the_weakest_name := get_name_by_value(min_value, EUR, USD, JPY, CHF, GBP, AUD, CAD, NZD)
    bool strongest_value_changed = the_strongest_name != the_strongest_name[1]
    bool weakest_value_changed = the_weakest_name != the_weakest_name[1]
    string alert_message = array.join(sorted_by_ranking_names, ' > ')
    
    if strongest_value_changed or weakest_value_changed
        alert('NEW UPDATE: ' + alert_message, alert.freq_once_per_bar_close)

Overview

Currency Strength Chart evaluates cross pairs from selected brokers using price action or oscillators like RSI, CCI, and Stochastics, smoothed by various moving average types. Users can configure resolution modes, lookback lengths, broker data feeds, and currency visibility. Calculation timing can be set to update on every tick or strictly after bar closes to manage execution performance.

Details

Published by

itmakesyousick on GitHub

Code credit

boitoki, as written in the script's header

Type

Indicator, Pine Script v5

Draws

Separate pane below the chart

Category

Oscillators & momentum, Screeners & dashboards

Markets

Forex

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Topics

pinescript

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Modestringt_reso_autoi_reso_mode
ResolutiontimeframeDi_reso_value
Lookback periodsint100Lookback periods
BrokersstringOANDAi_broker
Calculated onstringt_calc_afteri_calclate
Sourcesourceclosei_source
Calculated bystringPricei_calc
i_lengthint7i_length
SmoothingstringSMAi_smoothtype
i_smoothint1i_smooth
Auto selectedstringNois_autoSelect
is_histogramstringt_histogram_option1is_histogram
Show all 40 settings
SettingTypeDefaultVariable
EURbooltrueshow_EUR
c_eurcolorcolor.redc_eur
i_eur_widthint2i_eur_width
USDbooltrueshow_USD
c_usdcolorcolor.orangec_usd
i_usd_widthint2i_usd_width
JPYbooltrueshow_JPY
c_jpycolorcolor.aquac_jpy
i_jpy_widthint2i_jpy_width
GBPbooltrueshow_GBP
c_gbpcolorcolor.greenc_gbp
i_gbp_widthint2i_gbp_width
CHFbooltrueshow_CHF
c_chfcolorcolor.maroonc_chf
i_chf_widthint2i_chf_width
AUDbooltrueshow_AUD
c_audcolorcolor.bluec_aud
i_aud_widthint2i_aud_width
CADbooltrueshow_CAD
c_cadcolorcolor.purplec_cad
i_cad_widthint2i_cad_width
NZDbooltrueshow_NZD
c_nzdcolorcolor.fuchsiac_nzd
i_nzd_widthint2i_nzd_width
XAUboolfalseshow_XAU
c_xaucolor#D7BE69c_xau
i_xau_widthint2i_xau_width
XAGboolfalseshow_XAG
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

This indicator scans a pasted list of symbols for RSI directional momentum and shows matching long and short signals in a table in a separate pane. The user chooses continuous break, continuous retracement, flip break, flip retracement, divergence, or hidden d

Indicator v6 Oscillators & momentumDivergence
Updated 1 year ago · MPL-2.0 GitHub repository of Momentum Setup - RSI Directional Momentum Scanner
261 stars

This indicator plots the RSI oscillator on the main chart and displays its value distribution in a table positioned at the top right. The script calculates the relative strength index using the input source and length, then plots horizontal lines at 0, 50, and

Indicator v4 Oscillators & momentumScreeners & dashboards
Updated 4 years ago · None stated GitHub repository of Tables-003 Oscillator Distribution

Market Speedometer

by TradersPost
218 stars

Market Speedometer plots a 0-100 market speed reading in a separate pane. It measures movement by bar-to-bar change, true range, or a short average of recent bars, then ranks that movement against ATR and a percentile lookback. An EMA smooths the reading, and

Indicator v6 Volatility & bandsOscillators & momentum
Updated 3 months ago · None stated GitHub repository of Market Speedometer

KamaFama

by Mastaaa1987
141 stars

KamaFama is an indicator that translates a Freqtrade trading strategy into Pine Script for visualization. It combines Kaufman Adaptive Moving Average (KAMA), MAMA/FAMA calculations derived via Hilbert Transform, Williams %R, and correlation trend filters to ev

Indicator v6 Moving averagesOscillators & momentum
Updated 6 weeks ago · MIT GitHub repository of KamaFama
114 stars

Calculates normalized reversal metrics across up to ten Forex currency pairs using user-selected moving average methods, including HarmonicMA, EMA, SMA, or WMA. The indicator identifies overbought, oversold, and mean-crossing conditions using a configurable th

Indicator v4 Screeners & dashboardsMean reversion
Updated 1 year ago · None stated GitHub repository of Multi-Pair Trend Reversal Widget

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers