Current to BTC [Morty]
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Morty

//@version=5
indicator('Current to BTC [Morty]') 

s2 = input.symbol(title='BTC Symbol', defval='BINANCE:BTCUSDTPERP')

f() =>
    [open, high, low, close, syminfo.basecurrency]

[o1, h1, l1, c1, sym1] = request.security(syminfo.tickerid, timeframe.period, f())
[o2, h2, l2, c2, sym2] = request.security(s2, timeframe.period, f())

c = o1 / o2 < c1 / c2 ? #E2DED0 : #4E4F50
plotcandle(o1 / o2, h1 / h2, l1 / l2, c1 / c2, color=c, wickcolor=c, bordercolor=c)

// Donchian Channels
length = input.int(50, 'Donchian Channel Length', minval=1)
mid_ma_length = input.int(5, 'Midline moving avarage length', minval=1)
lower = ta.lowest(l1 / l2, length)
upper = ta.highest(h1 / h2, length)
basis = math.avg(upper, lower)
pallete = ta.ema(c1 / c2, mid_ma_length) > basis ? #76B947 : #F83839
plot(basis, 'Basis', color=pallete, linewidth=2)
u = plot(upper, 'Upper', color=color.new(#2962FF, 0))
l = plot(lower, 'Lower', color=color.new(#2962FF, 0))
fill(u, l, color=color.rgb(33, 150, 243, 95), title='Background')

// plot labels, e.g. DYDX/BTC
label0 = label.new(bar_index+2, basis, str.format("{0}/{1}", sym1, sym2), textcolor=color.white, style= label.style_label_left)
label.delete(label0[1])
