Bollinger Bands Reversal
Find reversion to the mean trade setups, using this simple, but powerful indicator layered on top of the Bollinger Bands
Introduction
In this step-by-step ThinkOrSwim coding tutorial, we’ll build a reversal indicator, using the Bollinger Bands.
The Bollinger Bands Reversal indicator that we’ll build is useful for capitalizing on mean reversion trades, and taking advantage of price movements outside the standard Bollinger Bands. The indicator identifies potential reversal points, plotting buy and sell signals based on specific conditions.
Let’s dive into the steps required to code this indicator in ThinkOrSwim’s thinkScript.
Volatility Box Invite
We are TOS Indicators.com, home of the Volatility Box.
The Volatility Box is our secret tool, to help us consistently profit from the market place. We’re a small team, and we spend hours every day, after the market close, doing nothing but studying thousands of data points to keep improving and perfecting the Volatility Box price ranges.
We have two different Volatility Boxes - a Futures Volatility Box and a Stock Volatility Box.
Futures Volatility Box - Trade Major Markets With an Edge
Designed For: Futures, Micro-Futures and Index Market Traders
Supported Models: Hourly Volatility Box models
Supported Markets: 10 Major Futures Markets
The Futures Volatility Box comes with:
- 5 Volatility Models for each market
- Support for 10 Futures Markets (/ES, /NQ, /YM, /RTY, /CL, /GC, /SI, /ZB, /HG, /NG)
- Video Setup Guide
- Trade Plan
- Access to all members-only resources, including Squeeze Course
Learn More About the Futures Volatility Box
Trade futures and micro futures with a consistent volatility edge
Stock Volatility Box - Powerful Web Based Volatility Platform
Designed For: Stock and Options Traders
Supported Models: Hourly and Daily Volatility Box models
Supported Markets: 10,000+ Stocks and ETFs (new markets added frequently)
A Stock Volatility Box membership includes access to:
- Live Scanner - A powerful scanner we've built from scratch, to scan 10,000 symbols every 2 seconds for new volatility breaches
- Dashboard - A quick and easy way to view daily volatility model levels online
- Short Interest Scanner - Short interest, Squeeze, and EMA data to find short squeezes
- Squeeze Course - All of our proprietary squeeze tools, including robust backtesters
- All Members Only Indicators - We don't nickel and dime you. Everything really is included.
- And much more!
Learn More About the Stock Volatility Box
Trade stocks and options with a consistent volatility edge
Understanding Bollinger Bands
Bollinger Bands are a versatile technical indicator that helps you visualize volatility and price trends. They consist of three lines: the middle band, which is usually a 20-period simple moving average (SMA), and two outer bands that are typically set two standard deviations above and below the SMA. These outer bands expand and contract based on market volatility. When price action nears the upper band, it indicates potential overbought conditions, while nearing the lower band suggests potential oversold conditions. You can use Bollinger Bands to track price movements, anticipate volatility shifts, and pinpoint possible trend reversals.
Why Bollinger Bands Are Useful for Reversals
You can leverage Bollinger Bands effectively to spot potential reversal points. When the price pushes outside the upper or lower bands, it’s often a signal that the current trend is overextended, and a reversal could be imminent. For example, if price breaks below the lower band but then quickly reverses upward, you might catch a long opportunity as the price reverts to the mean (the middle SMA). Similarly, a move above the upper band followed by a sharp reversal downward can signal a short opportunity. These bands give you an intuitive way to spot possible reversals and time entries and exits based on price action relative to volatility.
Step-by-Step Guide to Building the Bollinger Bands Reversal Indicator
Step 1: Define the Upper and Lower Bollinger Bands
To start, we define the upper, lower, and mid Bollinger Bands, which serve as the core of this indicator. ThinkOrSwim has a built-in function for Bollinger Bands, so we’ll leverage that here:
def lowerBand = BollingerBands().lowerBand;
def upperBand = BollingerBands().upperBand;
def mid = BollingerBands().MidLine;
The lowerBand
and upperBand
lines represent two standard deviations from the simple moving average (SMA), which is mid
. These three lines will frame our trading signals based on price movements around them.
Step 2: Define Conditions for Signal Generation
This indicator requires certain conditions to be met for generating buy and sell signals. We need conditions for the price to be outside the Bollinger Bands and for additional validation to reduce false signals:
# Requirement 1
def cond1 = low[1] < lowerBand[1]; def cond2 = high[1] > upperBand[1];
# Requirement 2
def cond3 = close > high[1];
def cond4 = close < low[1];
# Filter out false signals:
def cond5 = high < mid; def cond6 = low > mid;
These conditions work together to determine our buy and sell signals. Specifically, cond1
and cond2
check if the price has moved outside the bands, while cond3
and cond4
confirm that a reversal candle has occurred. cond5
and cond6
add a filter for signals by verifying the relationship between the price and the midline.
Step 3: Define Buy Signal
The buy signal triggers when the price meets all conditions for a long trade. We’re also setting the appearance of the signal with a plot style and line weight:
plot bullSignal = cond1 and cond3 and cond5 and low <= 20;
bullSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
bullSignal.SetLineWeight(3);
The bullSignal
appears when the price is below the lower Bollinger Band, the close is above the previous candle’s high, and the high is under the midline. We apply a visual style using BOOLEAN_ARROW_UP
to plot an upward arrow when these conditions are met.
Step 4: Define Sell Signal
Now, let’s define the sell signal, which operates similarly but focuses on the price exceeding the upper Bollinger Band:
plot bearSignal = cond2 and cond4 and cond6 and high >= 30;
bearSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
bearSignal.SetLineWeight(3);
The bearSignal
plots a downward arrow whenever the price meets all conditions for a sell setup. It appears when the high exceeds the upper band, the close is below the previous low, and the low remains above the midline, indicating a potential bearish reversal.
Step 5: Customize Signal Settings
ThinkOrSwim allows for signal customization, so feel free to adjust the low <= 20
and high >= 30
conditions in both bullSignal
and bearSignal
. These parameters let you refine how extreme the conditions should be before a signal plots.
Step 6: Add to Your ThinkOrSwim Chart
Once you’ve entered the code, save it as a custom indicator by going to Studies > Create, then naming and saving your code. Afterward, you can load it onto any chart in ThinkOrSwim:
1. Go to the Studies icon.
2. Select “Create” to start a new custom indicator.
3. Copy and paste the code from the tutorial into the editor.
4. Save and apply the indicator to see it in action.
With the Bollinger Bands Reversal Indicator now on your chart, you should see the buy and sell signals plotted based on the conditions coded above.
Conclusion
That brings us to the end of this tutorial!
Hopefully, you’ve learned how to not only build this Bollinger Bands Reversal Indicator, but also understood why it provides a solid foundation for reversal-based trading strategies (particularly suitable for mean reversion setups). As with any strategy, consider testing it thoroughly on a demo account or historical data before using it in live trading.
Use this as a starting point for building more complex strategies!
Thanks for following along, and as always, good luck trading!
downloads
Download the Bollinger Bands Reversal Indicator for ThinkorSwim.
The download contains a STUDY.ts file, which you can directly import into your ThinkOrSwim platform.
Download Indicator
Download the Bollinger Bands Reversal Indicator for ThinkorSwim.
The download contains a STUDY.ts file, which you can directly import into your ThinkOrSwim platform.