QQE (Quantitative Qualitative Estimation) for ThinkorSwim

If I want to change the settings to Faster Periods, the 3 lines on top
input RSI_Period = 20;
input Slow_Factor = 5;

def QQE = 4.236;

All I have to do is change these to
input RSI_Period = 6;
input Slow_Factor = 3;

def QQE = 2.621;

Or, there are other settings within the script that needs to be changed?
Yes and on this line
def QQE = 2.622;

Change def for input
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

I read through this thread after not checking it for a long time and noticed a few people were asking for features or additions to the code that I already had in mine, so thought I'd share what I've been using. I use two of these together (Fast and Slow settings) on the same chart. Each type of cross is indicated with a Dot and each Dot & Flat trend is color coded to make it easier to understand(Colors indicate possible support/resist areas). I did have code included that gave the option to change from fast to slow in a drop down box, but apparently it confused too many.

Included two pictures at the bottom as examples of how it looks and what the possible support and resist areas show up as.

Been making various versions of QQE and it seems like there's always a new way to use it.


Code:
# QQE Indicator
# Converted by Kory Gill for BenTen at useThinkScript.com
# Original https://www.tradingview.com/script/zwbe2plA-Ghosty-s-Zero-Line-QQE/
# Final Version of my QQE before my Leave for a few months 4/16/21 - Xiuying

# Whats been added-
# Points for crossings to let you know what to watch out for
# Labels for when it reaches O/S or O/B and colors change depending on level. Going from Less severity to most, It's Orange , Dark Orange, and Red. Red being the "Watch the **** out" Level.
# Oversold and Overbought levels were added and adjusted to my preferences.
# Added labels for instances where it crosses the 50
# Added Labels for 50 crosses and indicated to watch for Sup/Res
# Added more user friendly features(Colored to indicate possible S/R areas)
# Added option to change oversold and overbought areas, my default from experience is 67/33 but can be adjusted +/- 2 (65/35 or 64/34)
# Default for o/s & o/b are still 30/70, keep that in mind and you can change it by editing the code right below if it bugs ya

declare lower;

input RSI_Period = 20;
input Slow_Factor = 5;
input QQE = 4.236;
input Oversold = 30;
input Overbought = 70;



def Wilder_Period = RSI_Period * 2 - 1;
def vClose = close;

def rsi = RSI(price = vClose, length = RSI_Period).RSI;
def rsi_ma = MovingAverage(AverageType.EXPONENTIAL, rsi, Slow_Factor);
def atr_rsi = AbsValue(rsi_ma[1] - rsi_ma);
def atr_rsi_ma = MovingAverage(AverageType.EXPONENTIAL, atr_rsi, Wilder_Period);
def dar = MovingAverage(AverageType.EXPONENTIAL, atr_rsi_ma, Wilder_Period) * QQE;

def DeltaFastAtrRsi = dar;
def RSIndex = rsi_ma;
def newshortband =  RSIndex + DeltaFastAtrRsi;
def newlongband = RSIndex - DeltaFastAtrRsi;

def longband = if RSIndex[1] > longband[1] and RSIndex > longband[1]
               then Max(longband[1], newlongband)
               else newlongband;

def shortband = if RSIndex[1] < shortband[1] and  RSIndex < shortband[1]
                then Min(shortband[1], newshortband)
                else newshortband;

def trend = if Crosses(RSIndex, shortband[1])
            then 1
            else if Crosses(longband[1], RSIndex)
            then -1
            else if !IsNaN(trend[1])
            then trend[1]
            else 1;

def FastAtrRsiTL = if trend == 1
                   then longband
                   else shortband;





plot pFastAtrRsiTL = FastAtrRsiTL;
plot pRsiMa = rsi_ma;
plot line50 = 50;
plot OB = 67;
plot OS = 33;
plot care = if pRsiMa crosses 50 then pRsiMa else Double.NaN;
plot BReversal = if pRsiMa crosses below Oversold then pRsiMa else Double.NaN;
plot SReversal = if pRsiMa crosses above Overbought then pRsiMa else Double.NaN;
plot Cross = if pRsiMa crosses 50 then pRsiMa else Double.NaN;
plot FRCross = if pRsiMa crosses pFastAtrRsiTL then pRsiMa else Double.NaN;


BReversal.SetPaintingStrategy(paintingStrategy = PaintingStrategy.POINTS);
BReversal.SetLineWeight(3);
BReversal.SetDefaultColor(color = Color.GREEN);
SReversal.SetPaintingStrategy(paintingStrategy = PaintingStrategy.POINTS);
SReversal.SetLineWeight(3);
SReversal.SetDefaultColor(color = Color.RED);
Cross.SetPaintingStrategy(paintingStrategy = PaintingStrategy.POINTS);
Cross.SetLineWeight(2);
Cross.AssignValueColor( if pRsiMa crosses above 50 then Color.RED else Color.GREEN);
FRCross.SetPaintingStrategy(paintingStrategy = PaintingStrategy.POINTS);
FRCross.SetLineWeight(2);
FRCross.AssignValueColor( if pRsiMa crosses above pfastAtrRsiTL then Color.RED else Color.GREEN);




pRsiMa.SetDefaultColor(CreateColor(113, 225, 180));

OB.SetDefaultColor(color = Color.GRAY);
OS.SetDefaultColor(color = Color.GRAY);

#pFastAtrRsiTL.SetDefaultColor(CreateColor(225, 109, 47));
pFastAtrRsiTL.AssignValueColor(if pFastAtrRsiTL == pFastAtrRsiTL[1] and pFastAtrRsiTL < pRsiMa then Color.RED else if pFastAtrRsiTL == pFastAtrRsiTL[1] and pFastAtrRsiTL > pRsiMa then Color.GREEN else CreateColor(225, 109, 47));

AddLabel(pRsiMa < 33, "Oversold", if pRsiMa < 33 and pRsiMa > 20 then Color.ORANGE else if pRsiMa < 20 and pRsiMa > 10 then Color.DARK_ORANGE else Color.RED);
AddLabel(pRsiMa > 68, "OverBought", if pRsiMa > 68 and pRsiMa < 80 then Color.ORANGE else if pRsiMa > 80 and pRsiMa < 90 then Color.DARK_ORANGE else Color.RED);
AddLabel(pRsiMa crosses 50, "Watch for Sup/Res", Color.PINK);

Example.png

Exampl2e.png
 
@OptionsGOAT found this from somebody's share, not sure exactly what the source is, but I guess this is what you are looking for.

Ruby:
# QQE_Mod

declare lower;

input RSI_Length = 6;
input RSI_Smoothing = 5;
input Fast_QQE_Factor = 3.0;
input Threshold = 3;
input RSI_Source = close;
input RSI_Length2 = 6;
input RSI_Smoothing2 = 5;
input Fast_QQE_Factor2 = 1.61;
input Threshold2 = 3;
input RSI_Source2 = close;
input Bollinger_Length = 50;
input BB_Multiplier = 0.35; # min: 0.001, max: 5

# QQE 1
def Wilders_period = RSI_Length * 2 - 1;

def Rsi = RSI(price = RSI_Source, length = RSI_Length);
def RsiMa = MovAvgExponential(Rsi, RSI_Smoothing);
def AtrRsi = absValue(RsiMa[1] - RsiMa);
def MaAtrRsi = MovAvgExponential(AtrRsi, Wilders_Period);
def dar = MovAvgExponential(MaAtrRsi, Wilders_Period) * Fast_QQE_Factor;

def DeltaFastAtrRsi = dar;
def RSIndex = RsiMa;
def newshortband = RSIndex + DeltaFastAtrRsi;
def newlongband = RSIndex - DeltaFastAtrRsi;
def longband = if RSIndex[1] > longband[1] and RSIndex > longband[1] then max(longband[1], newlongband) else newlongband;
def shortband = if RSIndex[1] < shortband[1] and RSIndex < shortband[1] then min(shortband[1], newshortband) else newshortband;
def cross_1 = Crosses(longband[1], RSIndex, CrossingDirection.ANY);
def trend = if Crosses(RSIndex, shortband[1], CrossingDirection.ANY) then 1 else if cross_1 then -1 else if isNaN(trend[1]) then 1 else trend[1];
def FastAtrRsiTL = if trend == 1 then longband else shortband;

# QQE 2
def Wilders_period2 = RSI_Length2 * 2 - 1;

def Rsi2 = RSI(price = RSI_Source2, length = RSI_Length2);
def RsiMa2 = MovAvgExponential(Rsi2, RSI_Smoothing2);
def AtrRsi2 = absValue(RsiMa2[1] - RsiMa2);
def MaAtrRsi2 = MovAvgExponential(AtrRsi2, Wilders_Period2);
def dar2 = MovAvgExponential(MaAtrRsi2, Wilders_Period2) * Fast_QQE_Factor;

def DeltaFastAtrRsi2 = dar2;
def RSIndex2 = RsiMa2;
def newshortband2 = RSIndex2 + DeltaFastAtrRsi2;
def newlongband2 = RSIndex2 - DeltaFastAtrRsi2;
def longband2 = if RSIndex2[1] > longband2[1] and RSIndex2 > longband2[1] then max(longband2[1], newlongband2) else newlongband2;
def shortband2 = if RSIndex2[1] < shortband2[1] and RSIndex2 < shortband2[1] then min(shortband2[1], newshortband2) else newshortband2;
def cross_2 = Crosses(longband2[1], RSIndex2, CrossingDirection.ANY);
def trend2 = if Crosses(RSIndex2, shortband2[1], CrossingDirection.ANY) then 1 else if cross_2 then -1 else if isNaN(trend2[1]) then 1 else trend2[1];
def FastAtrRsiTL2 = if trend2 == 1 then longband2 else shortband2;

# BB

def basis = SimpleMovingAvg(FastAtrRsiTL - 50, Bollinger_Length);
def dev = BB_Multiplier * stdev(FastAtrRsiTL - 50, Bollinger_Length);
def upper = basis + dev;
def lower = basis - dev;

# Ups and Downs

def Greenbar1 = RsiMa2 - 50 > Threshold2;
def Greenbar2 = RsiMa - 50 > upper;

def Redbar1 = RsiMa2 - 50 < 0 - Threshold2;
def Redbar2 = RsiMa - 50 < lower;

# Plots

plot Zero = 0;
Zero.SetDefaultColor(Color.WHITE);

plot QQE_Line = FastAtrRsiTL2 - 50;
QQE_Line.SetDefaultColor(Color.WHITE);
QQE_Line.SetLineWeight(2);

plot Hist = RsiMa2 - 50;
Hist.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Hist.SetLineWeight(4);
Hist.AssignValueColor(
    if Greenbar1 and Greenbar2 == 1 then CreateColor(0, 195, 255)
    else if Redbar1 and Redbar2 == 1 then CreateColor(255, 0, 98)
    else if RsiMa2 - 50 > Threshold2 then Color.DARK_GRAY
    else if RsiMa2 - 50 < 0 - Threshold2 then Color.DARK_GRAY
    else Color.BLACK
);

pls amend DR2 in the QQE2 as below since seems last number missed.

def dar2 = MovAvgExponential(MaAtrRsi2, Wilders_Period2) * Fast_QQE_Factor;

to be

def dar2 = MovAvgExponential(MaAtrRsi2, Wilders_Period2) * Fast_QQE_Factor2;
 
QQE Indicator Scan

Code:
# QQE Indicator Scan
# Converted by Kory Gill for BenTen at useThinkScript.com
# Original https://www.tradingview.com/script/zwbe2plA-Ghosty-s-Zero-Line-QQE/
# Pensar - modified into scan with 4 different choices -

input RSI_Period = 20;
input Slow_Factor = 5;
input QQE = 4.236;

def Wilder_Period = RSI_Period * 2 - 1;
def vClose = close;

def rsi = RSI(price = vClose, length = RSI_Period).RSI;
def rsi_ma = MovingAverage(AverageType.EXPONENTIAL, rsi, Slow_Factor);
def atr_rsi = AbsValue(rsi_ma[1] - rsi_ma);
def atr_rsi_ma = MovingAverage(AverageType.EXPONENTIAL, atr_rsi, Wilder_Period);
def dar = MovingAverage(AverageType.EXPONENTIAL, atr_rsi_ma, Wilder_Period) * QQE;

def DeltaFastAtrRsi = dar;
def RSIndex = rsi_ma;
def newshortband =  RSIndex + DeltaFastAtrRsi;
def newlongband = RSIndex - DeltaFastAtrRsi;

def longband = if RSIndex[1] > longband[1] and RSIndex > longband[1]
               then max(longband[1],newlongband)
               else newlongband;

def shortband = if RSIndex[1] < shortband[1] and  RSIndex < shortband[1]
                then min(shortband[1], newshortband)
                else newshortband;

def trend = if Crosses(RSIndex, shortband[1])
            then 1
            else if Crosses(longband[1], RSIndex)
            then -1
            else if !IsNAN(trend[1])
            then trend[1]
            else 1;

def FastAtrRsiTL = if trend == 1 then longband else shortband;

plot CrossAbove = if rsi_ma crosses above FastAtrRsiTL then 1 else 0;
#plot CrossBelow = if rsi_ma crosses below FastAtrRsiTL then 1 else 0;
#plot Above = if rsi_ma > FastAtrRsiTL then 1 else 0;
#plot Below = if rsi_ma < FastAtrRsiTL then 1 else 0;

# end scan

Here's a picture of what the scan is doing - it visually shows each choice that you can scan for.

QQE.png
I copy pasted this code in to my TOS and it only shows me just one signal (basically the green line with spikes when the cross over takes place for long ) how can I get it to show the short signals as well along with the cyan and pink lines that show trend direction??
 
I copy pasted this code in to my TOS and it only shows me just one signal (basically the green line with spikes when the cross over takes place for long ) how can I get it to show the short signals as well along with the cyan and pink lines that show trend direction??

You got a scanner script in the chart. you don't add this to chart, but call in a scan query. Look around for the custom Study scanners you will fine the examples.
 
QQE DIVERGENCE HISTORGRAM


Code:
# QQE_Mod

#MODS BY CWPARKER23#

declare lower;

input RSI_Length = 6;
input RSI_Smoothing = 5;
input Fast_QQE_Factor = 3.0;
input Threshold = 3;
input RSI_Source = close;
input RSI_Length2 = 6;
input RSI_Smoothing2 = 5;
input Fast_QQE_Factor2 = 1.61;
input Threshold2 = 3;
input RSI_Source2 = close;
input Bollinger_Length = 50;
input BB_Multiplier = 0.35; # min: 0.001, max: 5

# QQE 1
def Wilders_period = RSI_Length * 2 - 1;

def Rsi = RSI(price = RSI_Source, length = RSI_Length);
def RsiMa = MovAvgExponential(Rsi, RSI_Smoothing);
def AtrRsi = absValue(RsiMa[1] - RsiMa);
def MaAtrRsi = MovAvgExponential(AtrRsi, Wilders_Period);
def dar = MovAvgExponential(MaAtrRsi, Wilders_Period) * Fast_QQE_Factor;

def DeltaFastAtrRsi = dar;
def RSIndex = RsiMa;
def newshortband = RSIndex + DeltaFastAtrRsi;
def newlongband = RSIndex - DeltaFastAtrRsi;
def longband = if RSIndex[1] > longband[1] and RSIndex > longband[1] then max(longband[1], newlongband) else newlongband;
def shortband = if RSIndex[1] < shortband[1] and RSIndex < shortband[1] then min(shortband[1], newshortband) else newshortband;
def cross_1 = Crosses(longband[1], RSIndex, CrossingDirection.ANY);
def trend = if Crosses(RSIndex, shortband[1], CrossingDirection.ANY) then 1 else if cross_1 then -1 else if isNaN(trend[1]) then 1 else trend[1];
def FastAtrRsiTL = if trend == 1 then longband else shortband;

# QQE 2
def Wilders_period2 = RSI_Length2 * 2 - 1;

def Rsi2 = RSI(price = RSI_Source2, length = RSI_Length2);
def RsiMa2 = MovAvgExponential(Rsi2, RSI_Smoothing2);
def AtrRsi2 = absValue(RsiMa2[1] - RsiMa2);
def MaAtrRsi2 = MovAvgExponential(AtrRsi2, Wilders_Period2);
def dar2 = MovAvgExponential(MaAtrRsi2, Wilders_Period2) * Fast_QQE_Factor;

def DeltaFastAtrRsi2 = dar2;
def RSIndex2 = RsiMa2;
def newshortband2 = RSIndex2 + DeltaFastAtrRsi2;
def newlongband2 = RSIndex2 - DeltaFastAtrRsi2;
def longband2 = if RSIndex2[1] > longband2[1] and RSIndex2 > longband2[1] then max(longband2[1], newlongband2) else newlongband2;
def shortband2 = if RSIndex2[1] < shortband2[1] and RSIndex2 < shortband2[1] then min(shortband2[1], newshortband2) else newshortband2;
def cross_2 = Crosses(longband2[1], RSIndex2, CrossingDirection.ANY);
def trend2 = if Crosses(RSIndex2, shortband2[1], CrossingDirection.ANY) then 1 else if cross_2 then -1 else if isNaN(trend2[1]) then 1 else trend2[1];
def FastAtrRsiTL2 = if trend2 == 1 then longband2 else shortband2;

# BB

def basis = SimpleMovingAvg(FastAtrRsiTL - 50, Bollinger_Length);
def dev = BB_Multiplier * stdev(FastAtrRsiTL - 50, Bollinger_Length);
def upper = basis + dev;
def lower = basis - dev;

# Ups and Downs

def Greenbar1 = RsiMa2 - 50 > Threshold2;
def Greenbar2 = RsiMa - 50 > upper;

def Redbar1 = RsiMa2 - 50 < 0 - Threshold2;
def Redbar2 = RsiMa - 50 < lower;

# Plots

plot Zero = 0;
Zero.SetDefaultColor(Color.WHITE);

plot QQE_Line = FastAtrRsiTL2 - 50;
QQE_Line.SetDefaultColor(Color.WHITE);
QQE_Line.SetLineWeight(2);



DEF Hist = RsiMa2 - 50;
def x = BarNumber();

def bar = BarNumber();

def Currh = if Hist > 0 then fold i = 1 to Floor(RSI_Length / 2) with p = 1 while p do Hist > getValue(Hist, -i) else 0;

def CurrPivotH = if (bar > RSI_Length and Hist == highest(Hist, Floor(RSI_Length/2)) and Currh) then Hist else double.NaN;

def Currl = if Hist < 0 then fold j = 1 to Floor(RSI_Length / 2) with q = 1 while q do Hist < getValue(Hist, -j)  else 0;

def CurrPivotL = if (bar > RSI_Length and Hist == lowest(Hist, Floor(RSI_Length/2)) and Currl) then Hist else double.NaN;

def CurrPHBar = if !isNaN(CurrPivotH) then bar else CurrPHBar[1];

def CurrPLBar = if !isNaN(CurrPivotL) then bar else CurrPLBar[1];

def PHpoint = if !isNaN(CurrPivotH) then CurrPivotH else PHpoint[1];

def priorPHBar = if PHpoint != PHpoint[1] then CurrPHBar[1] else priorPHBar[1];

def PLpoint = if !isNaN(CurrPivotL)then CurrPivotL else PLpoint[1];

def priorPLBar = if PLpoint != PLpoint[1] then CurrPLBar[1] else priorPLBar[1];

def HighPivots = bar >= highestAll(priorPHBar);

def LowPivots = bar >= highestAll(priorPLBar);

def pivotHigh = if HighPivots then CurrPivotH else double.NaN;

plot PlotHline = pivotHigh;

    PlotHline.enableApproximation();

    PlotHline.SetDefaultColor(Color.yellow);

    PlotHline.SetStyle(Curve.Short_DASH);
PlotHline.SetLineWeight(2);
plot pivotLow = if LowPivots

                then CurrPivotL

                else double.NaN;

    pivotLow.enableApproximation();

    pivotLow.SetDefaultColor(GetColor(7));

    pivotLow.SetStyle(Curve.Short_DASH);
pivotLow.SetLineWeight(2);


plot PivotDot = if !isNaN(pivotHigh)

                then pivotHigh

                else if !isNaN(pivotLow)

                     then pivotLow

                     else double.NaN;

    pivotDot.SetDefaultColor(GetColor(7));

    pivotDot.SetPaintingStrategy(PaintingStrategy.POINTS);

    pivotDot.SetLineWeight(3);

# End Code RSI with Divergence

plot Hist2 = RsiMa2 - 50;
Hist2.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Hist2.SetLineWeight(4);
Hist2.AssignValueColor(
    if Greenbar1 and Greenbar2 == 1 then CreateColor(0, 195, 255)
    else if Redbar1 and Redbar2 == 1 then CreateColor(255, 0, 98)
    else if RsiMa2 - 50 > Threshold2 then Color.DARK_GRAY
    else if RsiMa2 - 50 < 0 - Threshold2 then Color.DARK_GRAY
    else Color.BLACK
);
 
Does anyone know if it'd be possible to turn this indicator into a strategy? My knowledge with ThinkScript and writing code is pretty much non-existent, but if someone has any tips/hints or can share a starting place, I can toy around with it.
Buying condition would be where the RSI plot crosses the Fast ATR; selling would be the Fast ATR crossing the RSI plot.

Not sure if it's possible with the issue I've noticed with the scanner, but I wanted to check. Thanks for the reply and again for putting this forum together! I can't speak for everyone, but the indicators, resources, and collaboration from others I've seen have really helped me develop new skills and fine tune others - it's really appreciated!

Sorry for the unending questions on this one, but is there a way to add up/down arrows on the candles themselves when the the RSI crosses the ATR line? Specifically an up arrow where the RSI crosses above the ATR, and a down arrow when the ATR crosses the RSI? I'm striking out on all fronts in trying to get a working scanner/strategy for this one, but I'm loving the signals I've seen on AMM 2.0 combined with this indicator. I've never used ToS support, and I'm not sure what their limitations are, but would they go through the code to assist with questions like this?

If it can't be done, I understand - I just wanted to make sure. It should go without saying, but thanks again for putting the time and effort in to this forum!

Try this...

in TOS Create a new strategy, paste the code and name the strategy. (you would need to add it twice on the same chart)
Set the chart to 5 min time frame for the best results. (MNQ, MES futures)
add another copy of the indicator to the same strategy chart with different settings .

first indicator setting
input RSI_Period = 26;
input Slow_Factor = 13;
input usereversal = no;
input useorder = yes;


second indicator setting for reversal
input RSI_Period = 232;
input Slow_Factor = 29;
input usereversal = yes;
input useorder = no;

no changes made to the original script except the changes for the strategy orders (also commented out the lower study declaration and plots)

Please let me know if you found better setting for the strategy..


# QQE Indicator
# Converted by Kory Gill for BenTen at useThinkScript.com
# Original https://www.tradingview.com/script/zwbe2plA-Ghosty-s-Zero-Line-QQE/

#declare lower;

input RSI_Period = 232;
input Slow_Factor = 29;
input QQE = 4.236;

def Wilder_Period = RSI_Period * 2 - 1;
def vClose = close;

def rsi = RSI(price = vClose, length = RSI_Period).RSI;
def rsi_ma = MovingAverage(AverageType.EXPONENTIAL, rsi, Slow_Factor);
def atr_rsi = AbsValue(rsi_ma[1] - rsi_ma);
def atr_rsi_ma = MovingAverage(AverageType.EXPONENTIAL, atr_rsi, Wilder_Period);
def dar = MovingAverage(AverageType.EXPONENTIAL, atr_rsi_ma, Wilder_Period) * QQE;

def DeltaFastAtrRsi = dar;
def RSIndex = rsi_ma;
def newshortband = RSIndex + DeltaFastAtrRsi;
def newlongband = RSIndex - DeltaFastAtrRsi;

def longband = if RSIndex[1] > longband[1] and RSIndex > longband[1]
then max(longband[1],newlongband)
else newlongband;

def shortband = if RSIndex[1] < shortband[1] and RSIndex < shortband[1]
then min(shortband[1], newshortband)
else newshortband;

def trend = if Crosses(RSIndex, shortband[1])
then 1
else if Crosses(longband[1], RSIndex)
then -1
else if !IsNAN(trend[1])
then trend[1]
else 1;

def FastAtrRsiTL = if trend == 1
then longband
else shortband;


input useorder = no;
input useorderstoploss = no;
input usereversalstoploss = no;
input usereversal = yes;



addOrder(OrderType.BUY_AUTO,useorder and trend<>trend[1] and trend == 1 ,tickColor = GetColor(1), arrowColor = GetColor(1), name = "B@ "+close);
addOrder(OrderType.sell_AUTO,useorder and trend<>trend[1] and trend == -1 , tickColor = GetColor(4), arrowColor = GetColor(4), name = "S@ " +close);


addOrder(OrderType.BUY_AUTO,usereversal and trend<>trend[1] and trend == -1 ,tickColor = GetColor(1), arrowColor = GetColor(1), name = "Br@ "+close);
addOrder(OrderType.sell_AUTO,usereversal and trend<>trend[1] and trend == 1 , tickColor = GetColor(4), arrowColor = GetColor(4), name = "Sr@ " +close);


addOrder(OrderType.BUY_to_close,useorderstoploss and trend == 1 and rsi_ma < 50 and FastAtrRsiTL < 50,tickColor = GetColor(1), arrowColor = GetColor(1), name = "Bsl@ "+close);
addOrder(OrderType.sell_to_close,useorderstoploss and trend == -1 and rsi_ma > 50 and FastAtrRsiTL > 50, tickColor = GetColor(4), arrowColor = GetColor(4), name = "Ssl@ " +close);


addOrder(OrderType.BUY_to_close,usereversalstoploss and trend == -1 and rsi_ma > 50 and FastAtrRsiTL > 50,tickColor = GetColor(1), arrowColor = GetColor(1), name = "Brv@ "+close);
addOrder(OrderType.sell_to_close,usereversalstoploss and trend == 1 and rsi_ma < 50 and FastAtrRsiTL < 50, tickColor = GetColor(4), arrowColor = GetColor(4), name = "Srv@ " +close);


https://drive.google.com/file/d/1Cf2nC569sj3idwR2DFANEGifSh2v6nNQ/view?usp=sharing


https://drive.google.com/file/d/1Cf2nC569sj3idwR2DFANEGifSh2v6nNQ/view?usp=sharing
 
QQE DIVERGENCE HISTORGRAM


Code:
# QQE_Mod

#MODS BY CWPARKER23#

declare lower;

input RSI_Length = 6;
input RSI_Smoothing = 5;
input Fast_QQE_Factor = 3.0;
input Threshold = 3;
input RSI_Source = close;
input RSI_Length2 = 6;
input RSI_Smoothing2 = 5;
input Fast_QQE_Factor2 = 1.61;
input Threshold2 = 3;
input RSI_Source2 = close;
input Bollinger_Length = 50;
input BB_Multiplier = 0.35; # min: 0.001, max: 5

# QQE 1
def Wilders_period = RSI_Length * 2 - 1;

def Rsi = RSI(price = RSI_Source, length = RSI_Length);
def RsiMa = MovAvgExponential(Rsi, RSI_Smoothing);
def AtrRsi = absValue(RsiMa[1] - RsiMa);
def MaAtrRsi = MovAvgExponential(AtrRsi, Wilders_Period);
def dar = MovAvgExponential(MaAtrRsi, Wilders_Period) * Fast_QQE_Factor;

def DeltaFastAtrRsi = dar;
def RSIndex = RsiMa;
def newshortband = RSIndex + DeltaFastAtrRsi;
def newlongband = RSIndex - DeltaFastAtrRsi;
def longband = if RSIndex[1] > longband[1] and RSIndex > longband[1] then max(longband[1], newlongband) else newlongband;
def shortband = if RSIndex[1] < shortband[1] and RSIndex < shortband[1] then min(shortband[1], newshortband) else newshortband;
def cross_1 = Crosses(longband[1], RSIndex, CrossingDirection.ANY);
def trend = if Crosses(RSIndex, shortband[1], CrossingDirection.ANY) then 1 else if cross_1 then -1 else if isNaN(trend[1]) then 1 else trend[1];
def FastAtrRsiTL = if trend == 1 then longband else shortband;

# QQE 2
def Wilders_period2 = RSI_Length2 * 2 - 1;

def Rsi2 = RSI(price = RSI_Source2, length = RSI_Length2);
def RsiMa2 = MovAvgExponential(Rsi2, RSI_Smoothing2);
def AtrRsi2 = absValue(RsiMa2[1] - RsiMa2);
def MaAtrRsi2 = MovAvgExponential(AtrRsi2, Wilders_Period2);
def dar2 = MovAvgExponential(MaAtrRsi2, Wilders_Period2) * Fast_QQE_Factor;

def DeltaFastAtrRsi2 = dar2;
def RSIndex2 = RsiMa2;
def newshortband2 = RSIndex2 + DeltaFastAtrRsi2;
def newlongband2 = RSIndex2 - DeltaFastAtrRsi2;
def longband2 = if RSIndex2[1] > longband2[1] and RSIndex2 > longband2[1] then max(longband2[1], newlongband2) else newlongband2;
def shortband2 = if RSIndex2[1] < shortband2[1] and RSIndex2 < shortband2[1] then min(shortband2[1], newshortband2) else newshortband2;
def cross_2 = Crosses(longband2[1], RSIndex2, CrossingDirection.ANY);
def trend2 = if Crosses(RSIndex2, shortband2[1], CrossingDirection.ANY) then 1 else if cross_2 then -1 else if isNaN(trend2[1]) then 1 else trend2[1];
def FastAtrRsiTL2 = if trend2 == 1 then longband2 else shortband2;

# BB

def basis = SimpleMovingAvg(FastAtrRsiTL - 50, Bollinger_Length);
def dev = BB_Multiplier * stdev(FastAtrRsiTL - 50, Bollinger_Length);
def upper = basis + dev;
def lower = basis - dev;

# Ups and Downs

def Greenbar1 = RsiMa2 - 50 > Threshold2;
def Greenbar2 = RsiMa - 50 > upper;

def Redbar1 = RsiMa2 - 50 < 0 - Threshold2;
def Redbar2 = RsiMa - 50 < lower;

# Plots

plot Zero = 0;
Zero.SetDefaultColor(Color.WHITE);

plot QQE_Line = FastAtrRsiTL2 - 50;
QQE_Line.SetDefaultColor(Color.WHITE);
QQE_Line.SetLineWeight(2);



DEF Hist = RsiMa2 - 50;
def x = BarNumber();

def bar = BarNumber();

def Currh = if Hist > 0 then fold i = 1 to Floor(RSI_Length / 2) with p = 1 while p do Hist > getValue(Hist, -i) else 0;

def CurrPivotH = if (bar > RSI_Length and Hist == highest(Hist, Floor(RSI_Length/2)) and Currh) then Hist else double.NaN;

def Currl = if Hist < 0 then fold j = 1 to Floor(RSI_Length / 2) with q = 1 while q do Hist < getValue(Hist, -j)  else 0;

def CurrPivotL = if (bar > RSI_Length and Hist == lowest(Hist, Floor(RSI_Length/2)) and Currl) then Hist else double.NaN;

def CurrPHBar = if !isNaN(CurrPivotH) then bar else CurrPHBar[1];

def CurrPLBar = if !isNaN(CurrPivotL) then bar else CurrPLBar[1];

def PHpoint = if !isNaN(CurrPivotH) then CurrPivotH else PHpoint[1];

def priorPHBar = if PHpoint != PHpoint[1] then CurrPHBar[1] else priorPHBar[1];

def PLpoint = if !isNaN(CurrPivotL)then CurrPivotL else PLpoint[1];

def priorPLBar = if PLpoint != PLpoint[1] then CurrPLBar[1] else priorPLBar[1];

def HighPivots = bar >= highestAll(priorPHBar);

def LowPivots = bar >= highestAll(priorPLBar);

def pivotHigh = if HighPivots then CurrPivotH else double.NaN;

plot PlotHline = pivotHigh;

    PlotHline.enableApproximation();

    PlotHline.SetDefaultColor(Color.yellow);

    PlotHline.SetStyle(Curve.Short_DASH);
PlotHline.SetLineWeight(2);
plot pivotLow = if LowPivots

                then CurrPivotL

                else double.NaN;

    pivotLow.enableApproximation();

    pivotLow.SetDefaultColor(GetColor(7));

    pivotLow.SetStyle(Curve.Short_DASH);
pivotLow.SetLineWeight(2);


plot PivotDot = if !isNaN(pivotHigh)

                then pivotHigh

                else if !isNaN(pivotLow)

                     then pivotLow

                     else double.NaN;

    pivotDot.SetDefaultColor(GetColor(7));

    pivotDot.SetPaintingStrategy(PaintingStrategy.POINTS);

    pivotDot.SetLineWeight(3);

# End Code RSI with Divergence

plot Hist2 = RsiMa2 - 50;
Hist2.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Hist2.SetLineWeight(4);
Hist2.AssignValueColor(
    if Greenbar1 and Greenbar2 == 1 then CreateColor(0, 195, 255)
    else if Redbar1 and Redbar2 == 1 then CreateColor(255, 0, 98)
    else if RsiMa2 - 50 > Threshold2 then Color.DARK_GRAY
    else if RsiMa2 - 50 < 0 - Threshold2 then Color.DARK_GRAY
    else Color.BLACK
);
@Cwparker23 are you able to provide anymore detail on how this divergence works? I’d like to look into doing some backtesting using the 1min chart. Thanks
 
Last edited by a moderator:
@Cwparker23 are you able to provide anymore detail on how this divergence works? I’d like to look into doing some backtesting using the 1min chart. Thanks
To use the divergence, you look for the pivot trend in one direction and the histogram in the opposite.
But it cannot not be backtested as the pivots repaint.

The repainted signals cannot be captured, so it is not possible to do backtesting with repainting strategies.
No, repainters cannot be made to not repaint.
 
Thread starter Similar threads Forum Replies Date
Xiuying Repaints QQE MTF (Multi Timeframe) for ThinkorSwim Indicators 22

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
227 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top