Bollinger Breakout EA MT5 — No Code

Bollinger Bands breakout recipe: Length 20, Std Dev 2, Breakout Up/Down conditions, all eight BB condition types, export and backtest.

📖 12 min read

📝 2,338 words

🏷️ MQL5 and Expert Advisors

Share this article:

Bollinger Breakout EA MT5 — No Code

Can I build a Bollinger Band breakout EA for MT5 without coding?

Yes. In AlfaTactix Strategy Builder, write the Buy rule on Step 3 — Entry rules as one line: Buy when Close crosses above BB upper(20, 2) (Bollinger Bands with Length 20, Width (standard deviations) 2). Write the Sell rule the other way round: Close crosses below BB lower(20, 2). Add a Stop loss on Step 5 and the position size on Step 6, press Save strategy in Step 7, then Get the code, compile once in MetaEditor, and backtest on H1 EURUSD with Every tick in the Strategy Tester.

Optional squeeze first: add a second line in the group All of these: BB BandWidth at or below its lowest of the last 120 bars, with Happened within the last N bars.

Disclosure: This tutorial uses AlfaTactix Strategy Builder. For the full no-code platform overview, see Build EA Without Coding. For Bollinger Bands indicator theory (squeeze, %B, band walk), see the Bollinger Bands Academy guide. For a mean-reversion counterpart, see RSI Overbought/Oversold EA — No Code.

Related guides: Create/Edit MT5 EA · EA Risk Management · Backtest in Strategy Tester · EA Strategy Library


What Is a Bollinger Band Breakout EA?

A Bollinger Band breakout Expert Advisor automates one of the most popular volatility expansion systems in trading:

SignalRule
Buy (long)Price was inside the bands and breaks above the upper Bollinger Band with momentum
Sell (short)Price was inside the bands and breaks below the lower Bollinger Band with momentum

Bollinger Bands plot three lines: a middle band (typically SMA 20), an upper band (middle + 2 standard deviations), and a lower band (middle − 2 standard deviations). When volatility contracts (squeeze), bands narrow; when price explodes out of the range, a breakout EA enters in the direction of the escape.

The EA runs on every tick or bar in MetaTrader 5 via OnTick() [1]. You do not watch charts manually — the platform executes when your Bollinger condition fires.

Why traders search for this: Bollinger breakouts capture post-squeeze moves and trend continuations. Tutorials usually show hand-written MQL5 with iBands() [2]. This guide shows the same logic in Strategy Builder, with the settings and sentence-builder options that matter for Bollinger Bands.


Classic BB Settings and When It Works

SettingStarter valueNotes
Length20John Bollinger default; 14 = faster, 50 = slower
Width (standard deviations)2Range 0.1–5; 2.5 = wider bands, fewer touches
Middle line averageSMAEMA middle band reacts faster
PriceCloseHigh/Low for wick-sensitive systems
TimeframeH1 (forex majors)M15 = more signals; H4 = cleaner breakouts
SymbolEURUSD, GBPUSDLiquid pairs; spread matters on tight stops
Squeeze windowwithin the last 5 barsOptional: BandWidth at its lowest of the last 120 bars happened within the last 5 bars

Works best: After a squeeze (narrow bands) or when volatility expands — trending sessions on liquid forex (London / New York).

Struggles in: Choppy sideways markets — price pokes outside bands and reverses. Mitigate with Step 4 Market sessions or Spread limit, a squeeze-first line in All of these, or a trend filter from the MA Crossover EA guide.

For indicator background (squeeze, %B, band walk), read the Bollinger Bands Academy guide.


Bollinger Bands Parameters in Strategy Builder

When you pick Bollinger Bands in the indicator picker (tab Indicator) on Step 3 — Entry rules, its settings open:

SettingRange / optionsDefaultWhat it does
Length2 – 20020Lookback bars for the middle band
Width (standard deviations)0.1 – 52Multiplier for the upper/lower band distance from the middle
PriceOpen … (O+H+L+C)/4 (7 choices), under More settingsClosePrice series used in the calculation
Middle line averageSMA, EMA, under More settingsSMAAverage type of the middle band

Pick the Timeframe in the picker too, and use Line to choose which of the five lines you mean: middle, upper, lower, %B or BandWidth.

Tip for breakout EAs: Length 20, Width (standard deviations) 2, Middle line average SMA, Price Close — the industry default. Choose the same Timeframe as your trading timeframe in Step 2 (e.g. H1).


Bollinger Bands Condition Types Explained

In Step 3 every condition is one sentence: What to watch · How they compare · Compare with. In the Buy rule it starts with Buy when. Below is how each Bollinger idea is built.

1. Compare

Under What to watch pick Close (tab Price) or a Bollinger line (tab Indicator, then Line), choose is above, is below, is at or above or is at or below, and under Compare with pick another line, a Number or a price.

Use case: “Only buy breakouts when Close is above BB middle(20, 2)” — a trend filter in the group All of these next to the breakout line.


2. Price crosses a band

Choose the operator crosses above or crosses below. It is true only on the bar where the left side passes the right side.

Classic breakout alternative:

RuleSentence
Buy ruleClose crosses above BB upper(20, 2)
Sell ruleClose crosses below BB lower(20, 2)

Use case: “Price crosses above the upper band” — the whole breakout entry in one line.


3. Squeeze

A squeeze is a narrow band width, often before an explosive move. Two ways to build it:

  • Step 4 quick filter: Trade only after a quiet squeeze (Bollinger BandWidth at its lowest of the last 120 bars).
  • Step 3 line: BB BandWidth is at or below the lowest BB BandWidth of the last 120 bars (tab Calculation, Lowest of).

Use case: “BandWidth at its lowest of the last 120 bars, Happened within the last 5 bars, and Close crosses above BB upper” — enter only after the compression releases.


4. Breakout

Price closes outside the band after being inside — the core condition for this EA. In v2 it is the crossing line from section 2: Close crosses above BB upper(20, 2) for Buy, Close crosses below BB lower(20, 2) for Sell.

To ask for “was in a squeeze recently”, set Time window on the squeeze line to Happened within the last N bars (the catalog example uses 5 bars). “Has been true for N bars in a row” is not offered with crossings.

Use case: Post-squeeze momentum entries; combine with the squeeze or BB BandWidth is rising for higher quality signals.


5. Candle patterns

The tab Patterns and the operator appears are for candle patterns. Most BB breakout EAs do not need them.


6. Rising / falling (slope)

Require the middle band to rise or fall: choose is rising or is falling on BB middle, with Over how many bars and Minimum change (0 = any rise or fall).

Use case: “Close crosses above BB upper and BB middle is rising over 5 bars” — only trade breakouts aligned with the band direction.


7. BandWidth expanding or contracting

Pick the line BandWidth and the operator is rising (volatility increasing) or is falling (volatility decreasing), with Over how many bars.

Use case: “BB BandWidth is rising and Close crosses above BB upper” — enter when volatility expands, not during contraction.


8. Percent B (%B)

Pick the line %B (price position within the bands) and compare it with a Number. The catalog example is “BB %B is below 0” (price below the lower band).

Use case: “%B is above 1” means price is above the upper band; combine with All of these / Any of these as needed.


Combining conditions on Step 3

Lines sit in groups: All of these (every line must be true) or Any of these (one is enough). Must not be true turns a line around. Add lines with Add a condition and groups with Add a group — same idea as in Build EA Without Coding. Example: group All of these with “BandWidth at its lowest of the last 120 bars, within the last 5 bars” and “Close crosses above BB upper”.


Build the BB Breakout EA Step by Step

Workflow: 7 steps in Strategy Builder demo. We detail what matters for a classic BB 20/2 breakout EA.

Step 1 — Information and platform

  • Name: e.g. BB Breakout H1 EURUSD
  • Description: optional

Step 2 — Timeframes

  • Add H1 as the trading timeframe (the lowest one in the list). In Step 3, choose H1 in the Timeframe selector of the Bollinger Bands.
  • Optional: add up to two higher timeframes as context for a trend filter (Advanced MTF Filters).

Step 3 — Entry rules (core)

  1. In the Buy rule, under What to watch, open tab Price and choose Close.
  2. Under How they compare, choose crosses above.
  3. Under Compare with, open tab Indicator and choose Bollinger Bands, Line upper:
    • Length: 20
    • Width (standard deviations): 2
    • Price: Close (under More settings)
    • Middle line average: SMA (under More settings)
    • Timeframe: H1
  4. Write the Sell rule the other way round (Write the sell rule yourself): Close crosses below BB lower(20, 2).

Optional squeeze first on Buy: add a second line in All of these: BB BandWidth is at or below the lowest BB BandWidth of the last 120 bars, Happened within the last 5 bars.

Step 4 — Filters (optional)

Examples: Market sessions (London/New York), a Spread limit, or Market conditions such as the quick filter Skip quiet markets. See Advanced EA MTF & Filters.

Steps 5 and 6 — Exits, risk and money management

Minimum for a testable EA:

SettingSuggestion
Position sizeFixed lots 0.01 on demo, or Risk per trade (% of the account) 1 %
Stop lossUnit Pips or ATR multiple (breakouts need room beyond the band)
Take profitOptional; many BB EAs trail or exit on the opposite breakout
Most trades open at the same time1, to avoid overlapping positions

Full reference: EA Risk Management.

Step 7 — Review and save

Read the Check list, fix any problem it shows, then press Save strategy.


Export, Compile, and Backtest

  1. In Step 7, after Save strategy, press Get the code and choose the MetaTrader 5 code.
  2. Copy to MQL5/Experts, compile (F7) in MetaEditor [3].
  3. Strategy Tester: Every tick, realistic spread, 6–12 months data on H1 EURUSD.
  4. Forward test on Demo before live.

If OrderSend fails with 10016, see Invalid Stops.

The generated code writes the Bollinger calculation out itself and does not call iBands() — see Build EA Without Coding for the full workflow.


Improvements: Filters and Risk

ProblemBuilder lever
False breakouts in rangesA squeeze-first line in All of these; Step 4 Market sessions
Entering during contractionBB BandWidth is rising in All of these with the cross
Counter-trend breakoutsAdd trend filter (see MA Crossover EA)
Spread eats profitStep 4 Spread limit; test on ECN/low-spread symbol
Over-tradingStep 6 Entries per day; keep Most trades open at the same time at 1
Late entriesUse is above BB upper instead of crosses above (more entries, and some are late)

Next Steps

Volatility check: BB breakouts fail in dead ranges. Note bandwidth on your chart last week — if bands were flat, expect false breaks. In the live demo, set Length 20 and Width (standard deviations) 2 and compare one month of breakouts to your manual marks before you get the code.

References: MQL5 iBands [2], MetaTrader 5 Strategy Tester [4].

Frequently Asked Questions

Yes. In AlfaTactix Strategy Builder, write the Buy rule on Step 3 — Entry rules as one line: Buy when Close crosses above BB upper(20, 2). Write the Sell rule the other way round: Close crosses below BB lower(20, 2). Set exits on Step 5 and size on Step 6, press Save strategy in Step 7, then Get the code. Compile once in MetaEditor and backtest in the Strategy Tester.

The classic starter is Length 20, Width (standard deviations) 2, Middle line average SMA and Price Close, on H1 forex majors like EURUSD. In Strategy Builder you set these in the settings of the Bollinger Bands indicator (the picker on Step 3); Price and Middle line average sit under More settings. For indicator theory, see the Bollinger Bands Academy guide.

Close crosses above BB upper is true only on the bar where price passes the band (it was at or below it one bar earlier) — best for a breakout entry after a squeeze or range. Close is above BB upper stays true on every bar outside the band, so it gives more entries. For a classic breakout EA, use crosses above in the Buy rule and crosses below BB lower in the Sell rule.

No. The generated code writes the Bollinger calculation out in the code you download, so you can read it; it does not call the built-in iBands. It uses your Length, Width (standard deviations), Price and Middle line average settings. See Build EA Without Coding.

BB breakouts need expanding volatility or a squeeze release. In tight ranges, price may poke outside bands and snap back — false breakouts. Add Step 4 filters (Market sessions, Spread limit), require a squeeze first with the group All of these, or combine with a trend filter from the MA Crossover EA guide. Read Backtest an EA in the MT5 Strategy Tester before going live.

Add a second line in All of these: BB BandWidth is rising (expanding volatility), or a squeeze first — BB BandWidth at or below its lowest of the last 120 bars, Happened within the last N bars. The Step 4 quick filter Trade only after a quiet squeeze does the same for the whole strategy. Set a realistic Stop loss on Step 5 per EA Risk Management. For mean-reversion instead of breakout, see the RSI Overbought/Oversold EA guide.

References

  1. MetaQuotes, MQL5 Reference. OnTick. https://www.mql5.com/en/docs/event_handlers/ontick
  2. MetaQuotes, MQL5 Reference. iBands. https://www.mql5.com/en/docs/indicators/ibands
  3. MetaQuotes, MetaEditor Help. Welcome to algorithmic trading!. https://www.metatrader5.com/en/metaeditor/help
  4. MetaQuotes. MetaTrader 5 Built-in Trading Strategy Tester. https://www.metatrader5.com/en/automated-trading/strategy-tester