Glassnode SOPR for BTC
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ROBO_Trading

//@version=4
study(title = "Glassnode SOPR", shorttitle="SOPR", overlay = false)

//Settings
coin = input(defval = "Bitcoin", options = ["Bitcoin", "Ethereum", "Litecoin"], title = "Cryptocurrency")
len = input(10, title = "SMA")
percent = input(4.0)
bg = input(true, title = "Need background")

//SOPR
symbol = coin == "Ethereum" ? "XTVCETH_SOPR" : coin == "Litecoin" ? "XTVCLTC_SOPR" : "XTVCBTC_SOPR"
sopr = security(symbol, "D", sma(close, len))

//Levels
uplevel = 1 + (percent / 100)
dnlevel = 1 - (percent / 100)

//Background
bgcol = bg == false ? na : sopr > uplevel ? color.red : sopr < dnlevel ? color.lime : na
bgcolor(bgcol, transp = 20)

//Lines
plot(sopr)
plot(uplevel, color = color.red)
plot(1.00, color = color.black)
plot(dnlevel, color = color.lime)