// 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)
import boitoki/TableColorTheme/1 as mycolor
import boitoki/AwesomeColor/1 as ac
import boitoki/ma_function/2 as ma
////////////////////
// Defines
////////////////////
noneColor = color.new(color.black, 100)
g1 = 'General:'
g2 = 'Display:'
g3 = 'Colors:'
g4 = 'Panel:'
g5 = ''
g6 = 'Options:'
g7 = 'Line style:'
g8 = 'Label style:'
g9 = 'Currency pair strength:'
EUR_FLAG = '🇪🇺'
USD_FLAG = '🇺🇸'
JPY_FLAG = '🇯🇵'
CHF_FLAG = '🇨🇭'
GBP_FLAG = '🇬🇧'
AUD_FLAG = '🇦🇺'
CAD_FLAG = '🇨🇦'
NZD_FLAG = '🇳🇿'
////////////////////
// Inputs
////////////////////
string reso_autovalue = not timeframe.isintraday ? '12M' : timeframe.multiplier >= 60 ? 'W' : timeframe.multiplier >= 240 ? 'M' : 'D'
string reso_customize = 'Resolution'
string reso_lookback = 'Lookback periods'
string i_reso_mode = input.string(defval='Auto', title='Mode', options=['Auto', reso_customize, reso_lookback], group=g1)
string i_reso_value = input.timeframe(defval='D', title='Resolution', group=g1, tooltip='When you choose the "Resolution" on the mode.')
get_reso (_mode) =>
switch _mode
'Auto' => reso_autovalue
reso_lookback => timeframe.period
reso_customize => i_reso_value
=> i_reso_value
string reso = get_reso(i_reso_mode)
i_reso_lookback = i_reso_mode == reso_lookback ? input.int(defval=100, title='Lookback periods', minval=1, group=g1, 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=g1)
i_smooth = input.int(defval=1, title='Smoothing', minval=1, group=g1)
i_smoothtype = input.string(defval='SMA', title='Smoothing type', options=['SMA', 'EMA', 'RMA', 'WMA', 'VWMA', 'HMA', 'LSMA', 'ALMA', 'SWMA', 'TMA', 'DEMA', 'TEMA', 'MAV', 'KAMA', 'ZZLEMA', 'AMA'], group=g1)
////////////////////
// Switches
////////////////////
show_EUR = input.bool(title='EUR', defval=true, group=g2)
show_USD = input.bool(title='USD', defval=true, group=g2)
show_JPY = input.bool(title='JPY', defval=true, group=g2)
show_GBP = input.bool(title='GBP', defval=true, group=g2)
show_CHF = input.bool(title='CHF', defval=true, group=g2)
show_AUD = input.bool(title='AUD', defval=true, group=g2)
show_CAD = input.bool(title='CAD', defval=true, group=g2)
show_NZD = input.bool(title='NZD', defval=true, group=g2)
show_XAU = input.bool(title='XAU', defval=false, group=g2)
show_XAG = input.bool(title='XAG', defval=false, group=g2)
show_OIL = input.bool(title='OIL', defval=false, group=g2)
is_autoSelect = input.bool(defval=false, title="Auto selected current currencies", group=g2)
bool show_fill = is_autoSelect
if is_autoSelect
show_EUR := false, show_USD := false, show_JPY := false
show_GBP := false, show_CHF := false, show_AUD := false
show_CAD := false, show_NZD := false, show_XAU := false
show_XAG := false, show_OIL := false
if (str.length(str.replace_all(syminfo.ticker, 'EUR', '')) < 6)
show_EUR := true
if (str.length(str.replace_all(syminfo.ticker, 'USD', '')) < 6)
show_USD := true
if (str.length(str.replace_all(syminfo.ticker, 'JPY', '')) < 6)
show_JPY := true
if (str.length(str.replace_all(syminfo.ticker, 'GBP', '')) < 6)
show_GBP := true
if (str.length(str.replace_all(syminfo.ticker, 'CHF', '')) < 6)
show_CHF := true
if (str.length(str.replace_all(syminfo.ticker, 'AUD', '')) < 6)
show_AUD := true
if (str.length(str.replace_all(syminfo.ticker, 'CAD', '')) < 6)
show_CAD := true
if (str.length(str.replace_all(syminfo.ticker, 'NZD', '')) < 6)
show_NZD := true
if (str.length(str.replace_all(syminfo.ticker, 'XAU', '')) < 6)
show_XAU := true
if (str.length(str.replace_all(syminfo.ticker, 'XAG', '')) < 6)
show_XAG := true
if (str.length(str.replace_all(syminfo.ticker, 'OIL', '')) < 6)
show_OIL := true
float v1_EURUSD = request.security(i_broker + ':EURUSD', timeframe.period, close)
float v1_USDJPY = request.security(i_broker + ':USDJPY', timeframe.period, close)
float v1_USDCHF = request.security(i_broker + ':USDCHF', timeframe.period, close)
float v1_GBPUSD = request.security(i_broker + ':GBPUSD', timeframe.period, close)
float v1_AUDUSD = request.security(i_broker + ':AUDUSD', timeframe.period, close)
float v1_USDCAD = request.security(i_broker + ':USDCAD', timeframe.period, close)
float v1_NZDUSD = request.security(i_broker + ':NZDUSD', timeframe.period, close)
float v1_XAUUSD = show_XAU ? request.security(i_broker + ':XAUUSD', timeframe.period, close) : 0
float v1_XAGUSD = show_XAG ? request.security(i_broker + ':XAGUSD', timeframe.period, close) : 0
float v1_OILUSD = show_OIL ? request.security('USOIL', timeframe.period, close) : 0
float v2_EURUSD = request.security(i_broker + ':EURUSD', reso, close[i_reso_lookback], barmerge.gaps_off, barmerge.lookahead_on)
float v2_USDJPY = request.security(i_broker + ':USDJPY', reso, close[i_reso_lookback], barmerge.gaps_off, barmerge.lookahead_on)
float v2_USDCHF = request.security(i_broker + ':USDCHF', reso, close[i_reso_lookback], barmerge.gaps_off, barmerge.lookahead_on)
float v2_GBPUSD = request.security(i_broker + ':GBPUSD', reso, close[i_reso_lookback], barmerge.gaps_off, barmerge.lookahead_on)
float v2_AUDUSD = request.security(i_broker + ':AUDUSD', reso, close[i_reso_lookback], barmerge.gaps_off, barmerge.lookahead_on)
float v2_USDCAD = request.security(i_broker + ':USDCAD', reso, close[i_reso_lookback], barmerge.gaps_off, barmerge.lookahead_on)
float v2_NZDUSD = request.security(i_broker + ':NZDUSD', reso, close[i_reso_lookback], barmerge.gaps_off, barmerge.lookahead_on)
float v2_XAUUSD = show_XAU ? request.security(i_broker + ':XAUUSD', reso, close[i_reso_lookback], barmerge.gaps_off, barmerge.lookahead_on) : 0
float v2_XAGUSD = show_XAU ? request.security(i_broker + ':XAGUSD', reso, close[i_reso_lookback], barmerge.gaps_off, barmerge.lookahead_on) : 0
float v2_OILUSD = show_OIL ? request.security('USOIL', reso, close[i_reso_lookback], barmerge.gaps_off, barmerge.lookahead_on) : 0
// Colors
c_eur = input.color(title='EUR', defval=color.red, group=g3)
c_usd = input.color(title='USD', defval=color.orange, group=g3)
c_jpy = input.color(title='JPY', defval=color.aqua, group=g3)
c_gbp = input.color(title='GBP', defval=color.green, group=g3)
c_chf = input.color(title='CHF', defval=color.maroon, group=g3)
c_aud = input.color(title='AUD', defval=color.blue, group=g3)
c_cad = input.color(title='CAD', defval=color.purple, group=g3)
c_nzd = input.color(title='NZD', defval=color.fuchsia, group=g3)
c_xau = input.color(title='XAU', defval=#D7BE69, group=g3)
c_xag = input.color(title='XAG', defval=color.silver, group=g3)
c_oil = input.color(title='OIL', defval=#745433, group=g3)
color c_green = ac.tradingview('green')
color c_red = ac.tradingview('red')
color c_black = ac.tradingview('black')
i_theme = input.string(title="Color theme", defval="monokai", options=["monokai", "monokai pro", "customize"], group=g3)
is_monokai = (i_theme == 'monokai' or i_theme == 'monokai pro')
// Color themes
if i_theme == "monokai"
c_eur := mycolor.monokai('pink')
c_usd := mycolor.monokai('orange')
c_gbp := mycolor.monokai('green')
c_cad := mycolor.monokai('purple')
c_aud := mycolor.monokai('blue')
c_chf := mycolor.monokai('yellow')
c_green := mycolor.monokai('green')
c_red := mycolor.monokai('pink')
c_black := mycolor.monokai('black')
else if i_theme == "monokai pro"
c_eur := mycolor.monokaipro('pink')
c_usd := mycolor.monokaipro('orange')
c_gbp := mycolor.monokaipro('green')
c_cad := mycolor.monokaipro('purple')
c_aud := mycolor.monokaipro('blue')
c_chf := mycolor.monokaipro('yellow')
c_green := mycolor.monokaipro('green')
c_red := mycolor.monokaipro('pink')
c_black := mycolor.monokaipro('black')
////////////////////
// Other settings
////////////////////
// Lines
show_lines = true
line_x1 = time
line_width = input.int(title='Line width', defval=2, minval=1, group=g7)
line_style = input.string(title='Extended line style', defval=line.style_dotted, options=[line.style_solid, line.style_dotted, line.style_dashed], group=g7)
is_line_extend = input.string(title='Line extend', defval="No", options=["Yes", "No"], group=g7) == "Yes"
// Labels
show_labels = input.bool(title='Name label', defval=true, group=g8)
label_size = input.string(title='Label size', options=[size.auto, size.tiny, size.small, size.normal, size.large, size.huge], defval=size.normal, group=g8)
label_offset = input.int(title='Label offset', defval=5, minval=0, group=g8)
label_style = label.style_label_left
label_x = time + timeframe.multiplier * 60 * 1000 * label_offset
line_x2 = is_line_extend ? time + 1000 : label_x
// Panel
show_panel = input.bool(title='Panel', defval=true, group=g4)
panel_position = input.string(title='Position', defval=position.top_right, options=[position.top_right, position.top_center, position.top_left, position.middle_right, position.middle_center, position.middle_left, position.bottom_right, position.bottom_center, position.bottom_left], group=g4)
panel_flag_size = input.string(title='Flag size', defval=size.large, options=[size.auto, size.tiny, size.small, size.normal, size.large, size.huge], group=g4)
panel_text_size = input.string(title='Text size', defval=size.normal, options=[size.auto, size.tiny, size.small, size.normal, size.large, size.huge], group=g4)
panel_theme = input.string(title='Color theme', defval='multi', options=['multi', 'green', 'blue', 'orange', 'red', 'black', 'white', 'night', 'carbon'], group=g4)
is_multi = panel_theme == 'multi'
// Currency pair strength
show_pair = input.bool(title="Currency pair strength", defval=false, group=g9)
pair_offset = show_pair ? input.int(defval=100, title="Position offset", options=[0,20,40,60,80,100,120,140,160,180,200], group=g9) : 0
pair_margin = input.int(defval=4, title="Position margin", options=[0,2,4,6,8,10,16,20], group=g9)
pair_labelcolor = input.color(defval=color.gray, title="Label color", group=g9)
// Options
show_levels = input.bool(title='Level lines', defval=false, group=g6)
i_levels = input.int(title='Level (±)', minval=1, defval=10, group=g6)
color c_levels = show_levels ? color.gray : na
////////////////////
// Functions
////////////////////
ma_function(type, src, len) => ma.ma_function(type, src, len)
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
////////////////////
float EURUSD = get_val(v1_EURUSD, v2_EURUSD)
float USDJPY = get_val(v1_USDJPY, v2_USDJPY)
float USDCHF = get_val(v1_USDCHF, v2_USDCHF)
float GBPUSD = get_val(v1_GBPUSD, v2_GBPUSD)
float AUDUSD = get_val(v1_AUDUSD, v2_AUDUSD)
float USDCAD = get_val(v1_USDCAD, v2_USDCAD)
float NZDUSD = get_val(v1_NZDUSD, v2_NZDUSD)
float XAUUSD = get_val(v1_XAUUSD, v2_XAUUSD)
float XAGUSD = get_val(v1_XAGUSD, v2_XAGUSD)
float OILUSD = get_val(v1_OILUSD, v2_OILUSD)
float EURJPY = get_val_m(v1_EURUSD, v2_EURUSD, v1_USDJPY, v2_USDJPY)
float EURCHF = get_val_m(v1_EURUSD, v2_EURUSD, v1_USDCHF, v2_USDCHF)
float EURGBP = get_val_d(v1_EURUSD, v2_EURUSD, v1_GBPUSD, v2_GBPUSD)
float EURCAD = get_val_m(v1_EURUSD, v2_EURUSD, v1_USDCAD, v2_USDCAD)
float EURAUD = get_val_d(v1_EURUSD, v2_EURUSD, v1_AUDUSD, v2_AUDUSD)
float EURNZD = get_val_d(v1_EURUSD, v2_EURUSD, v1_NZDUSD, v2_NZDUSD)
float EURXAU = get_val_d(v1_EURUSD, v2_EURUSD, v1_XAUUSD, v2_XAUUSD)
float EURXAG = get_val_d(v1_EURUSD, v2_EURUSD, v1_XAGUSD, v2_XAGUSD)
float EUROIL = get_val_d(v1_EURUSD, v2_EURUSD, v1_OILUSD, v2_OILUSD)
float GBPCHF = get_val_m(v1_GBPUSD, v2_GBPUSD, v1_USDCHF, v2_USDCHF)
float GBPJPY = get_val_m(v1_GBPUSD, v2_GBPUSD, v1_USDJPY, v2_USDJPY)
float GBPCAD = get_val_m(v1_GBPUSD, v2_GBPUSD, v1_USDCAD, v2_USDCAD)
float GBPAUD = get_val_d(v1_GBPUSD, v2_GBPUSD, v1_AUDUSD, v2_AUDUSD)
float GBPNZD = get_val_d(v1_GBPUSD, v2_GBPUSD, v1_NZDUSD, v2_NZDUSD)
float AUDCHF = get_val_m(v1_AUDUSD, v2_AUDUSD, v1_USDCHF, v2_USDCHF)
float AUDJPY = get_val_m(v1_AUDUSD, v2_AUDUSD, v1_USDJPY, v2_USDJPY)
float AUDCAD = get_val_m(v1_AUDUSD, v2_AUDUSD, v1_USDCAD, v2_USDCAD)
float AUDNZD = get_val_d(v1_AUDUSD, v2_AUDUSD, v1_NZDUSD, v2_NZDUSD)
float NZDCAD = get_val_m(v1_NZDUSD, v2_NZDUSD, v1_USDCAD, v2_USDCAD)
float NZDCHF = get_val_m(v1_NZDUSD, v2_NZDUSD, v1_USDCHF, v2_USDCHF)
float NZDJPY = get_val_m(v1_NZDUSD, v2_NZDUSD, v1_USDJPY, v2_USDJPY)
float CADJPY = get_val_d(v1_USDJPY, v2_USDJPY, v1_USDCAD, v2_USDCAD)
float CADCHF = get_val_d(v1_USDCHF, v2_USDCHF, v1_USDCAD, v2_USDCAD)
float CHFJPY = get_val_d(v1_USDJPY, v2_USDJPY, v1_USDCHF, v2_USDCHF)
float XAUJPY = get_val_m(v1_XAUUSD, v2_XAUUSD, v1_USDJPY, v2_USDJPY)
float XAUCHF = get_val_m(v1_XAUUSD, v2_XAUUSD, v1_USDCHF, v2_USDCHF)
float XAUGBP = get_val_d(v1_XAUUSD, v2_XAUUSD, v1_GBPUSD, v2_GBPUSD)
float XAUCAD = get_val_m(v1_XAUUSD, v2_XAUUSD, v1_USDCAD, v2_USDCAD)
float XAUAUD = get_val_d(v1_XAUUSD, v2_XAUUSD, v1_AUDUSD, v2_AUDUSD)
float XAUNZD = get_val_d(v1_XAUUSD, v2_XAUUSD, v1_NZDUSD, v2_NZDUSD)
float XAGJPY = get_val_m(v1_XAGUSD, v2_XAGUSD, v1_USDJPY, v2_USDJPY)
float XAGCHF = get_val_m(v1_XAGUSD, v2_XAGUSD, v1_USDCHF, v2_USDCHF)
float XAGGBP = get_val_d(v1_XAGUSD, v2_XAGUSD, v1_GBPUSD, v2_GBPUSD)
float XAGCAD = get_val_m(v1_XAGUSD, v2_XAGUSD, v1_USDCAD, v2_USDCAD)
float XAGAUD = get_val_d(v1_XAGUSD, v2_XAGUSD, v1_AUDUSD, v2_AUDUSD)
float XAGNZD = get_val_d(v1_XAGUSD, v2_XAGUSD, v1_NZDUSD, v2_NZDUSD)
float OILJPY = get_val_m(v1_OILUSD, v2_OILUSD, v1_USDJPY, v2_USDJPY)
float OILCHF = get_val_m(v1_OILUSD, v2_OILUSD, v1_USDCHF, v2_USDCHF)
float OILGBP = get_val_d(v1_OILUSD, v2_OILUSD, v1_GBPUSD, v2_GBPUSD)
float OILCAD = get_val_m(v1_OILUSD, v2_OILUSD, v1_USDCAD, v2_USDCAD)
float OILAUD = get_val_d(v1_OILUSD, v2_OILUSD, v1_AUDUSD, v2_AUDUSD)
float OILNZD = get_val_d(v1_OILUSD, v2_OILUSD, v1_NZDUSD, v2_NZDUSD)
float OILXAU = get_val_d(v1_OILUSD, v2_OILUSD, v1_XAUUSD, v2_XAUUSD)
float EUR = ma_function(i_smoothtype, ( EURUSD + EURJPY + EURCHF + EURGBP + EURAUD + EURCAD + EURNZD) / 7, i_smooth)
float USD = ma_function(i_smoothtype, (-EURUSD + USDJPY + USDCHF - GBPUSD - AUDUSD + USDCAD - NZDUSD) / 7, i_smooth)
float JPY = ma_function(i_smoothtype, (-EURJPY - USDJPY - CHFJPY - GBPJPY - AUDJPY - CADJPY - NZDJPY) / 7, i_smooth)
float CHF = ma_function(i_smoothtype, (-EURCHF - USDCHF + CHFJPY - GBPCHF - AUDCHF - CADCHF - NZDCHF) / 7, i_smooth)
float GBP = ma_function(i_smoothtype, (-EURGBP + GBPUSD + GBPCHF + GBPJPY + GBPAUD + GBPCAD + GBPNZD) / 7, i_smooth)
float AUD = ma_function(i_smoothtype, (-EURAUD + AUDUSD + AUDJPY + AUDCHF - GBPAUD + AUDCAD + AUDNZD) / 7, i_smooth)
float CAD = ma_function(i_smoothtype, (-EURCAD - USDCAD + CADJPY + CADCHF - GBPCAD - AUDCAD - NZDCAD) / 7, i_smooth)
float NZD = ma_function(i_smoothtype, (-EURNZD + NZDUSD + NZDJPY + NZDCHF - GBPNZD + NZDCAD - AUDNZD) / 7, i_smooth)
float XAU = ma_function(i_smoothtype, (-EURXAU + XAUUSD + XAUJPY + XAUCHF + XAUGBP + XAUAUD + XAUCAD + XAUNZD) / 8, i_smooth)
float XAG = ma_function(i_smoothtype, (-EURXAG + XAGUSD + XAGJPY + XAGCHF + XAGGBP + XAGAUD + XAGCAD + XAGNZD) / 8, i_smooth)
float OIL = ma_function(i_smoothtype, (-EUROIL + OILUSD + OILJPY + OILCHF + OILGBP + OILAUD + OILCAD + OILNZD) / 8, i_smooth)
////////////////////
// Plotting
////////////////////
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)
// Lines
plot(show_OIL ? OIL : na, title='OIL', color=c_oil, linewidth=line_width, editable=false, show_last=pair_offset)
plot(show_XAG ? XAG : na, title='XAG', color=c_xag, linewidth=line_width, editable=false, show_last=pair_offset)
plot(show_XAU ? XAU : na, title='XAU', color=c_xau, linewidth=line_width, editable=false, show_last=pair_offset)
plot(show_NZD ? NZD : na, title='NZD', color=c_nzd, linewidth=line_width, editable=false, show_last=pair_offset)
plot(show_CAD ? CAD : na, title='CAD', color=c_cad, linewidth=line_width, editable=false, show_last=pair_offset)
plot(show_CHF ? CHF : na, title='CHF', color=c_chf, linewidth=line_width, editable=false, show_last=pair_offset)
plot(show_AUD ? AUD : na, title='AUD', color=c_aud, linewidth=line_width, editable=false, show_last=pair_offset)
plot(show_GBP ? GBP : na, title='GBP', color=c_gbp, linewidth=line_width, editable=false, show_last=pair_offset)
plot(show_JPY ? JPY : na, title='JPY', color=c_jpy, linewidth=line_width, editable=false, show_last=pair_offset)
plot(show_EUR ? EUR : na, title='EUR', color=c_eur, linewidth=line_width, editable=false, show_last=pair_offset)
plot(show_USD ? USD : na, title='USD', color=c_usd, linewidth=line_width, editable=false, show_last=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=true, show_last=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=true, show_last=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=true, show_last=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=true, show_last=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=true, show_last=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=true, show_last=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=true, show_last=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=true, show_last=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=true, show_last=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=true, show_last=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=true, show_last=pair_offset)
if show_lines
line_extend = is_line_extend ? extend.right : extend.none
if show_OIL
OIL_LINE = line.new(line_x1, OIL, line_x2, OIL, extend=line_extend, xloc=xloc.bar_time, width=line_width, style=line_style, color=c_oil)
line.delete(OIL_LINE[1])
if show_XAG
XAG_LINE = line.new(line_x1, XAG, line_x2, XAG, extend=line_extend, xloc=xloc.bar_time, width=line_width, style=line_style, color=c_xag)
line.delete(XAG_LINE[1])
if show_XAU
XAU_LINE = line.new(line_x1, XAU, line_x2, XAU, extend=line_extend, xloc=xloc.bar_time, width=line_width, style=line_style, color=c_xau)
line.delete(XAU_LINE[1])
if show_NZD
NZD_LINE = line.new(line_x1, NZD, line_x2, NZD, extend=line_extend, xloc=xloc.bar_time, width=line_width, style=line_style, color=c_nzd)
line.delete(NZD_LINE[1])
if show_CAD
CAD_LINE = line.new(line_x1, CAD, line_x2, CAD, extend=line_extend, xloc=xloc.bar_time, width=line_width, style=line_style, color=c_cad)
line.delete(CAD_LINE[1])
if show_CHF
CHF_LINE = line.new(line_x1, CHF, line_x2, CHF, extend=line_extend, xloc=xloc.bar_time, width=line_width, style=line_style, color=c_chf)
line.delete(CHF_LINE[1])
if show_AUD
AUD_LINE = line.new(line_x1, AUD, line_x2, AUD, extend=line_extend, xloc=xloc.bar_time, width=line_width, style=line_style, color=c_aud)
line.delete(AUD_LINE[1])
if show_GBP
GBP_LINE = line.new(line_x1, GBP, line_x2, GBP, extend=line_extend, xloc=xloc.bar_time, width=line_width, style=line_style, color=c_gbp)
line.delete(GBP_LINE[1])
if show_JPY
JPY_LINE = line.new(line_x1, JPY, line_x2, JPY, extend=line_extend, xloc=xloc.bar_time, width=line_width, style=line_style, color=c_jpy)
line.delete(JPY_LINE[1])
if show_EUR
EUR_LINE = line.new(line_x1, EUR, line_x2, EUR, extend=line_extend, xloc=xloc.bar_time, width=line_width, style=line_style, color=c_eur)
line.delete(EUR_LINE[1])
if show_USD
USD_LINE = line.new(line_x1, USD, line_x2, USD, extend=line_extend, xloc=xloc.bar_time, width=line_width, style=line_style, color=c_usd)
line.delete(USD_LINE[1])
// Labels
if show_labels
label_text_color = is_monokai ? c_black : color.white
if show_OIL
label OIL_LABEL = label.new(label_x, OIL, 'OIL', color=c_oil, xloc=xloc.bar_time, textcolor=label_text_color, style=label_style, size=label_size)
label.delete(OIL_LABEL[1])
if show_XAG
label XAG_LABEL = label.new(label_x, XAG, 'XAG', color=c_xag, xloc=xloc.bar_time, textcolor=label_text_color, style=label_style, size=label_size)
label.delete(XAG_LABEL[1])
if show_XAU
label XAU_LABEL = label.new(label_x, XAU, 'XAU', color=c_xau, xloc=xloc.bar_time, textcolor=label_text_color, style=label_style, size=label_size)
label.delete(XAU_LABEL[1])
if show_NZD
label NZD_LABEL = label.new(label_x, NZD, 'NZD', color=c_nzd, xloc=xloc.bar_time, textcolor=label_text_color, style=label_style, size=label_size)
label.delete(NZD_LABEL[1])
if show_CAD
label CAD_LABEL = label.new(label_x, CAD, 'CAD', color=c_cad, xloc=xloc.bar_time, textcolor=label_text_color, style=label_style, size=label_size)
label.delete(CAD_LABEL[1])
if show_CHF
label CHF_LABEL = label.new(label_x, CHF, 'CHF', color=c_chf, xloc=xloc.bar_time, textcolor=label_text_color, style=label_style, size=label_size)
label.delete(CHF_LABEL[1])
if show_AUD
label AUD_LABEL = label.new(label_x, AUD, 'AUD', color=c_aud, xloc=xloc.bar_time, textcolor=label_text_color, style=label_style, size=label_size)
label.delete(AUD_LABEL[1])
if show_GBP
label GBP_LABEL = label.new(label_x, GBP, 'GBP', color=c_gbp, xloc=xloc.bar_time, textcolor=label_text_color, style=label_style, size=label_size)
label.delete(GBP_LABEL[1])
if show_JPY
label JPY_LABEL = label.new(label_x, JPY, 'JPY', color=c_jpy, xloc=xloc.bar_time, textcolor=label_text_color, style=label_style, size=label_size)
label.delete(JPY_LABEL[1])
if show_EUR
label EUR_LABEL = label.new(label_x, EUR, 'EUR', color=c_eur, xloc=xloc.bar_time, textcolor=label_text_color, style=label_style, size=label_size)
label.delete(EUR_LABEL[1])
if show_USD
label USD_LABEL = label.new(label_x, USD, 'USD', color=c_usd, xloc=xloc.bar_time, textcolor=label_text_color, style=label_style, size=label_size)
label.delete(USD_LABEL[1])
////////////////////
// Analysis
////////////////////
values = array.new_float(8)
array.set(values, 0, EUR)
array.set(values, 1, USD)
array.set(values, 2, JPY)
array.set(values, 3, CHF)
array.set(values, 4, GBP)
array.set(values, 5, AUD)
array.set(values, 6, CAD)
array.set(values, 7, NZD)
array.sort(values, order.descending)
sorted_by_ranking_names = array.new_string(8)
////////////////////
// Panel
////////////////////
[border_color, border_width, frame_color, frame_width, text_color, text_size, bgcolor, head_text_color, head_text_size, head_bgcolor] = mycolor.theme(panel_theme)
table panel = table.new(panel_position, 4, 8, border_color=border_color, border_width=border_width, frame_color=frame_color, frame_width=frame_width)
if is_multi and is_monokai
text_color := c_black
head_text_color := c_black
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 := is_multi ? c : head_bgcolor
bgcolor := is_multi ? c : bgcolor
table.cell(panel, 0, i, r, bgcolor=head_bgcolor, text_color=head_text_color, text_size=panel_text_size)
table.cell(panel, 1, i, f, bgcolor=bgcolor, text_color=text_color, text_size=panel_flag_size)
table.cell(panel, 2, i, n, bgcolor=bgcolor, text_color=text_color, text_size=panel_text_size, text_halign=text.align_left)
table.cell(panel, 3, i, v, bgcolor=bgcolor, text_color=text_color, text_size=panel_text_size, text_halign=text.align_right)
////////////////////
// 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.new_float(8)
array.set(delta_pairs, 0, DELTA_EURUSD)
array.set(delta_pairs, 1, DELTA_USDJPY)
array.set(delta_pairs, 2, DELTA_USDCHF)
array.set(delta_pairs, 3, DELTA_GBPUSD)
array.set(delta_pairs, 4, DELTA_AUDUSD)
array.set(delta_pairs, 5, DELTA_USDCAD)
array.set(delta_pairs, 6, DELTA_NZDUSD)
array.set(delta_pairs, 7, DELTA_GBPJPY)
array.sort(delta_pairs, order.descending)
DELTA_MAX = array.max(delta_pairs)
plot(show_pair ? (array.get(delta_pairs, 0)) : na, style=plot.style_histogram, linewidth=12, show_last=1, editable=false, offset=-pair_offset-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=-pair_offset-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=-pair_offset-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=-pair_offset-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=-pair_offset-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=-pair_offset-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=-pair_offset-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=-pair_offset-pair_margin-7*7, color=ac.gogh_cafeterrace('blue'))
if (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 - (pair_offset + 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=pair_labelcolor)
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=pair_labelcolor)
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=pair_labelcolor)
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=pair_labelcolor)
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=pair_labelcolor)
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=pair_labelcolor)
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=pair_labelcolor)
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=pair_labelcolor)
label.delete(delta_1[1])
label.delete(delta_2[1])
label.delete(delta_3[1])
label.delete(delta_4[1])
label.delete(delta_5[1])
label.delete(delta_6[1])
label.delete(delta_7[1])
label.delete(delta_8[1])
////////////////////
// Alerts
////////////////////
float max_value = array.max(values)
float min_value = array.min(values)
string the_strongest_name = get_name_by_value(max_value, EUR, USD, JPY, CHF, GBP, AUD, CAD, NZD)
string 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)
Show all 561 lines