Strength Vs. BTC (SMA)
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © rydawglv24

//@version=5
indicator("Strength Vs. BTC (SMA)")
btc = input.symbol("BYBIT:BTCUSDT", title = "Compare To")
period = input("5", title = "timeframe")
candleAmount = input(100,title = "Number Of Candles to Include in Avg." )
upColor = input(color.green, title = "Up Color")
downColor = input(color.red, title = "Down Color")

float candleSum = 0
float candleAvg = 0
float btcCandleSum = 0
float btcCandleAvg = 0

float lowCandleSum = 0
float lowCandleAvg = 0
float lowBtcCandleSum = 0
float lowBtcCandleAvg = 0

thisHigh = request.security(syminfo.tickerid, period, high)
btcHigh = request.security(btc, period, high)
btcLow = request.security(btc, period, low)

for i=1 to candleAmount
    candleSum:= candleSum + thisHigh[i]
    btcCandleSum:= btcCandleSum + btcHigh[i]
    if i == candleAmount
        candleAvg:= candleSum / candleAmount
        btcCandleAvg:= btcCandleSum / candleAmount
        
pairPCT = (thisHigh - candleAvg) / thisHigh
btcPCT = (btcHigh - btcCandleAvg) / btcHigh

// for i=1 to candleAmount
//     lowCandleSum:= lowCandleSum + low[i]
//     lowBtcCandleSum:= lowBtcCandleSum + btcLow[i]
//     if i == candleAmount
//         lowCandleAvg:= lowCandleSum / candleAmount
//         lowBtcCandleAvg:= lowBtcCandleSum / candleAmount
        
// lowPairPCT = (candleAvg - low) / candleAvg
// lowBtcPCT = (lowBtcCandleAvg - btcLow) / lowBtcCandleAvg

// highDif = pairPCT - btcPCT
// lowDif = lowPairPCT - lowBtcPCT


plotColor = color.gray
plotPCT = (pairPCT - btcPCT) * 100
if plotPCT < 0
    plotColor := downColor
if plotPCT > 0
    plotColor := upColor


plot(0, color=color.gray)
plot(plotPCT, color=plotColor)
// plot((lowPairPCT - lowBtcPCT) * -100, color=color.red)

