Ready to go further
Next: test a rule honestly
The backtesting guide covers the steps and the traps that catch most band and indicator rules.
What is included
- What it is, in plain words
- The formula or mechanism, with exact arithmetic
- How it hits grid, martingale and DCA bots
- A check you can run before you switch a bot on
Who it is for
- People who run or plan to run a trading bot
- Anyone reading a backtest or a bot sales page
- Readers who want the numbers, not the pitch
- Not advice, and not a signal service
Key facts
- Bollinger Bands draw a moving average, usually of 20 bars, and a band above and below it, usually 2 standard deviations away. The band is wider when prices have been moving more.
- In the made-up window below the 20-bar average is 105.75, the standard deviation is 4.02, so the upper band is 113.80 and the lower band is 97.70 (calculated by us on 28 Oct 2026, exact).
- For a bell curve about 4.6 percent of values fall outside 2 standard deviations. Price changes are not a bell curve, so touches of the band are not as rare as that suggests.
- In a trend the price can close beyond a band again and again. In the made-up rising path 7 of 11 closes were above the upper band, and 7 of the last 10.
- A bot that sells at the upper band and buys at the lower band bets on a return to the average. It loses when the price keeps going.
The formula
For each bar, take the last 20 closes. Find their average, and their standard deviation, which measures how far the closes spread around that average. The bands sit 2 standard deviations above and below the average. Many tools use the population standard deviation, dividing by 20, and some use the sample version, dividing by 19, so values differ a little.
Upper band = middle + 2 x standard deviation
Lower band = middle - 2 x standard deviation
Bandwidth = (upper - lower) / middle
A worked example
Take the first 20 made-up closes in the picture, from 100 to 113. Their average is 105.75. The standard deviation of those closes is 4.02. The upper band is 105.75 + 2 x 4.02 = 113.80 and the lower band is 105.75 - 2 x 4.02 = 97.70. The last close, 113, sits inside. The bandwidth is 15.2 percent of the middle line.
As the path moves on the window slides. The price speeds up, and the average and the standard deviation both rise. The bands follow, but the average lags, so the price can run outside the upper band while the average is still behind it.
Bandwidth, the squeeze and the expansion
Bandwidth is the gap between the bands as a percent of the middle line. In the made-up path it is 15.2 percent in the first window and 34.7 percent in the last, so the bands have widened as the price sped up. Traders talk about a squeeze when bandwidth is low and an expansion when it rises. Bandwidth only describes how much the price has moved, and a narrow band does not tell you which way the next move goes, or whether there will be one.
What the bands do and do not mean
- They measure recent spread, not the future. A narrow band means the last 20 bars moved little. It does not say the next move will be small or large.
- A touch is not a signal. The 95 percent figure belongs to a bell curve. Real price changes have fatter tails and cluster, so closes outside the bands are more common.
- Trends walk the band. In a strong trend the price can sit near or beyond one band for many bars in a row.
How a bot misuses them
The popular bot rule is mean reversion: buy at the lower band, sell at the upper. In a range it can earn small gains. In a trend it keeps selling into a rising price. In this made-up path a rule that sold at each close above the upper band would have sold 7 times while the price kept rising. If it also adds each time, it is averaging against the trend, the same shape as a martingale, with the same risk of one large loss. The average down calculator shows how the average price moves as you add.
How to check a rule that uses the bands
Test it in a range, an uptrend and a downtrend, and count the trades in each. Include the spread and slippage, since a band rule trades often. Do not tune the period and the width to the best past result, which is overfitting. Keep data back and test once, as in backtesting. Look at the max drawdown, which is where mean reversion rules usually show their cost.
What this page does not tell you
It does not say that any setting works. The prices are made up. The bands describe recent spread and nothing more, and this page is education, not a signal.
Keep Going
Related Tools and Guides
Keep exploring
FAQ
Frequently Asked Questions
What are Bollinger Bands?
A moving average with a band above and below it, usually 2 standard deviations away. The band widens when recent prices have moved more and narrows when they have moved less.
How are Bollinger Bands calculated?
Take the average of the last 20 closes and their standard deviation. The upper band is the average plus 2 standard deviations and the lower band is the average minus 2.
Does price stay inside the bands 95 percent of the time?
Only for a bell curve. Real price changes have fatter tails and trends, so closes outside the bands are more common than that.
Can a bot sell at the upper band and buy at the lower band?
It can, and it may earn in a range. In a trend it keeps selling into a rising price or buying into a falling one, so test it in all three kinds of market with full costs.
Why do tools show slightly different bands?
Some use the population standard deviation and some the sample version, and the average can be simple or exponential. The values are close but not identical.
Are the numbers on this page real?
Example numbers are made up to show how the maths works, and the page says so. A figure only counts as exact when the page says it was calculated on a stated date. Nothing you enter in a calculator leaves your browser.
Can I use this to decide whether to run a bot?
It can show whether a bot's numbers hold together and how much an account can lose. It cannot say what the market will do, and it is not advice. Use it to ask better questions, then read the terms of your own broker or exchange.
Is this financial advice?
No. It is general education about a calculation. The prices are made up and it is not a signal.
Know the Risk Before You Run It
Free calculators and guides, added every week. Leave your details and we will email you when new ones go up.
Trading carries a risk of loss