LankouSpreads ema 13
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © lankou
// v2

//@version=5
indicator('LankouSpreads ema 13 BINANCE', overlay=false)


// the_string_perp = syminfo.ticker + 'PERP'

// syminfo.prefix

// PERP from BINANCE

// special shiba case
// force underlying asset if perp in name
// force binance
the_string_perp = "BINANCE:" + str.replace(
  str.replace(syminfo.ticker, "PERP", "")
  , "SHIB", "1000SHIB") + "PERP"

the_string_not_perp = "BINANCE:" + str.replace(
  str.replace(syminfo.ticker, "PERP", "")
  , "SHIB", "1000SHIB")


//is a perp syminfo.root


symOpen = request.security(the_string_perp, timeframe.period, open)
symOpen_underlying = request.security(the_string_not_perp, timeframe.period, open)

col = color.rgb(255, 255, 255)
ema_period = input(defval=13, title="EMA")

if ta.ema(symOpen, ema_period) > ta.ema(symOpen_underlying, ema_period)
    col := color.rgb(50, 155, 210)
else
    col := color.rgb(185, 0, 100)

//plot(ta.ema(symOpen - open, 13), color=col, style=plot.style_area)
plot(ta.ema(symOpen - symOpen_underlying, ema_period), color=col, style=plot.style_columns)

//debug 
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.normal, 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, 0)
    label.set_text(_label, _text)

// f_print_source(symOpen, the_string_perp)