Crypto Market Cap Oscillator
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © BigPhilBxl

//@version=5
indicator('Crypto Market Cap Oscillator')

// inputs
int length = input.int(21, 'Length', group='Settings')
int hhigh = input.int(20, 'High Bar', group='Settings')
int hlow = input.int(-20, 'Low Bar', group='Settings')

leader_market_cap = input.symbol(title='BTC Market Cap', defval='CRYPTOCAP:BTC', group='Market Cap')
alt_market_cap = input.symbol(title='Alt Market Cap', defval='CRYPTOCAP:TOTAL3', group='Market Cap')
custom_market_cap = input.symbol(title='Custom Crypto Cap', defval='', group='Market Cap') 


// Get BTC & alt market caps
leader_cap = request.security(leader_market_cap, timeframe=timeframe.period, expression=close)
alt_cap = request.security(alt_market_cap, timeframe=timeframe.period, expression=close)

// base 100
leader = 100 - leader_cap[length] / leader_cap * 100
alt = 100 - alt_cap[length] / alt_cap * 100

// plot BTC and Alt market cap 100 base
l = plot(leader, color=color.new(color.orange, 0), linewidth=1, title='BTC Plot')
a = plot(alt, color=color.new(color.blue, 0), title='Alt Plot')

// Custom cap
custom_cap = request.security(custom_market_cap == '' ? ticker.new('CRYPTOCAP', syminfo.basecurrency) : custom_market_cap, timeframe.period, close)
custom = 100 - custom_cap[length] / custom_cap * 100

grad = color.from_gradient(custom, hlow, hhigh, color.lime, color.red)
customplot = plot(custom, linewidth=3, color=color.new(grad, 0), title='Custom Crypto Plot')
baseline = plot(series=0, color=custom > 0 ? color.red : color.lime, style=plot.style_circles, title='Baseline')

// Add horizontal lines
hline(hhigh, title='High')
hline(hlow, title='Low')

