SOPR Candles Oscillator
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Gokubro

//@version=5
indicator("SOPR Candles", overlay = false)

string crypto_choice = input.string("BTC", "Type in desired Crypto e.g. BTC, ETH, or LTC")

BTC_SOPR = request.security(crypto_choice + "_SOPR", timeframe.period, close)

matype = input.string(title='Moving Average Type', options=['SMA', 'EMA'], defval='SMA')
length = input(30, 'Moving Average Length')


BTC_SOPR_ema = matype == 'SMA' ? ta.sma(BTC_SOPR, length) : ta.ema(BTC_SOPR, length)


plot(BTC_SOPR-1, title="BTC SOPR", color=color.green, style=plot.style_columns, color=(BTC_SOPR-1>=0? color.gray : color.green))
plot(BTC_SOPR_ema-1, title="BTC SOPR smoothed", color=color.green, style=plot.style_columns, color=(BTC_SOPR_ema-1>=0? color.gray : color.green), display=display.none)

bcolor = BTC_SOPR-1>=0 ? color.green : color.blue
 
barcolor(bcolor)


