LankouMultiSpreadsV2 All
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © lankou

//@version=5
indicator('LankouMultiSpreadsV2', overlay=false)

// https://kodify.net/tradingview/indicator-settings/indicator-name/

limit = input(8, "limit (color)")
ema_period = input(13, "ema")

//input.string("On", "Plot Display", options = ["On", "Off"])
spreadName = input.string(defval = "DEFI", title = "choose spread", options = ["DEFI", "META", "STORAGE", "SHIT", "EXCHANGE(ftx)"])
//, group = "Paramètres d'Entrée en Trade")


f_print_source(source, _text) =>
    // Create label on the first bar.
    var _label = label.new(bar_index, na, _text, xloc.bar_index, yloc.price, color(na), label.style_none, color.white, size.large, text.align_left)
    // On next bars, update the label's x and y position, and the text it displays.
    label.set_xy(_label, bar_index, ta.highest(source, 10)[1])
    label.set_text(_label, _text)

f_print(_text) =>
    // Create label on the first bar.
    var _label = label.new(bar_index, na, _text, xloc.bar_index, yloc.price, color(na), label.style_none, color.white, size.large, text.align_left)
    // On next bars, update the label's x and y position, and the text it displays.
    label.set_xy(_label, bar_index, ta.highest(10)[1])
    label.set_text(_label, _text)

get_shib() =>
    sym2 = request.security("(1000*BINANCE:SHIBUSDT-BINANCE:1000SHIBUSDTPERP)/1000*BINANCE:SHIBUSDT", timeframe.period, close)
    sym2

// get symbol and PERP version of it FTX version
gen_sym2_ftx(symbol) =>
    local_sym = 'FTX:' + symbol + 'USD'
    the_string_perp = 'FTX:' + symbol + 'PERP'
    sec = request.security('(' + local_sym + '-' + the_string_perp + ')/' + local_sym, timeframe.period, close)


// get symbol and PERP version of it
gen_sym2(symbol) =>
    local_sym = 'BINANCE:' + symbol + 'USDT'
    the_string_perp = local_sym + 'PERP'
    sec = request.security('(' + local_sym + '-' + the_string_perp + ')/' + local_sym, timeframe.period, close)
    // TODO essayer dans la diviosn 
    // sec = security(local_sym + "-" + the_string_perp, timeframe.period, close)


// sym2 = c-BINANCE:MATICUSDTPERP", timeframe.period, close)
ALT_LINE = close

if (spreadName == "EXCHANGE(ftx)")
    sym1 = gen_sym2_ftx("BNB")
    sym2 = gen_sym2_ftx("CRO")
    sym3 = gen_sym2_ftx("OKB")
    sym4 = gen_sym2_ftx("FTT")
    sym5 = gen_sym2_ftx("LEO")
    //sym6 = gen_sym2_ftx("KCS")
    sym7 = gen_sym2_ftx("HT")
    // ALT_LINE = -(sym1 + sym2 + sym3 + sym4 + sym5 + sym6 + sym7) / 7
    ALT_LINE := -(sym1 + sym2 + sym3 + sym4 + sym5 + sym7) / 6


if (spreadName == "STORAGE")
    sym1 = gen_sym2('STORJ')
    sym2 = gen_sym2('AR')
    sym3 = gen_sym2('SC')
    sym4 = gen_sym2('FIL')
    //sym5 = gen_sym2('BTT')
    sym6 = gen_sym2('HOT')
    ALT_LINE := -(sym1 + sym2 + sym3 + sym4 + sym6) / 5

if (spreadName == "DEFI")
    sym1 = gen_sym2("AAVE")
    sym2 = gen_sym2("YFI")
    sym3 = gen_sym2("UNI")
    sym4 = gen_sym2("SUSHI")
    sym5 = gen_sym2("COMP")
    sym6 = gen_sym2("SNX")
    sym7 = gen_sym2("MKR")
    sym8 = gen_sym2("CRV")
    sym9 = gen_sym2("RUNE")
    ALT_LINE := -( sym1 + sym2 + sym3 + sym4 + sym5 + sym6 + sym7 + sym8 + sym9) / 9

if (spreadName == "META")
    sym1 = gen_sym2("AXS")
    sym2 = gen_sym2("SAND")
    sym3 = gen_sym2("MANA")
    sym4 = gen_sym2("ENJ")
    ALT_LINE := -(sym1 + sym2 + sym3 + sym4) / 4

if (spreadName == "SHIT")
    sym2 = get_shib()
    sym1 = gen_sym2("DOGE")
    ALT_LINE := -(sym1 + sym2) / 2


ema = ta.ema(ALT_LINE, ema_period) * 10000

col = color.rgb(255, 255, 255)
if (ema > 0)
    col := color.from_gradient(ema, 0, limit, color.white, color.green)
else
    col := color.from_gradient(ema, -limit, 0, color.red, color.white)

f_print_source(ema, spreadName)

plot(ema, color=col, linewidth=2, style=plot.style_area)

hline(limit, title="10", color=color.rgb(100, 100, 100, 50), linestyle=hline.style_dashed)
hline(-limit, title="10", color=color.rgb(100, 100, 100, 50), linestyle=hline.style_dashed)
