SuperJump QQE MOD MTF
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © SuperJump
//@version=5
//By Glaz, By Mihkel00 Modified

indicator("SuperJump QQE MOD MTF", shorttitle = "Sjump QQE MOD MTF", timeframe="",timeframe_gaps =true)

RSI_Period = input.int(6, title='RSI Length')
SF = input.int(5, title='RSI Smoothing')
QQE = input.int(3, title='Fast QQE Factor')
ThreshHold = input.int(3, title="Threshold")
src = input.source(close, title="RSI Source")

QQELongColor = input.color(color.new(color.green,50), "QQE Long")
QQEShortColor = input.color(color.new(color.red,50), "QQE Short")
QQEWeakColor = input.color(color.new(color.gray,50), "QQE Weak")
isFillBackGround = input.bool(false,"Fill BackGround for higherTimeFrame")



GetQQEDefaultValue(_src, _rsi_period, _sf, _qqe) =>
    _Wilders_Period = _rsi_period * 2 - 1
    _RSI = ta.rsi(_src, _rsi_period)
    _RsiMa = ta.ema(_RSI, _sf)
    _AtrRsi = math.abs(_RsiMa[1] - _RsiMa)
    _MaAtrRsi = ta.ema(_AtrRsi, _Wilders_Period)
    _dar = ta.ema(_MaAtrRsi, _Wilders_Period) * _qqe

    [_Wilders_Period, _RSI, _RsiMa, _AtrRsi, _dar] 

[Wilders_Period, Rsi,RsiMa,AtrRsi,dar] = GetQQEDefaultValue(src, RSI_Period, SF, QQE)

GetFastAtrRsiTL(_dar, _RsiMa)=>
    longband = 0.0
    shortband = 0.0
    trend = 0
    DeltaFastAtrRsi = _dar
    RSIndex = _RsiMa
    newshortband = RSIndex + DeltaFastAtrRsi
    newlongband = RSIndex - DeltaFastAtrRsi
    longband := RSIndex[1] > longband[1] and RSIndex > longband[1] ? math.max(longband[1], newlongband) : newlongband
    shortband := RSIndex[1] < shortband[1] and RSIndex < shortband[1] ? math.min(shortband[1], newshortband) : newshortband
    cross_1 = ta.cross(longband[1], RSIndex)
    trend := ta.cross(RSIndex, shortband[1]) ? 1 : cross_1 ? -1 : nz(trend[1], 1)
    FastAtrRsiTL = trend == 1 ? longband : shortband


FastAtrRsiTL = GetFastAtrRsiTL(dar, RsiMa)



length = input.int(50, minval=1, title="Bollinger Length")
mult = input.float(0.35, minval=0.001, maxval=5, step=0.1, title="BB Multiplier")
basis = ta.sma(FastAtrRsiTL - 50, length)
dev = mult * ta.stdev(FastAtrRsiTL - 50, length)
upper = basis + dev
lower = basis - dev


Zero = hline(0, color=color.white, linestyle=hline.style_dotted, linewidth=1)

////////////////////////////////////////////////////////////////

RSI_Period2 = input(6, title='RSI Length')
SF2 = input(5, title='RSI Smoothing')
QQE2 = input(1.61, title='Fast QQE2 Factor')
ThresHold2 = input(3, title="Threshold")
src2 = input(close, title="RSI Source")


[Wilders_Period2, Rsi2,RsiMa2,AtrRsi2,dar2] = GetQQEDefaultValue(src2, RSI_Period2, SF2, QQE2)
FastAtrRsi2TL = GetFastAtrRsiTL(dar2, RsiMa2)

Greenbar1 = RsiMa2 - 50 > ThresHold2
Greenbar2 = RsiMa - 50 > upper

Redbar1 = RsiMa2 - 50 < 0 - ThresHold2
Redbar2 = RsiMa - 50 < lower

isLongTrend = Greenbar1 and Greenbar2 == 1 
isShortTrend = Redbar1 and Redbar2 == 1 

   
plot(isFillBackGround == false?  FastAtrRsi2TL - 50:na , title='QQE Line', color=color.white, transp=0, linewidth=2)
plot(isFillBackGround == false ? RsiMa2 - 50 :na , title="QQE Area", style=plot.style_area, color= isLongTrend ? QQELongColor : isShortTrend ? QQEShortColor : QQEWeakColor)

isLongSignal = FastAtrRsi2TL - 50 >=0 and ta.crossunder(RsiMa2 - 50,FastAtrRsi2TL - 50) and isFillBackGround == false
isShortSignal = FastAtrRsi2TL - 50 <0 and ta.crossover(RsiMa2 - 50,FastAtrRsi2TL - 50) and isFillBackGround == false
