The bands widen when the market is active and narrow when it is quiet, with no manual adjustment.
What are Bollinger Bands?
Draws two bands that flex with the standard deviation to show how far price has strayed from its average.
What is Bollinger Bands?
A price band made of a middle SMA and upper/lower bands set a multiple of standard deviations apart.
Illustrative signals of the rule on simulated data — not a trading recommendation.
Rule: The wick touches the outer BB(20,2) band and price closes back inside: lower band buy, upper band sell. Entry = close of the signal candle; SL = entry ∓ 1.5 × ATR(14); TP1/TP2/TP3 = 1R/2R/3R.
Where this indicator is strong
Three reasons Bollinger Bands is still used after decades.
The band width shows whether the market is consolidating or running.
An unusually tight squeeze often comes before a strong move.
How to read Bollinger Bands signals
How Bollinger Bands produces its number, and what each shape on the chart means.
Formula and how it works
The middle line is the SMA over N periods; the upper/lower bands are the middle line plus/minus K times the standard deviation of price over the same window. The bands narrow when the market is quiet and widen when volatility rises. Price usually moves within this range.
Reversal strategy: look to buy at the lower band and sell at the upper band when the market moves sideways. A squeeze signals that a strong breakout may be coming.
The market moves sideways, with price oscillating around a value zone and often returning to the middle of the bands.
A strong one-way trend. Price rides the band for many sessions, and every trade back toward the middle loses.
Treating a band touch as a reversal signal. The band only says price is far from its average, not that it is about to come back.
Recommended MT5 parameters for Bollinger Bands
Default values of the sample file; test them for your market and timeframe.
| Parameter | Description |
|---|---|
| InpPeriod | Period of the SMA and standard deviation (default 20). |
| InpDev | Standard deviation multiple for the bands (default 2.0). |
Put the indicator into MetaTrader 5
Four steps, no software needed besides MT5.
Click the download button above; the file saves to your computer under the indicator's name.
In MetaTrader 5 choose File → Open Data Folder, then go to MQL5/Indicators.
Open the file in MetaEditor and click Compile. No errors means the indicator is ready.
Go back to MT5, refresh the Navigator and drag the indicator onto the price chart.
DinexSpace wrote this file from the indicator's public formula, not from any commercial source. You are free to edit and reuse it.
How it differs from MetaTrader 5's built-in indicator
The short answer: the formula is not different. What differs is what you can do with it.
Bollinger Bands here gives exactly the same number as MetaTrader 5's built-in version — on purpose. The four points below are what differs, and all four can be read from the very bollinger_bands.mq5 you download.
- Calls a built-in indicator
- No — the calculation sits in
OnCalculateand can be copied straight into an EA - External libraries
- Not a single #import declaration
- Code length
- 57 lines · 2
inputparameters - How it draws
- Drawn over the price chart · calculated incrementally, does not redraw the past
Why this library promises no secret formula — read the full explanation on the library page.
Which indicators to pair Bollinger Bands with, and what you gain
Each indicator only answers one question. Pairing well means covering the right weakness, not stacking more.
- What you gain
- Confirmation at the band edge. A touch without confirmation from another measure only means price is moving far, and says nothing about a reversal.
- Note
- Both indicators are based on averages, so their signals overlap a lot; do not treat them as two independent sources.
- What you gain
- Tells a real squeeze apart. Narrow bands can come from a truly compressed market or just from the parameters; ATR measures the real range and shows which it is.
- Note
- This pair answers 'is volatility coming', but still not 'in which direction'.
- What you gain
- Know when NOT to trade reversals. Bollinger's mean-reversion strategy only survives when ADX is low.
- Note
- Trading back toward the middle while ADX is high is this strategy's worst way to lose.
Frequently asked questions about Bollinger Bands
What does a Bollinger squeeze signal?
Volatility is compressing and a strong move often follows. But a squeeze does NOT tell you whether price will go up or down — to know the direction you need a trend indicator alongside it.
Should I sell when price touches the upper band?
Not automatically. In a strong uptrend, price can ride the upper band for many sessions and every sell loses. Trading the bands only makes sense once you have confirmed the market is moving sideways.
Does Bollinger Bands on this page use real or simulated data?
The chart on this page uses a deterministic simulated candle series; it is not market prices or trading results.
Using Bollinger Bands in an EA, and further reading
State the candle-close condition, parameters and server time clearly when you put the rule into an EA. See the EAs available on the marketplace to compare options, or read how to read MT5 backtest results before judging any EA.
Other volatility indicators
Indicators in the same volatility group, often used instead of or alongside Bollinger Bands.
An indicator draws signals, but when to enter, where to stop out and how much to risk are still your set of rules. Send those rules and DinexSpace builds them into an EA.