DINEXSPACEXAUUSD SpecialistEAs available to rentCustom EA: Strategy → Code → BacktestView rentable EA bots
// BOLLINGER_BANDS.MQ5

What are Bollinger Bands?

Bollinger BandsVolatility

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.

Bollinger Bands — BB(20,2) 2,429.8 / 2,382.0 — SIMULATEDDINEXSPACE / VolatilityBB(20,2) 2,429.8 / 2,382.0XAUUSD · 1H / SIMULATEDRESSUP2,315.32,352.12,462.52,423.7▼ SELLCandle 79: SELL▲ BUYCandle 98: BUY▼ SELLCandle 110: SELLVOL*CANDLE 1CANDLE 29CANDLE 57CANDLE 85CANDLE 112MA · EMA 14 ━━━━ / VOL* · ILLUSTRATIVE CANDLE RANGEUpperMiddleLowerIllustrative data — not real market data, not a trading signalBollinger Bands — BB(20,2) 2,429.8 / 2,382.0 — SIMULATEDBOLLINGER 20/2XAUUSD · 1H / SIMULATEDRESSUP2,315.32,352.12,462.52,423.7▼ SELLCandle 110: SELLVOL*Bollinger Bands — BB(20,2) 2,429.8 / 2,382.0 — SIMULATEDBOLLINGER 20/2XAUUSD · 1H / SIMULATEDRESSUP2,315.32,352.12,462.52,423.7▼ SELLCandle 110: SELLVOL*Bollinger Bands — BB(20,2) 2,429.8 / 2,382.0 — SIMULATEDBOLLINGER 20/2XAUUSD · 1H / SIMULATEDRESSUP2,315.32,352.12,462.52,423.7▼ SELLCandle 110: SELLVOL*UpperMiddleLowerIllustrative data — not real market data, not a trading signal

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.

Use this indicator to create a Custom EA brief →
// WHY_USE_IT

Where this indicator is strong

Three reasons Bollinger Bands is still used after decades.

Self-adapting

The bands widen when the market is active and narrow when it is quiet, with no manual adjustment.

Measures the market state

The band width shows whether the market is consolidating or running.

Warns of breakouts

An unusually tight squeeze often comes before a strong move.

// READING_SIGNALS

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.

How to use it in an EA

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.

Fits when

The market moves sideways, with price oscillating around a value zone and often returning to the middle of the bands.

Struggles when

A strong one-way trend. Price rides the band for many sessions, and every trade back toward the middle loses.

Price touches the upper bandPrice has strayed far from its average. In a strong trend, price can ride the band for a long time.
The bands squeezeVolatility is compressing. It often comes before a breakout — but does not show the direction.
Price closes outside the bandsAn unusual move relative to the last 20 candles, not automatically a reversal.
Price returns to the middle lineThe middle line is itself a moving average — it is the balance point.
Common mistakes

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.

// PARAMETERS

Recommended MT5 parameters for Bollinger Bands

Default values of the sample file; test them for your market and timeframe.

ParameterDescription
InpPeriodPeriod of the SMA and standard deviation (default 20).
InpDevStandard deviation multiple for the bands (default 2.0).
// INSTALL

Put the indicator into MetaTrader 5

Four steps, no software needed besides MT5.

01Download the .mq5 file

Click the download button above; the file saves to your computer under the indicator's name.

02Open the data folder

In MetaTrader 5 choose File → Open Data Folder, then go to MQL5/Indicators.

03Compile

Open the file in MetaEditor and click Compile. No errors means the indicator is ready.

04Drag it onto the chart

Go back to MT5, refresh the Navigator and drag the indicator onto the price chart.

📄 bollinger_bands.mq5

DinexSpace wrote this file from the indicator's public formula, not from any commercial source. You are free to edit and reuse it.

// THE_DIFFERENCE

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 OnCalculate and can be copied straight into an EA
External libraries
Not a single #import declaration
Code length
57 lines · 2 input parameters
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.

// COMBINATIONS

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.

Bollinger BandsRelative Strength Index
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.
See Relative Strength Index
Bollinger BandsAverage True Range
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'.
See Average True Range
// FAQ

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.

// SAME_GROUP

Other volatility indicators

Indicators in the same volatility group, often used instead of or alongside Bollinger Bands.

Turn Bollinger Bands into an automated EA

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.

Use this indicator to create a Custom EA brief