Trend Spotter with Squeeze for ThinkorSwim

chewie76

Well-known member
VIP
VIP Enthusiast
This is a creative way to use Bollinger bands to spot the trend. I added the red/orange clouds for squeeze areas where trend is flat. Notice the arrows. They are triggered when price breaks outside the inner shaded bands. This indicator is best on 5 min or more timeframe.

The below picture is /NQ on the 5M. Highlighted the squeeze zones. The Cyan line is a 20 SMA. I use it for confirmation. Works great on the Daily chart. Typically when an arrow triggers, the next day will follow the arrow's direction.

trendtracker.jpg


Link Download: http://tos.mx/Vwdvqqd

Code:
#Trend Spotter
#assembled by Chewie 10-10-2023

input price = close;
input displace = 0;
input length = 10;
input Num_Dev_Dn = -0.80;
input Num_Dev_up = 0.80;
input Num_Dev_Dn2 = -2.3;
input Num_Dev_up2 = 2.3;
input averageType = AverageType.Simple;
input arrows = yes;
input paintbars = yes;

def sDev = stdev(data = price[-displace], length = length);

plot MidLine = MovingAverage(averageType, data = price[-displace], length = length);
plot LowerBand = MidLine + num_Dev_Dn * sDev;
plot UpperBand = MidLine + num_Dev_Up * sDev;
plot LowerBand2 = MidLine + num_Dev_Dn2 * sDev;
plot UpperBand2 = MidLine + num_Dev_Up2 * sDev;

MidLine.AssignValueColor(if MidLine > MidLine[1] then Color.GREEN else Color.red);
LowerBand.AssignValueColor(if MidLine > MidLine[1] then Color.GREEN else Color.red);
UpperBand.AssignValueColor(if MidLine > MidLine[1] then Color.GREEN else Color.red);
Upperband2.setDefaultColor(color.gray);
Lowerband2.setDefaultColor(color.gray);

def UP = MidLine > MidLine[1];
def DOWN = MidLine < MidLine[1];

#AddCloud(Upperband, LowerBand, Color.DARK_GRAY, Color.DARK_GRAY);
def cloud1_top = if UP then Upperband else double.nan;
def cloud2_top = if DOWN then Lowerband else double.nan;

addcloud(cloud1_top, LowerBand, color. dark_green);
addcloud(Upperband, cloud2_top, color. dark_red);

plot DownSignal = if arrows and close crosses below LowerBand then 1 else 0;
plot UpSignal = if arrows and close crosses above Upperband then 1 else 0;
UpSignal.SetPaintingStrategy(PaintingStrategy.Boolean_arrow_up);
DownSignal.SetPaintingStrategy(PaintingStrategy.Boolean_arrow_down);
UpSignal.SetDefaultColor(Color.GREEN);
DownSignal.SetDefaultColor(Color.RED);
UPSIGNAL.HideTitle();
DOWNSIGNAL.HideTitle();
UPSIGNAL.setLineWeight(2);
DOWNSIGNAL.setLineWeight(2);

AssignPriceColor(if PaintBars and Upsignal then color.green else if paintbars and down then Color.RED else if paintbars and downsignal then color.red else if paintbars and up then Color.GREEN else Color.CURRENT);

#SimpleMovingAvg 20

def length1 = 20;
plot SMA = Average(price[-displace], length1);
SMA.SetDefaultColor(color.cyan);
SMA.setlineweight(2);
SMA.HideTitle();

#SQUEEZE

input KELTNER_Lines = yes;

def factorH = 1.0;
def factorM = 1.5;
def trueRangeAverageType = AverageType.SIMPLE;
def shiftH = factorH * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), length);
def shiftM = factorM * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), length);
def average = MovingAverage(averageType, price, length);
def Avg = average[-displace];
def Upper_BandH = if KELTNER_Lines then average[-displace] + shiftH[-displace] else Double.NaN;
def Lower_BandH = if KELTNER_Lines then average[-displace] - shiftH[-displace] else Double.NaN;
def Upper_BandM = if KELTNER_Lines then average[-displace] + shiftM[-displace] else Double.NaN;
def Lower_BandM = if KELTNER_Lines then average[-displace] - shiftM[-displace] else Double.NaN;


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

#End Code
 
Thank you for sharing! Have you found anything that pairs well with this in your testing? Any favorite studies combine well in testing?
 
This is a creative way to use Bollinger bands to spot the trend. I added the red/orange clouds for squeeze areas where trend is flat. Notice the arrows. They are triggered when price breaks outside the inner shaded bands. This indicator is best on 5 min or more timeframe.

The below picture is /NQ on the 5M. Highlighted the squeeze zones. The Cyan line is a 20 SMA. I use it for confirmation. Works great on the Daily chart. Typically when an arrow triggers, the next day will follow the arrow's direction.

View attachment 19887

Link Download: http://tos.mx/Vwdvqqd

Code:
#Trend Spotter
#assembled by Chewie 10-10-2023

input price = close;
input displace = 0;
input length = 10;
input Num_Dev_Dn = -0.80;
input Num_Dev_up = 0.80;
input Num_Dev_Dn2 = -2.3;
input Num_Dev_up2 = 2.3;
input averageType = AverageType.Simple;
input arrows = yes;
input paintbars = yes;

def sDev = stdev(data = price[-displace], length = length);

plot MidLine = MovingAverage(averageType, data = price[-displace], length = length);
plot LowerBand = MidLine + num_Dev_Dn * sDev;
plot UpperBand = MidLine + num_Dev_Up * sDev;
plot LowerBand2 = MidLine + num_Dev_Dn2 * sDev;
plot UpperBand2 = MidLine + num_Dev_Up2 * sDev;

MidLine.AssignValueColor(if MidLine > MidLine[1] then Color.GREEN else Color.red);
LowerBand.AssignValueColor(if MidLine > MidLine[1] then Color.GREEN else Color.red);
UpperBand.AssignValueColor(if MidLine > MidLine[1] then Color.GREEN else Color.red);
Upperband2.setDefaultColor(color.gray);
Lowerband2.setDefaultColor(color.gray);

def UP = MidLine > MidLine[1];
def DOWN = MidLine < MidLine[1];

#AddCloud(Upperband, LowerBand, Color.DARK_GRAY, Color.DARK_GRAY);
def cloud1_top = if UP then Upperband else double.nan;
def cloud2_top = if DOWN then Lowerband else double.nan;

addcloud(cloud1_top, LowerBand, color. dark_green);
addcloud(Upperband, cloud2_top, color. dark_red);

plot DownSignal = if arrows and close crosses below LowerBand then 1 else 0;
plot UpSignal = if arrows and close crosses above Upperband then 1 else 0;
UpSignal.SetPaintingStrategy(PaintingStrategy.Boolean_arrow_up);
DownSignal.SetPaintingStrategy(PaintingStrategy.Boolean_arrow_down);
UpSignal.SetDefaultColor(Color.GREEN);
DownSignal.SetDefaultColor(Color.RED);
UPSIGNAL.HideTitle();
DOWNSIGNAL.HideTitle();
UPSIGNAL.setLineWeight(2);
DOWNSIGNAL.setLineWeight(2);

AssignPriceColor(if PaintBars and Upsignal then color.green else if paintbars and down then Color.RED else if paintbars and downsignal then color.red else if paintbars and up then Color.GREEN else Color.CURRENT);

#SimpleMovingAvg 20

def length1 = 20;
plot SMA = Average(price[-displace], length1);
SMA.SetDefaultColor(color.cyan);
SMA.setlineweight(2);
SMA.HideTitle();

#SQUEEZE

input KELTNER_Lines = yes;

def factorH = 1.0;
def factorM = 1.5;
def trueRangeAverageType = AverageType.SIMPLE;
def shiftH = factorH * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), length);
def shiftM = factorM * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), length);
def average = MovingAverage(averageType, price, length);
def Avg = average[-displace];
def Upper_BandH = if KELTNER_Lines then average[-displace] + shiftH[-displace] else Double.NaN;
def Lower_BandH = if KELTNER_Lines then average[-displace] - shiftH[-displace] else Double.NaN;
def Upper_BandM = if KELTNER_Lines then average[-displace] + shiftM[-displace] else Double.NaN;
def Lower_BandM = if KELTNER_Lines then average[-displace] - shiftM[-displace] else Double.NaN;


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

#End Code

Nice work Chewie. Very nice !! Thx.
 
This is a creative way to use Bollinger bands to spot the trend. I added the red/orange clouds for squeeze areas where trend is flat. Notice the arrows. They are triggered when price breaks outside the inner shaded bands. This indicator is best on 5 min or more timeframe.

The below picture is /NQ on the 5M. Highlighted the squeeze zones. The Cyan line is a 20 SMA. I use it for confirmation. Works great on the Daily chart. Typically when an arrow triggers, the next day will follow the arrow's direction.

View attachment 19887

Link Download: http://tos.mx/Vwdvqqd

Code:
#Trend Spotter
#assembled by Chewie 10-10-2023

input price = close;
input displace = 0;
input length = 10;
input Num_Dev_Dn = -0.80;
input Num_Dev_up = 0.80;
input Num_Dev_Dn2 = -2.3;
input Num_Dev_up2 = 2.3;
input averageType = AverageType.Simple;
input arrows = yes;
input paintbars = yes;

def sDev = stdev(data = price[-displace], length = length);

plot MidLine = MovingAverage(averageType, data = price[-displace], length = length);
plot LowerBand = MidLine + num_Dev_Dn * sDev;
plot UpperBand = MidLine + num_Dev_Up * sDev;
plot LowerBand2 = MidLine + num_Dev_Dn2 * sDev;
plot UpperBand2 = MidLine + num_Dev_Up2 * sDev;

MidLine.AssignValueColor(if MidLine > MidLine[1] then Color.GREEN else Color.red);
LowerBand.AssignValueColor(if MidLine > MidLine[1] then Color.GREEN else Color.red);
UpperBand.AssignValueColor(if MidLine > MidLine[1] then Color.GREEN else Color.red);
Upperband2.setDefaultColor(color.gray);
Lowerband2.setDefaultColor(color.gray);

def UP = MidLine > MidLine[1];
def DOWN = MidLine < MidLine[1];

#AddCloud(Upperband, LowerBand, Color.DARK_GRAY, Color.DARK_GRAY);
def cloud1_top = if UP then Upperband else double.nan;
def cloud2_top = if DOWN then Lowerband else double.nan;

addcloud(cloud1_top, LowerBand, color. dark_green);
addcloud(Upperband, cloud2_top, color. dark_red);

plot DownSignal = if arrows and close crosses below LowerBand then 1 else 0;
plot UpSignal = if arrows and close crosses above Upperband then 1 else 0;
UpSignal.SetPaintingStrategy(PaintingStrategy.Boolean_arrow_up);
DownSignal.SetPaintingStrategy(PaintingStrategy.Boolean_arrow_down);
UpSignal.SetDefaultColor(Color.GREEN);
DownSignal.SetDefaultColor(Color.RED);
UPSIGNAL.HideTitle();
DOWNSIGNAL.HideTitle();
UPSIGNAL.setLineWeight(2);
DOWNSIGNAL.setLineWeight(2);

AssignPriceColor(if PaintBars and Upsignal then color.green else if paintbars and down then Color.RED else if paintbars and downsignal then color.red else if paintbars and up then Color.GREEN else Color.CURRENT);

#SimpleMovingAvg 20

def length1 = 20;
plot SMA = Average(price[-displace], length1);
SMA.SetDefaultColor(color.cyan);
SMA.setlineweight(2);
SMA.HideTitle();

#SQUEEZE

input KELTNER_Lines = yes;

def factorH = 1.0;
def factorM = 1.5;
def trueRangeAverageType = AverageType.SIMPLE;
def shiftH = factorH * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), length);
def shiftM = factorM * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), length);
def average = MovingAverage(averageType, price, length);
def Avg = average[-displace];
def Upper_BandH = if KELTNER_Lines then average[-displace] + shiftH[-displace] else Double.NaN;
def Lower_BandH = if KELTNER_Lines then average[-displace] - shiftH[-displace] else Double.NaN;
def Upper_BandM = if KELTNER_Lines then average[-displace] + shiftM[-displace] else Double.NaN;
def Lower_BandM = if KELTNER_Lines then average[-displace] - shiftM[-displace] else Double.NaN;


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

#End Code
There are many up down arrows within the squeeze zone. Is there any way to mark the arrows when they break outside of the inner shade bands?!
 
There are many up down arrows within the squeeze zone. Is there any way to mark the arrows when they break outside of the inner shade bands?!
All of the arrows break outside the inner shade bands. When in a squeeze, price is very choppy.
 

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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