Satoshi Indicator
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Seungdori_

//@version=5

indicator('Satoshi Indicator', overlay=false, precision = 8)
sym = input.symbol(defval = 'BINANCE:BTCUSDT', title = 'Pair', confirm = false)

ma_on = input.bool(defval = true, title = 'Moving Average On/Off', group = 'MA')
len = input.int(defval = 200, title = 'SMA Length', minval = 1, group = 'MA')


filter_indicator = input.string(defval = 'RSI', title = 'Color Satoshi plot with Indicators', options = ['None','RSI', 'Stochastic RSI', 'Disparity', 'Slope'], group = 'Color')

BTC = request.security(sym, timeframe.period, close)

satoshi = (close/BTC)
satoshi_high = (high/BTC)
satoshi_Low = (low/BTC)

ma = ta.sma(source = satoshi, length = len)

//Add on

rsi = ta.rsi(satoshi, length = 14)

stochastic_rsi_k = ta.sma(ta.stoch(rsi, rsi, rsi, 14), 3)
stochastic_rsi_d = ta.sma(stochastic_rsi_k, 3)

disparity = (satoshi - ma) / ma * 100
dis_high = ta.highest(disparity, 100)
dis_low = ta.lowest(disparity, 100)
dis_avg = (dis_high - dis_low)

slope = (ta.hma(satoshi, len) - ta.hma(satoshi, len)[1])
slope_high = ta.highest(slope, len)
slope_low = ta.lowest(slope, len)


mycolor = input.color(color.teal, 'Option Off Color', group = 'Color')
color_overbought= input.color(color.red, 'Overbought', group = 'Color')
color_oversold = input.color(color.green, 'Oversold', group = 'Color')

if filter_indicator == 'RSI'
    mycolor :=  color.from_gradient(rsi, 25, 75, color.new(color_oversold, 0), color.new(color_overbought, 0))
if filter_indicator == 'Stochastic RSI'
    mycolor :=  color.from_gradient(stochastic_rsi_k, 20, 80, color.new(color_oversold, 0), color.new(color_overbought, 0))
if filter_indicator == 'Disparity'
    mycolor :=  color.from_gradient(disparity, -dis_avg, dis_avg, color.new(color_oversold, 0), color.new(color_overbought, 0))
if filter_indicator == 'Slope'
    mycolor := color.from_gradient(slope,slope_low,slope_high, color.new(color_oversold, 0), color.new(color_overbought, 0))

 
//==plots
plot(satoshi, title='Satoshi', linewidth=1, color= mycolor)
plot(ma_on ? ma : na, color = color.new(color.white, 30), title = 'Moving Average', style = plot.style_line)

//==alert

crossover = ta.crossover(satoshi, ma)
crossunder = ta.crossunder(satoshi, ma)

alertcondition(crossover, title = 'Satoshi Crossover MA')
alertcondition(crossunder, title = 'Satoshi Crossunder MA')