Repaints "Trade In The Shade" -Multi-time frame Current Reverse Engineered RSI with Bands and Squeeze For ThinkOrSwim

Repaints

chewie76

Well-known member
VIP
VIP Enthusiast
If you like the Reverse Engineered RSI indicator, then you are in for a treat. I created a MTF with current version that shows oversold bands/clouds, with a squeeze cloud included. There is an "extreme" line that shows when RSI is over 80 or less than 20. The MTF and current version can be toggled on/off in the settings. The squeeze cloud for both current and MTF can be toggled on/off in the settings. The Colored Candles can be turned on/off. Default settings are MTF 4hr, RSI length =12, Color bars off, extreme off. Feel free to adjust these. The Green and Red Clouds represent when price is "oversold/overbought" in RSI. Yellow arrows are when price leaves these areas on the current timeframe and the magenta and cyan arrows are when price leaves the MTF area. The squeeze has two colors to measure strength. Red is mild and orange is extreme. Enjoy!

This example is on a 4 min chart showing the 4 hour oversold green cloud. Price is exiting the area. Note: cyan arrows are displayed for all of the candles that are in the 4 hour candle time frame.
4oiEDQF.jpg


In this example, on a 15 min chart, but viewing only the 4 hour version. Notice price leaving oversold area, passing through a squeeze, and pushing higher.

lUSqK3Z.jpg


I noticed something interesting when trading. When price went outside the MTF cloud, it caught the low. Here is an example.

https%3A//i.imgur.com/a2OGWWn.jpg[/img]']
a2OGWWn.jpg



Shareable Link:
http://tos.mx/T1N4zwR

CODE:

Code:
# "Trade In The Shade"
# MTF and Current ReverseEngineeringRSI with Bands and Squeeze
# Assembled by Chewie 9/16/2022

input aggregationPeriod = AggregationPeriod.thirty_MIN;
input MTF = yes;
input Current = yes;
input length = 12;
input rsiValue = 50.0;
input rsivaluetop = 70;
input rsivalueb = 30;
input rsivalueOB = 80;
input rsivalueOS = 20;
input smoothingType = {default Wilders, EMA};
input ColorBar = yes;
input MTFColorBar = no;
input Extreme = no;

def closeMTF = close(period = aggregationPeriod);
def price = close;
def priceMTF = closeMTF;
def coeff = rsiValue / (100 - rsiValue);
def chg = price - price[1];
def chgMTF = priceMTF - priceMTF[1];
def diff;
switch (smoothingType) {
case Wilders:
    diff =  (length - 1) * (WildersAverage(Max(-chg, 0), length) * coeff - WildersAverage(Max(chg, 0), length));
case EMA:
    diff =  (length - 1) * (ExpAverage(Max(-chg, 0), length) * coeff - ExpAverage(Max(chg, 0), length)) / 2;
}

def value = price + if diff >= 0 then diff else diff / coeff;
plot RevEngRSI = if Current then CompoundValue(1, value[1], Double.NaN) else Double.NaN;
RevEngRSI.SetDefaultColor(CreateColor(255, 204, 0));
RevEngRSI.SetLineWeight(3);

#MTF RSI

def diffMTF;
switch (smoothingType) {
case Wilders:
    diffMTF =  (length - 1) * (WildersAverage(Max(-chgMTF, 0), length) * coeff - WildersAverage(Max(chgMTF, 0), length));
case EMA:
    diffMTF =  (length - 1) * (ExpAverage(Max(-chgMTF, 0), length) * coeff - ExpAverage(Max(chgMTF, 0), length)) / 2;
}

def valueMTF = priceMTF + if diffMTF >= 0 then diffMTF else diffMTF / coeff;
plot MTFRevEngRSI = if MTF then CompoundValue(1, valueMTF[1], Double.NaN) else Double.NaN;
MTFRevEngRSI.SetDefaultColor(CreateColor(255, 204, 0));
MTFRevEngRSI.SetLineWeight(3);


#top
def coefftop = rsivaluetop / (100 - rsivaluetop);
def difft;
switch (smoothingType) {
case Wilders:
    difft =  (length - 1) * (WildersAverage(Max(-chg, 0), length) * coefftop - WildersAverage(Max(chg, 0), length));
case EMA:
    difft =  (length - 1) * (ExpAverage(Max(-chg, 0), length) * coefftop - ExpAverage(Max(chg, 0), length)) / 2;
}
def valuet = price + if difft >= 0 then difft else difft / coefftop;
plot Top = if Current then CompoundValue(1, valuet[1], Double.NaN) else Double.NaN;
Top.SetDefaultColor(Color.RED);
Top.SetLineWeight(1);

# top MTF
def difftMTF;
switch (smoothingType) {
case Wilders:
    difftMTF =  (length - 1) * (WildersAverage(Max(-chgMTF, 0), length) * coefftop - WildersAverage(Max(chgMTF, 0), length));
case EMA:
    difftMTF =  (length - 1) * (ExpAverage(Max(-chgMTF, 0), length) * coefftop - ExpAverage(Max(chgMTF, 0), length)) / 2;
}
def valuetMTF = priceMTF + if difftMTF >= 0 then difftMTF else difftMTF / coefftop;
plot MTFTop = if MTF then CompoundValue(1, valuetMTF[1], Double.NaN) else Double.NaN;
MTFTop.SetDefaultColor(Color.RED);
MTFTop.SetLineWeight(1);

#Bottom

def coeffb = rsivalueb  / (100 - rsivalueb );
def diffb;
switch (smoothingType) {
case Wilders:
    diffb =  (length - 1) * (WildersAverage(Max(-chg, 0), length) * coeffb - WildersAverage(Max(chg, 0), length));
case EMA:
    diffb =  (length - 1) * (ExpAverage(Max(-chg, 0), length) * coeffb - ExpAverage(Max(chg, 0), length)) / 2;
}

def valueb = price + if diffb >= 0 then diffb else diffb / coeffb;
plot Bottom = if Current then CompoundValue(1, valueb[1], Double.NaN) else Double.NaN;
Bottom.SetDefaultColor(Color.GREEN);
Bottom.SetLineWeight(1);

#bottom MTF
def diffbMTF;
switch (smoothingType) {
case Wilders:
    diffbMTF =  (length - 1) * (WildersAverage(Max(-chgMTF, 0), length) * coeffb - WildersAverage(Max(chgMTF, 0), length));
case EMA:
    diffbMTF =  (length - 1) * (ExpAverage(Max(-chgMTF, 0), length) * coeffb - ExpAverage(Max(chgMTF, 0), length)) / 2;
}

def valuebMTF = priceMTF + if diffbMTF >= 0 then diffbMTF else diffbMTF / coeffb;
plot MTFBottom = if MTF then CompoundValue(1, valuebMTF[1], Double.NaN) else Double.NaN;
MTFBottom.SetDefaultColor(Color.GREEN);
MTFBottom.SetLineWeight(1);


plot down = if Current then close crosses below Top else Double.NaN;
plot up = if Current then close crosses above Bottom else Double.NaN;
plot downMTF = if MTF then closeMTF crosses below MTFTop else Double.NaN;
plot upMTF = if MTF then closeMTF crosses above MTFBottom else Double.NaN;

down.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
up.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
up.SetDefaultColor(Color.YELLOW);
down.SetDefaultColor(Color.YELLOW);
up.SetLineWeight(1);
down.SetLineWeight(1);

downMTF.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
upMTF.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
upMTF.SetDefaultColor(Color.CYAN);
downMTF.SetDefaultColor(Color.MAGENTA);
upMTF.SetLineWeight(1);
downMTF.SetLineWeight(1);

#OB
def coeffOB = rsivalueOB / (100 - rsivalueOB);
def diffOB;
switch (smoothingType) {
case Wilders:
    diffOB =  (length - 1) * (WildersAverage(Max(-chg, 0), length) * coeffOB - WildersAverage(Max(chg, 0), length));
case EMA:
    diffOB =  (length - 1) * (ExpAverage(Max(-chg, 0), length) * coeffOB - ExpAverage(Max(chg, 0), length)) / 2;
}

def valueOB = price + if diffOB >= 0 then diffOB else diffOB / coeffOB;
plot RSIOB =  if Current and Extreme then (CompoundValue(1, valueOB[1], Double.NaN)) else Double.NaN;
RSIOB.SetDefaultColor(Color.DARK_RED);
RSIOB.SetLineWeight(2);

#OB MTF
def diffOBMTF;
switch (smoothingType) {
case Wilders:
    diffOBMTF =  (length - 1) * (WildersAverage(Max(-chgMTF, 0), length) * coeffOB - WildersAverage(Max(chgMTF, 0), length));
case EMA:
    diffOBMTF =  (length - 1) * (ExpAverage(Max(-chgMTF, 0), length) * coeffOB - ExpAverage(Max(chgMTF, 0), length)) / 2;
}

def valueOBMTF = priceMTF + if diffOBMTF >= 0 then diffOBMTF else diffOBMTF / coeffOB;

plot MTFRSIOB =  if MTF and Extreme then (CompoundValue(1, valueOB[1], Double.NaN)) else Double.NaN;
MTFRSIOB.SetDefaultColor(Color.DARK_RED);
MTFRSIOB.SetLineWeight(2);


#OS
def coeffOS = rsivalueOS / (100 - rsivalueOS);
def diffOS;
switch (smoothingType) {
case Wilders:
    diffOS =  (length - 1) * (WildersAverage(Max(-chg, 0), length) * coeffOS - WildersAverage(Max(chg, 0), length));
case EMA:
    diffOS =  (length - 1) * (ExpAverage(Max(-chg, 0), length) * coeffOS - ExpAverage(Max(chg, 0), length)) / 2;
}

def valueOS = price + if diffOS >= 0 then diffOS else diffOS / coeffOS;
plot RSIOS = if Current and Extreme then (CompoundValue(1, valueOS[1], Double.NaN)) else Double.NaN;
RSIOS.SetDefaultColor(Color.DARK_GREEN);
RSIOS.SetLineWeight(2);

#OS MTF

def diffOSMTF;
switch (smoothingType) {
case Wilders:
    diffOSMTF =  (length - 1) * (WildersAverage(Max(-chgMTF, 0), length) * coeffOS - WildersAverage(Max(chgMTF, 0), length));
case EMA:
    diffOSMTF =  (length - 1) * (ExpAverage(Max(-chgMTF, 0), length) * coeffOS - ExpAverage(Max(chgMTF, 0), length)) / 2;
}

def valueOSMTF = priceMTF + if diffOSMTF >= 0 then diffOSMTF else diffOSMTF / coeffOS;
plot MTFRSIOS = if MTF  and Extreme then (CompoundValue(1, valueOSMTF[1], Double.NaN)) else Double.NaN;
MTFRSIOS.SetDefaultColor(Color.DARK_GREEN);
MTFRSIOS.SetLineWeight(2);

def OB = price > Top;
def OS = price < Bottom;
def Neutral = price < Top and price > Bottom;
def ARSI = price > RevEngRSI;
def BRSI = price < RevEngRSI;

AssignPriceColor(if ColorBar and OB then Color.MAGENTA else if ColorBar and OS then Color.CYAN else if ColorBar and ARSI then Color.GREEN else if ColorBar and BRSI then Color.RED else Color.CURRENT);

#MTF Colors
def OBMTF = priceMTF > MTFTop;
def OSMTF = priceMTF < MTFBottom;
def NeutralMTF = priceMTF < MTFTop and priceMTF > MTFBottom;

AssignPriceColor(if MTF and MTFColorBar and OBMTF then Color.RED else if MTF and MTFColorBar and OSMTF then Color.GREEN else if MTF and MTFColorBar and NeutralMTF then Color.WHITE else Color.CURRENT);


# Volatility Bands
input BBands = yes;
def STDEV_Multiplier = 2;
input Volatility_Band = 14;
def RSI_Price = 0; #0-6
def RSI_Price_Line = 2;
input RSI_Period = 14;
def averageType = AverageType.EXPONENTIAL;
def NetChgAvg = MovingAverage(averageType, price - price[1], length);
def TotChgAvg = MovingAverage(averageType, AbsValue(price - price[1]), length);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;

def DYNRSI = reference RSI(RSI_Period);
def Price1 = if averageType == AverageType.SIMPLE then Average(price, RSI_Price_Line) else ExpAverage(price, RSI_Price_Line);

def SDBB = StDev(price, Volatility_Band);

def DYNAverage = Average(price, Volatility_Band);
#DYNAverage.SetDefaultColor(Color.YELLOW);
#DYNAverage.SetLineWeight(1);


plot UpperBollinger = if Current and BBands then DYNAverage + STDEV_Multiplier * SDBB else Double.NaN;
UpperBollinger.SetDefaultColor(Color.RED);
plot LowerBollinger = if Current and BBands then DYNAverage - STDEV_Multiplier * SDBB else Double.NaN;
LowerBollinger.SetDefaultColor(Color.GREEN);
UpperBollinger.SetLineWeight(2);
LowerBollinger.SetLineWeight(2);

AddCloud(UpperBollinger, Top, Color.RED, Color.DARK_GRAY);
AddCloud(Bottom, LowerBollinger, Color.GREEN, Color.DARK_GRAY);

# MTF Volatility Bands

def NetChgAvgMTF = MovingAverage(averageType, priceMTF - priceMTF[1], length);
def TotChgAvgMTF = MovingAverage(averageType, AbsValue(priceMTF - priceMTF[1]), length);
def ChgRatioMTF = if TotChgAvgMTF != 0 then NetChgAvgMTF / TotChgAvgMTF else 0;

def DYNRSIMTF = reference RSI(RSI_Period);
def Price1MTF = if averageType == AverageType.SIMPLE then Average(priceMTF, RSI_Price_Line) else ExpAverage(priceMTF, RSI_Price_Line);

def SDBBMTF = StDev(priceMTF, Volatility_Band);

def DYNAverageMTF = Average(priceMTF, Volatility_Band);
#DYNAverage.SetDefaultColor(Color.YELLOW);
#DYNAverage.SetLineWeight(1);


plot MTFUpperBollinger = if MTF and BBands then DYNAverageMTF + STDEV_Multiplier * SDBBMTF else Double.NaN;
MTFUpperBollinger.SetDefaultColor(Color.RED);
plot MTFLowerBollinger = if MTF and BBands then DYNAverageMTF - STDEV_Multiplier * SDBBMTF else Double.NaN;
MTFLowerBollinger.SetDefaultColor(Color.GREEN);


AddCloud(MTFUpperBollinger, MTFTop, Color.RED, Color.GRAY);
AddCloud(MTFBottom, MTFLowerBollinger, Color.GREEN, Color.GRAY);


# SQUEEZE

def displace = 0;
def lengths = 14;
def Num_Dev_Dn = -2.0;
def Num_Dev_up = 2.0;
input Squeeze = yes;

def averageTypes = AverageType.SIMPLE;
def sDev = StDev(data = price[-displace], length = lengths);
def MidLine = if Squeeze then MovingAverage(averageTypes, data = price[-displace], length = lengths) else Double.NaN;
def LowerBand = if Squeeze then MidLine + Num_Dev_Dn * sDev else Double.NaN;
def UpperBand = if Squeeze then MidLine + Num_Dev_up * sDev else Double.NaN;


#KELTNER CHANNELS

def factorH = 1.0;
def factorM = 1.5;

def trueRangeAverageType = AverageType.SIMPLE;
def shiftH = factorH * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), lengths);
def shiftM = factorM * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), lengths);

def average = MovingAverage(averageTypes, price, lengths);
def Avg = average[-displace];
def Upper_BandH = if Squeeze then average[-displace] + shiftH[-displace] else Double.NaN;
def Lower_BandH = if Squeeze then average[-displace] - shiftH[-displace] else Double.NaN;
def Upper_BandM = if Squeeze then average[-displace] + shiftM[-displace] else Double.NaN;
def Lower_BandM = if Squeeze then average[-displace] - shiftM[-displace] else Double.NaN;


AddCloud(if Squeeze and Upper_BandH < UpperBand and Upper_BandH < Upper_BandM then Double.NaN else Upper_BandH, UpperBand, Color.YELLOW, Color.YELLOW);
AddCloud(if Squeeze and Lower_BandH > LowerBand then Double.NaN else Lower_BandH, LowerBand, Color.YELLOW, Color.YELLOW);
AddCloud(if Squeeze and  Upper_BandM < UpperBand then Double.NaN else Upper_BandM, UpperBand, Color.RED, Color.RED);
AddCloud(if Squeeze and  Lower_BandM > LowerBand then Double.NaN else Lower_BandM, LowerBand, Color.RED, Color.RED);

# MTF SQUEEZE

input MTFSqueeze = yes;

def sDevMTF = StDev(data = priceMTF[-displace], length = lengths);
def MidLineMTF = if MTFSqueeze then MovingAverage(averageTypes, data = priceMTF[-displace], length = lengths) else Double.NaN;
def LowerBandMTF = if MTFSqueeze then MidLineMTF + Num_Dev_Dn * sDevMTF else Double.NaN;
def UpperBandMTF = if MTFSqueeze then MidLineMTF + Num_Dev_up * sDevMTF else Double.NaN;


#KELTNER CHANNELS

def HIGHMTF = high(period = aggregationPeriod);
def lowMTF = low(period = aggregationPeriod);
def shiftHMTF = factorH * MovingAverage(trueRangeAverageType, TrueRange(HIGHMTF, closeMTF, lowMTF), lengths);
def shiftMMTF = factorM * MovingAverage(trueRangeAverageType, TrueRange(HIGHMTF, closeMTF, lowMTF), lengths);

def averageMTF = MovingAverage(averageTypes, priceMTF, lengths);
def Upper_BandHMTF = if MTFSqueeze then averageMTF[-displace] + shiftHMTF[-displace] else Double.NaN;
def Lower_BandHMTF = if MTFSqueeze then averageMTF[-displace] - shiftHMTF[-displace] else Double.NaN;
def Upper_BandMMTF = if MTFSqueeze then averageMTF[-displace] + shiftMMTF[-displace] else Double.NaN;
def Lower_BandMMTF = if MTFSqueeze then averageMTF[-displace] - shiftMMTF[-displace] else Double.NaN;


AddCloud(if MTFSqueeze and Upper_BandHMTF < UpperBandMTF and Upper_BandHMTF < Upper_BandMMTF then Double.NaN else Upper_BandHMTF, UpperBandMTF, Color.YELLOW, Color.YELLOW);
AddCloud(if MTFSqueeze and Lower_BandHMTF > LowerBandMTF then Double.NaN else Lower_BandHMTF, LowerBandMTF, Color.YELLOW, Color.YELLOW);
AddCloud(if MTFSqueeze and  Upper_BandMMTF < UpperBandMTF then Double.NaN else Upper_BandMMTF, UpperBandMTF, Color.RED, Color.RED);
AddCloud(if MTFSqueeze and  Lower_BandMMTF > LowerBandMTF then Double.NaN else Lower_BandMMTF, LowerBandMTF, Color.RED, Color.RED);
 
Last edited:

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

Wow! Pretty Cool! I was wondering if you have a particular way of interpreting divergence? Thanks for your work and time
 
Last edited:
@chewie76 : Currently I'm on a 20-day 1 Hour chart of /NQ and there are three cyan arrows (UpMTF) flickering on and off...While I don't want to assume anything, do the arrows for this indicator repaint?
 
Wow! Pretty Cool! I was wondering if you have a particular way of interpreting divergence? Thanks for your work and time
You'll see divergence when price first pushes into the cloud, and exits, and tries again, but doesn't get to the line, you know it's weakening.
 
@chewie76 : Currently I'm on a 20-day 1 Hour chart of /NQ and there are three cyan arrows (UpMTF) flickering on and off...While I don't want to assume anything, do the arrows for this indicator repaint?
It does not repaint. The reason it was flickering was because the 4 hr price was fluctuating above and below the shaded area. It finally broke higher.
 
If you like the Reverse Engineered RSI indicator, then you are in for a treat. I created a MTF with current version that shows oversold bands/clouds, with a squeeze cloud included. There is an "extreme" line that shows when RSI is over 80 or less than 20. The MTF and current version can be toggled on/off in the settings. The squeeze cloud for both current and MTF can be toggled on/off in the settings. The Colored Candles can be turned on/off. Default settings are MTF 4hr, RSI length =12, Color bars off, extreme off. Feel free to adjust these. The Green and Red Clouds represent when price is "oversold/overbought" in RSI. Yellow arrows are when price leaves these areas on the current timeframe and the magenta and cyan arrows are when price leaves the MTF area. The squeeze has two colors to measure strength. Red is mild and orange is extreme. Enjoy!

This example is on a 4 min chart showing the 4 hour oversold green cloud. Price is exiting the area. Note: cyan arrows are displayed for all of the candles that are in the 4 hour candle time frame.
4oiEDQF.jpg


In this example, on a 15 min chart, but viewing only the 4 hour version. Notice price leaving oversold area, passing through a squeeze, and pushing higher.

lUSqK3Z.jpg



Shareable Link:
http://tos.mx/90FkFNw

CODE:

Code:
# "Trade in the Shade"
# MTF and Current ReverseEngineeringRSI with Bands and Squeeze
# Assembled by Chewie 9/16/2022

input aggregationPeriod = AggregationPeriod.four_hours;
input MTF = yes;
input Current = yes;
input length = 12;
input rsiValue = 50.0;
input rsivaluetop = 70;
input rsivalueb = 30;
input rsivalueOB = 80;
input rsivalueOS = 20;
input smoothingType = {default Wilders, EMA};
input ColorBar = no;
input Extreme = no;

def closeMTF = close(period = aggregationPeriod);
def price = close;
def priceMTF = closeMTF;
def coeff = rsiValue / (100 - rsiValue);
def chg = price - price[1];
def chgMTF = priceMTF - priceMTF[1];
def diff;
switch (smoothingType) {
case Wilders:
    diff =  (length - 1) * (WildersAverage(Max(-chg, 0), length) * coeff - WildersAverage(Max(chg, 0), length));
case EMA:
    diff =  (length - 1) * (ExpAverage(Max(-chg, 0), length) * coeff - ExpAverage(Max(chg, 0), length)) / 2;
}

def value = price + if diff >= 0 then diff else diff / coeff;
plot RevEngRSI = if Current then CompoundValue(1, value[1], Double.NaN) else double.nan;
RevEngRSI.SetDefaultColor(GetColor(8));
RevEngRSI.SetLineWeight(2);

#MTF RSI

def diffMTF;
switch (smoothingType) {
case Wilders:
    diffMTF =  (length - 1) * (WildersAverage(Max(-chgMTF, 0), length) * coeff - WildersAverage(Max(chgMTF, 0), length));
case EMA:
    diffMTF =  (length - 1) * (ExpAverage(Max(-chgMTF, 0), length) * coeff - ExpAverage(Max(chgMTF, 0), length)) / 2;
}

def valueMTF = priceMTF + if diffMTF >= 0 then diffMTF else diffMTF / coeff;
plot MTFRevEngRSI = if MTF then CompoundValue(1, valueMTF[1], Double.NaN) else double.nan;
MTFRevEngRSI.SetDefaultColor(GetColor(8));
MTFRevEngRSI.SetLineWeight(2);


#top
def coefftop = rsivaluetop / (100 - rsivaluetop);
def difft;
switch (smoothingType) {
case Wilders:
    difft =  (length - 1) * (WildersAverage(Max(-chg, 0), length) * coefftop - WildersAverage(Max(chg, 0), length));
case EMA:
    difft =  (length - 1) * (ExpAverage(Max(-chg, 0), length) * coefftop - ExpAverage(Max(chg, 0), length)) / 2;
}
def valuet = price + if difft >= 0 then difft else difft / coefftop;
plot Top = if Current then CompoundValue(1, valuet[1], Double.NaN) else double.nan;
Top.SetDefaultColor(Color.RED);
Top.SetLineWeight(1);

# top MTF
def difftMTF;
switch (smoothingType) {
case Wilders:
    difftMTF =  (length - 1) * (WildersAverage(Max(-chgMTF, 0), length) * coefftop - WildersAverage(Max(chgMTF, 0), length));
case EMA:
    difftMTF =  (length - 1) * (ExpAverage(Max(-chgMTF, 0), length) * coefftop - ExpAverage(Max(chgMTF, 0), length)) / 2;
}
def valuetMTF = priceMTF + if difftMTF >= 0 then difftMTF else difftMTF / coefftop;
plot MTFTop = if MTF then CompoundValue(1, valuetMTF[1], Double.NaN) else double.nan;
MTFTop.SetDefaultColor(Color.RED);
MTFTop.SetLineWeight(1);

#Bottom

def coeffb = rsivalueb  / (100 - rsivalueb );
def diffb;
switch (smoothingType) {
case Wilders:
    diffb =  (length - 1) * (WildersAverage(Max(-chg, 0), length) * coeffb - WildersAverage(Max(chg, 0), length));
case EMA:
    diffb =  (length - 1) * (ExpAverage(Max(-chg, 0), length) * coeffb - ExpAverage(Max(chg, 0), length)) / 2;
}

def valueb = price + if diffb >= 0 then diffb else diffb / coeffb;
plot Bottom = if current then CompoundValue(1, valueb[1], Double.NaN) else double.nan;
Bottom.SetDefaultColor(Color.GREEN);
Bottom.SetLineWeight(1);

#bottom MTF
def diffbMTF;
switch (smoothingType) {
case Wilders:
    diffbMTF =  (length - 1) * (WildersAverage(Max(-chgMTF, 0), length) * coeffb - WildersAverage(Max(chgMTF, 0), length));
case EMA:
    diffbMTF =  (length - 1) * (ExpAverage(Max(-chgMTF, 0), length) * coeffb - ExpAverage(Max(chgMTF, 0), length)) / 2;
}

def valuebMTF = priceMTF + if diffbMTF >= 0 then diffbMTF else diffbMTF / coeffb;
plot MTFBottom = if MTF then CompoundValue(1, valuebMTF[1], Double.NaN) else double.nan;
MTFBottom.SetDefaultColor(Color.GREEN);
MTFBottom.SetLineWeight(1);


plot down = if current then close crosses below top else double.nan;
plot up = if current then close crosses above bottom else double.nan;
plot downMTF = if MTF then closeMTF crosses below MTFtop else double.nan;
plot upMTF = if MTF then closeMTF crosses above MTFbottom else double.nan;

Down.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
Up.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
Up.SetDefaultColor(Color.yellow);
Down.SetDefaultColor(Color.yellow);
Up.setlineweight(1);
Down.setlineweight(1);

DownMTF.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
UpMTF.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
UpMTF.SetDefaultColor(Color.CYAN);
DownMTF.SetDefaultColor(Color.MAGENTA);
UpMTF.setlineweight(2);
DownMTF.setlineweight(2);

#OB
def coeffOB = rsivalueOB / (100 - rsivalueOB);
def diffOB;
switch (smoothingType) {
case Wilders:
    diffOB =  (length - 1) * (WildersAverage(Max(-chg, 0), length) * coeffOB - WildersAverage(Max(chg, 0), length));
case EMA:
    diffOB =  (length - 1) * (ExpAverage(Max(-chg, 0), length) * coeffOB - ExpAverage(Max(chg, 0), length)) / 2;
}

def valueOB = price + if diffOB >= 0 then diffOB else diffOB / coeffOB;
plot RSIOB =  if current and Extreme then (CompoundValue(1, valueOB[1], Double.NaN)) else double.nan;
RSIOB.SetDefaultColor(Color.DARK_RED);
RSIOB.SetLineWeight(2);

#OB MTF
def diffOBMTF;
switch (smoothingType) {
case Wilders:
    diffOBMTF =  (length - 1) * (WildersAverage(Max(-chgMTF, 0), length) * coeffOB - WildersAverage(Max(chgMTF, 0), length));
case EMA:
    diffOBMTF =  (length - 1) * (ExpAverage(Max(-chgMTF, 0), length) * coeffOB - ExpAverage(Max(chgMTF, 0), length)) / 2;
}

def valueOBMTF = priceMTF + if diffOBMTF >= 0 then diffOBMTF else diffOBMTF / coeffOB;

plot MTFRSIOB =  if MTF and Extreme then (CompoundValue(1, valueOB[1], Double.NaN)) else double.nan;
MTFRSIOB.SetDefaultColor(Color.DARK_RED);
MTFRSIOB.SetLineWeight(2);


#OS
def coeffOS = rsivalueOS / (100 - rsivalueOS);
def diffOS;
switch (smoothingType) {
case Wilders:
    diffOS =  (length - 1) * (WildersAverage(Max(-chg, 0), length) * coeffOS - WildersAverage(Max(chg, 0), length));
case EMA:
    diffOS =  (length - 1) * (ExpAverage(Max(-chg, 0), length) * coeffOS - ExpAverage(Max(chg, 0), length)) / 2;
}

def valueOS = price + if diffOS >= 0 then diffOS else diffOS / coeffOS;
plot RSIOS = if current and Extreme then (CompoundValue(1, valueOS[1], Double.NaN)) else double.nan;
RSIOS.SetDefaultColor(Color.DARK_GREEN);
RSIOS.SetLineWeight(2);

#OS MTF

def diffOSMTF;
switch (smoothingType) {
case Wilders:
    diffOSMTF =  (length - 1) * (WildersAverage(Max(-chgMTF, 0), length) * coeffOS - WildersAverage(Max(chgMTF, 0), length));
case EMA:
    diffOSMTF =  (length - 1) * (ExpAverage(Max(-chgMTF, 0), length) * coeffOS - ExpAverage(Max(chgMTF, 0), length)) / 2;
}

def valueOSMTF = priceMTF + if diffOSMTF >= 0 then diffOSMTF else diffOSMTF / coeffOS;
plot MTFRSIOS = if MTF  and Extreme then (CompoundValue(1, valueOSMTF[1], Double.NaN)) else double.nan;
MTFRSIOS.SetDefaultColor(Color.DARK_GREEN);
MTFRSIOS.SetLineWeight(2);

def OB = price > Top;
def OS = price < Bottom;
def Neutral = price < Top and price > Bottom;

AssignPriceColor(if current and ColorBar and OB then Color.RED else if ColorBar and OS then Color.GREEN else if ColorBar and Neutral then Color.WHITE else Color.CURRENT);

#MTF Colors
def OBMTF = priceMTF > MTFTop;
def OSMTF = priceMTF < MTFBottom;
def NeutralMTF = priceMTF < MTFTop and priceMTF > MTFBottom;

AssignPriceColor(if MTF and ColorBar and OBMTF then Color.RED else if MTF and ColorBar and OSMTF then Color.GREEN else if MTF and ColorBar and NeutralMTF then Color.WHITE else Color.CURRENT);


# Volatility Bands
input BBands = yes;
def STDEV_Multiplier = 2;
def Volatility_Band = 14;
def RSI_Price = 0; #0-6
def RSI_Price_Line = 2;
def RSI_Period = 14;
def averageType = AverageType.exponential;
def NetChgAvg = MovingAverage(averageType, price - price[1], length);
def TotChgAvg = MovingAverage(averageType, AbsValue(price - price[1]), length);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;

def DYNRSI = reference RSI(RSI_Period);
def Price1 = if averageType == AverageType.SIMPLE then Average(price, RSI_Price_Line) else ExpAverage(price, RSI_Price_Line);

def SDBB = StDev(price, Volatility_Band);

def DYNAverage = Average(price, Volatility_Band);
#DYNAverage.SetDefaultColor(Color.YELLOW);
#DYNAverage.SetLineWeight(1);


plot UpperBollinger = if current and BBands then DYNAverage + STDEV_Multiplier * SDBB else double.nan;
UpperBollinger.SetDefaultColor(Color.RED);
plot LowerBollinger = if current and BBands then DYNAverage - STDEV_Multiplier * SDBB else double.nan;
LowerBollinger.SetDefaultColor(Color.GREEN);


AddCloud(upperbollinger, top, Color.red, Color.dark_gray);
AddCloud(bottom, lowerbollinger, Color.green, Color.dark_gray);

# MTF Volatility Bands

def NetChgAvgMTF = MovingAverage(averageType, priceMTF - priceMTF[1], length);
def TotChgAvgMTF = MovingAverage(averageType, AbsValue(priceMTF - priceMTF[1]), length);
def ChgRatioMTF = if TotChgAvgMTF != 0 then NetChgAvgMTF / TotChgAvgMTF else 0;

def DYNRSIMTF = reference RSI(RSI_Period);
def Price1MTF = if averageType == AverageType.SIMPLE then Average(priceMTF, RSI_Price_Line) else ExpAverage(priceMTF, RSI_Price_Line);

def SDBBMTF = StDev(priceMTF, Volatility_Band);

def DYNAverageMTF = Average(priceMTF, Volatility_Band);
#DYNAverage.SetDefaultColor(Color.YELLOW);
#DYNAverage.SetLineWeight(1);


plot MTFUpperBollinger = if MTF and BBands then DYNAverageMTF + STDEV_Multiplier * SDBBMTF else double.nan;
MTFUpperBollinger.SetDefaultColor(Color.RED);
plot MTFLowerBollinger = if MTF and BBands then DYNAverageMTF - STDEV_Multiplier * SDBBMTF else double.nan;
MTFLowerBollinger.SetDefaultColor(Color.GREEN);


AddCloud(MTFupperbollinger, MTFtop, Color.red, Color.gray);
AddCloud(MTFbottom, MTFlowerbollinger, Color.green, Color.gray);


# SQUEEZE

def displace = 0;
def lengths = 14;
def Num_Dev_Dn = -2.0;
def Num_Dev_up = 2.0;
input Squeeze = yes;

def averageTypes = AverageType.SIMPLE;
def sDev = StDev(data = price[-displace], length = lengths);
def MidLine = if Squeeze then MovingAverage(averageTypes, data = price[-displace], length = lengths) else double.nan;
def LowerBand = if Squeeze then MidLine + Num_Dev_Dn * sDev else Double.NaN;
def UpperBand = if Squeeze then MidLine + Num_Dev_up * sDev else Double.NaN;


#KELTNER CHANNELS

def factorH = 1.0;
def factorM = 1.5;

def trueRangeAverageType = AverageType.SIMPLE;
def shiftH = factorH * MovingAverage(trueRangeAverageType, TrueRange(High, close, low), lengths);
def shiftM = factorM * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), lengths);

def average = MovingAverage(averageTypes, price, lengths);
def Avg = average[-displace];
def Upper_BandH = if Squeeze then average[-displace] + shiftH[-displace] else Double.NaN;
def Lower_BandH = if Squeeze then average[-displace] - shiftH[-displace] else Double.NaN;
def Upper_BandM = if Squeeze then average[-displace] + shiftM[-displace] else Double.NaN;
def Lower_BandM = if Squeeze then average[-displace] - shiftM[-displace] else Double.NaN;


AddCloud(if Squeeze and Upper_BandH < UpperBand and Upper_BandH < Upper_BandM then double.nan else Upper_BandH, UpperBand, color.YELLOW, color.YELLOW);
AddCloud(if Squeeze and Lower_BandH > LowerBand then double.nan else Lower_BandH, LowerBand, color.YELLOW, color.YELLOW);
AddCloud(if Squeeze and  Upper_BandM < UpperBand then double.nan else Upper_BandM, UpperBand, color.RED, color.RED);
AddCloud(if Squeeze and  Lower_BandM > LowerBand then double.nan else Lower_BandM, LowerBand, color.RED, color.RED);

# MTF SQUEEZE

input MTFSqueeze = yes;

def sDevMTF = StDev(data = priceMTF[-displace], length = lengths);
def MidLineMTF = if MTFSqueeze then MovingAverage(averageTypes, data = priceMTF[-displace], length = lengths) else double.nan;
def LowerBandMTF = if MTFSqueeze then MidLineMTF + Num_Dev_Dn * sDevMTF else Double.NaN;
def UpperBandMTF = if MTFSqueeze then MidLineMTF + Num_Dev_up * sDevMTF else Double.NaN;


#KELTNER CHANNELS

def HIGHMTF = high(period = aggregationPeriod);
def lowMTF = low(period = aggregationPeriod);
def shiftHMTF = factorH * MovingAverage(trueRangeAverageType, TrueRange(HighMTF, closeMTF, lowMTF), lengths);
def shiftMMTF = factorM * MovingAverage(trueRangeAverageType, TrueRange(highMTF, closeMTF, lowMTF), lengths);

def averageMTF = MovingAverage(averageTypes, priceMTF, lengths);
def Upper_BandHMTF = if MTFSqueeze then averageMTF[-displace] + shiftHMTF[-displace] else Double.NaN;
def Lower_BandHMTF = if MTFSqueeze then averageMTF[-displace] - shiftHMTF[-displace] else Double.NaN;
def Upper_BandMMTF = if MTFSqueeze then averageMTF[-displace] + shiftMMTF[-displace] else Double.NaN;
def Lower_BandMMTF = if MTFSqueeze then averageMTF[-displace] - shiftMMTF[-displace] else Double.NaN;


AddCloud(if MTFSqueeze and Upper_BandHMTF < UpperBandMTF and Upper_BandHMTF < Upper_BandMMTF then double.nan else Upper_BandHMTF, UpperBandMTF, color.YELLOW, color.YELLOW);
AddCloud(if MTFSqueeze and Lower_BandHMTF > LowerBandMTF then double.nan else Lower_BandHMTF, LowerBandMTF, color.YELLOW, color.YELLOW);
AddCloud(if MTFSqueeze and  Upper_BandMMTF < UpperBandMTF then double.nan else Upper_BandMMTF, UpperBandMTF, color.RED, color.RED);
AddCloud(if MTFSqueeze and  Lower_BandMMTF > LowerBandMTF then double.nan else Lower_BandMMTF, LowerBandMTF, color.RED, color.RED);
Chewie : This is an awesome study! By far one of the best "signal" type studies ever created. I really like it on a 5 min /ES chart using the 30 min aggregation. The prudent way to use this study would be to just trade the short signals on a down trending day and vise versa. Especially when the signal(s) occur at a confluence of resistance zones on down days. Thank you so much for sharing this great study!
 
Chewie, I am hoping traders reading this post will respond with their ideas about how to use this indicator. I am a SPY scalper trading momentum. I like to trade the 2 minute chart but am open to suggestions. Seeking suggestions about what aggregation setting are best for the 2-3-4 minute charts. Thanks
 
Tried using the suggested above by @rip78. 5 min chart with 30 minute aggregation on the /ES caught short 3902 to 3890 this morning for a scalp. Also, reviewing the 15 min with 4 hour aggregation. Will do some more back-testing.
 
Curious question about a SCAN not a backtest, but a SCAN
Right now i am using 2 SCANS one to search for Longs and one to tell me when to swap to a short. but on occasion stocks are stuck in the middle between long and short. is there a way to rewrite the scan so that i can reverse what the scan does.... AKA on my watchlist, tell me what is not a SHORT. so the scan results will give me the longs AND the ones stuck in middle?

my thought process is as follows when you run Scans, the scan results can become a new watchlist that changes daily. So if the scan i run gives me the list that is NOT a SHORT, i can then run another scan on that list to get my actual trading list.........

so bottom line, i want to run a scan on my WATCH LIST, and only want the scan results to be a LIST, that is NOT .....the 4 variables that make it a short. so instead of scan for something, I'm scan for what it is not....??? thanks for any help
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
596 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