On this page
Back to tutorials

Bollinger Band Breakout EA MT5 — No Code Builder

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

📖 16 min read

📝 3,200 words

🏷️ MQL5 & Expert Advisors

Share this article:

Want to build a no-code strategy right now?

Create your free account in seconds and start building immediately.


Build a Bollinger Band Breakout EA for MT5 — No Code

Quick Answer: Bollinger Band Breakout EA Without Code

Quick answer: Add Bollinger Bands on Step 3 — Signals in AlfaTactix Strategy Builder, set Breakout with Direction = Up, Threshold = 0, Period = 5, Confirmation = 1 for Buy and Breakout with Direction = Down, Threshold = 0, Period = 5, Confirmation = 1 for Sell, configure Length 20, Std Dev 2, Band Type SMA, Source Close, add Stop Loss / lot size on Step 5, Save, export MQL5 from Code Generator, compile once in MetaEditor, and backtest on H1 EURUSD with Every tick in the Strategy Tester.

Alternative buy entry: Breakout Up OR Price Cross with Band = Upper Band, Source = Close (same sell logic with Breakout Down or Price Cross Lower Band).

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


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(). 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(). This guide shows the same logic in Strategy Builder with every parameter and condition the product exposes for Bollinger Bands.


Classic BB Settings and When It Works

SettingStarter valueNotes
Length20John Bollinger default; 14 = faster, 50 = slower
Std Dev2Range 0.1–5; 2.5 = wider bands, fewer touches
Band TypeSMAEMA middle band reacts faster
SourceCloseHigh/Low for wick-sensitive systems
Band WidthOffEnable On to plot bandwidth sub-chart
TimeframeH1 (forex majors)M15 = more signals; H4 = cleaner breakouts
SymbolEURUSD, GBPUSDLiquid pairs; spread matters on tight stops
Breakout Period5Bars ago price must have been inside bands
Breakout Confirmation1 bar2 bars reduces false pokes

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 session/spread filters, Squeeze AND Breakout logic, 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 add Bollinger Bands on Step 3 — Signals, the Parameters panel shows seven fields:

ParameterTypeRange / optionsDefaultWhat it does
LengthNumber2 – 20020Lookback periods for the middle band calculation
Std DevNumber0.1 – 5 (step 0.1)2Multiplier for upper/lower band distance from middle
SourceSelectClose, Open, High, LowClosePrice series used in the calculation
Band TypeSelectSMA, EMASMAMoving average type for the middle band
Band WidthSelectOn, OffOffShow bandwidth indicator line on chart
OffsetNumber-50 – 500Shifts bands forward/backward in bars (advanced; leave 0 for standard EAs)
TimeframeSelect1m, 5m, 15m, 30m, 1h, 4h, 1d, 1w, 1M1dIndicator calculation timeframe (match Step 2 trading TF for simple EAs)

Tip for breakout EAs: Set Length 20, Std Dev 2, Band Type SMA, Source Close — the industry default. Match the indicator Timeframe to your Step 2 trading timeframe (e.g. both H1).

Band Width On: Useful when combining Squeeze or Band Width conditions — you can see contraction/expansion visually. Leave Off for a clean price chart on your first EA.


Bollinger Bands Condition Types Explained

Open a Bollinger Bands indicator on Step 3 → Add condition. The dropdown lists eight condition types. Below is every field the UI exposes.

1. Compare

Compare the Middle Band value to a fixed threshold (or current price when value is zero).

FieldOptions
Operator>, <, >=, <=, ==, !=
ValueNumber (step 0.01); 0 = current Close price

Use case: “Only buy breakouts when Close > Middle Band” — trend filter combined with Breakout using AND.


2. Price Cross

Detect when price crosses a Bollinger band line.

FieldOptions
BandUpper Band · Middle Band · Lower Band
SmoothingNone, SMA, EMA, WMA
Smoothing Length1 – 100 (shown when Smoothing ≠ None; default 5)
SourceClose, Open, High, Low

UI hint: “Which band to check for cross (BUY: lower, SELL: upper)” — but you can set any band per rule.

Classic breakout alternative:

TabBandSource
BuyUpper BandClose
SellLower BandClose

Use case: “Price crosses above upper band” — simpler than full Breakout when you do not need “was inside bands N bars ago” logic.


3. Squeeze

Detect when band width contracts below a threshold — often precedes explosive breakouts.

FieldRange / options
Period1 – 100 (default 20)
ThresholdNumber (step 0.01; default 0.02 = 2% bandwidth)
SmoothingNone, SMA, EMA, WMA
Smoothing Length1 – 100 (when Smoothing ≠ None; default 5)
SourceClose, Open, High, Low

Use case:Squeeze Threshold 0.02 AND Breakout Up” — enter only after volatility compression releases.


4. Breakout

Price breaks outside the bands after being inside — the core condition for this EA.

FieldRange / options
DirectionUp (breaks above Upper) · Down (breaks below Lower)
ThresholdNumber (step 0.01; 0 = band edge only)
Period1 – 50 bars (default 14; use 5 for responsive breakouts)
Confirmation1 – 10 bars (default 1)

Classic breakout recipe:

TabDirectionThresholdPeriodConfirmation
BuyUp051
SellDown051

UI hint: “BUY: up (breaks above Upper), SELL: down (breaks below Lower)”

Use case: Post-squeeze momentum entries; combine with Squeeze or Band Width Up using AND for higher quality signals.


5. Pattern

Chart pattern detection on the Middle Band series.

FieldOptions
Pattern TypeDouble Top, Double Bottom, Head & Shoulders, Inverse H&S, Triangle, Wedge
Min HeightNumber (step 0.01; price units)
Min WidthNumber (bars between pattern points)
Volume ConfirmationNone · Above Average · High

Use case: Advanced entries on middle-band structure; most BB breakout EAs use Breakout only.


6. Slope

Require the Middle Band to be rising or falling by a minimum amount.

FieldRange / options
DirectionUp · Down
Period1 – 50 (default 14)
Min SlopeNumber (0 = any slope; step 0.01)
SmoothingNone, SMA, EMA, WMA
Smoothing Length1 – 100 (when Smoothing ≠ None; default 5)
SourceClose, Open, High, Low

Use case:Breakout Up AND Middle Band Slope Up” — only trade breakouts aligned with band direction.


7. Band Width

Detect expanding or contracting band width over a lookback window.

FieldRange / options
DirectionUp (expanding) · Down (contracting / squeeze)
ThresholdNumber (step 0.01; e.g. 0.03 = 3% bandwidth)
Period1 – 50 (default 14)
Confirmation1 – 10 bars (default 1)

UI hint: “up = Expanding (volatility increasing), down = Contracting (volatility decreasing)”

Use case: Filter breakouts with Band Width Direction Up AND Breakout Up — enter when volatility expands, not during contraction.


8. Percent B (%B)

Compare %B (price position within bands, 0–1 scale) to a threshold.

FieldRange / options
Operator>, <, >=, <=, ==, !=
ValueNumber (0–1 typical; 0.2 near lower, 0.8 near upper)
Period1 – 50 (default 14)
Confirmation1 – 10 bars (default 1)

Use case:Breakout Up when %B > 1” (price above upper band) or mean-reversion prep with %B < 0.2 before a bounce — combine with OR / AND as needed.


Logical combinations on Step 3

Combine indicators and conditions with AND, OR, NOT, parentheses, and groups — same as described in Build EA Without Coding. Example: (Squeeze AND Breakout Up) OR (Price Cross Upper Band).


Build the BB Breakout EA Step by Step

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

Step 1 — Strategy information

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

Step 2 — Timeframes

  • Enable one trading timeframe, e.g. H1 (matches tab tf0 on Step 3).
  • Optional: add a higher timeframe later for trend filter (Advanced MTF Filters).

Step 3 — Signals (core)

  1. Open tab Buy.
  2. Select timeframe H1.
  3. Add indicatorBollinger Bands (Volatility group).
  4. Parameters:
    • Length: 20
    • Std Dev: 2
    • Source: Close
    • Band Type: SMA
    • Band Width: Off
    • Offset: 0
    • Timeframe: 1h (match H1 trading TF)
  5. Add conditionBreakout.
    • Direction: Up
    • Threshold: 0
    • Period: 5
    • Confirmation: 1

Alternative buy (OR logic): Add a second condition group: Price Cross with Band = Upper Band, Smoothing = None, Source = Close. Combine: (Breakout Up) OR (Price Cross Upper).

  1. Open tab Sell.
  2. Add Bollinger Bands again (or mirror rule): Breakout
    • Direction: Down
    • Threshold: 0
    • Period: 5
    • Confirmation: 1

Optional squeeze filter on Buy: Add Squeeze with Period 20, Threshold 0.02, combine Squeeze AND Breakout Up for post-compression entries only.

Step 4 — Filters (optional)

Examples: market session (London/NY), spread cap, ATR filter. See Advanced EA MTF & Filters.

Step 5 — Risk management

Minimum for a testable EA:

SettingSuggestion
Lot / risk %0.01 lot demo or 1% risk
Stop LossFixed pips or ATR-based (breakouts need room beyond the band)
Take ProfitOptional; many BB EAs trail or exit on opposite breakout
One trade at a timeAvoid overlapping positions

Full reference: EA Risk Management.

Step 6 — Preview and Save

Review Buy/Sell rules → Save strategy to your account.


Export, Compile, and Backtest

  1. Open Code Generator → select your saved strategy → MQL5 → download .mq5.
  2. Copy to MQL5/Experts, compile (F7) in MetaEditor.
  3. Strategy Tester: Every tick, realistic spread, 6–12 months data on H1 EURUSD.
  4. Forward test on Demo before live. Read Strategy Tester vs Live.

If OrderSend fails with 10016, see Invalid Stops.

Exported code uses standard iBands() — see Build EA Without Coding for the full export workflow.


Improvements: Filters and Risk

ProblemBuilder lever
False breakouts in rangesSqueeze AND Breakout; Confirmation 2; Step 4 session filter
Entering during contractionBand Width Direction Up AND Breakout Up
Counter-trend breakoutsAdd trend filter (see MA Crossover EA)
Spread eats profitStep 4 spread filter; test on ECN/low-spread symbol
Over-tradingStep 5 max trades; one position per symbol
Late entriesShorter Breakout Period (3) or Price Cross Upper instead of full Breakout

Next Steps

Try it: Strategy Builder demo — build the BB 20/2 breakout EA in one session, export, and backtest.

References: MQL5 iBands, MetaTrader 5 Strategy Tester.

Build your no-code trading strategy now — free

Create your account and start building a complete no-code strategy right now. Add indicators, filters, and risk rules, then export MQL5 in minutes.

Frequently Asked Questions

Yes. In AlfaTactix Strategy Builder, add Bollinger Bands on Step 3 — Signals, set Breakout with Direction = Up, Threshold = 0, Period = 5, Confirmation = 1 for buy and Direction = Down for sell, configure risk on Step 5, save, then export MQL5 from Code Generator. Compile once in MetaEditor and backtest in the Strategy Tester.

The classic starter is Length 20, Std Dev 2, Band Type SMA, Source Close, on H1 forex majors like EURUSD. In Strategy Builder, set these in the Bollinger Bands Parameters panel and use Breakout Direction Up/Down with Period 5 and Confirmation 1. For indicator theory, see the Bollinger Bands Academy guide.

Breakout fires when price was inside the bands and then closes outside the upper (Up) or lower (Down) band — best for momentum continuation after a squeeze or range. Price Cross detects when price crosses a specific band line (Upper, Middle, or Lower). For a classic breakout EA, use Breakout Direction Up on Buy. As an alternative entry, combine Breakout Up OR Price Cross Band Upper on the Buy tab.

Yes. Exported code calls the standard MT5 iBands handle with your Length, Std Dev, Source, and band settings. You do not write that logic by hand — see Build EA Without Coding and Production-Ready MQL5 Without MetaEditor.

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 session/spread filters, require Squeeze before Breakout using AND, or combine with a trend filter from the MA Crossover EA guide. Read Strategy Tester vs Live before going live.

Use Confirmation 2 on Breakout, add Band Width Direction Up (expanding volatility) with AND, or filter entries with Squeeze (Threshold 0.02) before the breakout. Set realistic Stop Loss on Step 5 per EA Risk Management. For mean-reversion instead of breakout, see the RSI Overbought/Oversold EA guide.

Build your no-code strategy now — free

Create Free Account