Comparative Relative Strength for Crypto (USDT/USD)
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Dr-Redux - Enitrely based on code CRS by © bharatTrader - / spontaneously inspired by TradingWithTrend 
// Thank you both for your knowledge and efforts - #Appreciated
//@version=5
indicator("Comparative Relative Strength for Crypto (USDT/USD)", shorttitle="Crypto Comparitive RS")

//Input
source = input(title='Source', defval=close)
comparativeTickerId = input.symbol('CIX', title='CIX100 Comparative Index')
//note that CIX is 'conveniently' used as a prefix here - which populates the drop down with all current Crypto Indices 
showMA = input(defval=false, title='', inline="ma", group="CRS Moving Avg")
lenghtMA = input.int(10, minval=1, title='Period', inline="ma", group="CRS Moving Avg")
colorTrend = input(defval=true, title='Color Average Trend', inline="ma2", group="CRS Moving Avg")
lookbackMATrend = input.int(title="Lookback", minval=1, defval=3, group="MA Trend", inline="ma2",group="CRS Moving Avg")

//Set up
baseSymbol = request.security(syminfo.tickerid, timeframe.period, source)
comparativeSymbol = request.security(comparativeTickerId, timeframe.period, source)
//Calculations
crs = baseSymbol / comparativeSymbol
crsSma = ta.sma(crs, lenghtMA)
//Color
baseColor = color.new(color.blue, 0)
crsRising =  ta.rising(crsSma, lookbackMATrend)
crsFalling = ta.falling(crsSma, lookbackMATrend)
crsColor = colorTrend ? crsRising ? color.new(color.green, 0) : crsFalling ? color.new(color.red, 0) : baseColor : baseColor

//Plot
plot(crs, title='CRS', color=color.new(color.orange, 0), linewidth=2)
plot(showMA ? crsSma : na, color=crsColor, title='MA', linewidth=2)


