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:
| Signal | Rule |
|---|---|
| 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
| Setting | Starter value | Notes |
|---|---|---|
| Length | 20 | John Bollinger default; 14 = faster, 50 = slower |
| Std Dev | 2 | Range 0.1–5; 2.5 = wider bands, fewer touches |
| Band Type | SMA | EMA middle band reacts faster |
| Source | Close | High/Low for wick-sensitive systems |
| Band Width | Off | Enable On to plot bandwidth sub-chart |
| Timeframe | H1 (forex majors) | M15 = more signals; H4 = cleaner breakouts |
| Symbol | EURUSD, GBPUSD | Liquid pairs; spread matters on tight stops |
| Breakout Period | 5 | Bars ago price must have been inside bands |
| Breakout Confirmation | 1 bar | 2 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:
| Parameter | Type | Range / options | Default | What it does |
|---|---|---|---|---|
| Length | Number | 2 – 200 | 20 | Lookback periods for the middle band calculation |
| Std Dev | Number | 0.1 – 5 (step 0.1) | 2 | Multiplier for upper/lower band distance from middle |
| Source | Select | Close, Open, High, Low | Close | Price series used in the calculation |
| Band Type | Select | SMA, EMA | SMA | Moving average type for the middle band |
| Band Width | Select | On, Off | Off | Show bandwidth indicator line on chart |
| Offset | Number | -50 – 50 | 0 | Shifts bands forward/backward in bars (advanced; leave 0 for standard EAs) |
| Timeframe | Select | 1m, 5m, 15m, 30m, 1h, 4h, 1d, 1w, 1M | 1d | Indicator 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).
| Field | Options |
|---|---|
| Operator | >, <, >=, <=, ==, != |
| Value | Number (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.
| Field | Options |
|---|---|
| Band | Upper Band · Middle Band · Lower Band |
| Smoothing | None, SMA, EMA, WMA |
| Smoothing Length | 1 – 100 (shown when Smoothing ≠ None; default 5) |
| Source | Close, 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:
| Tab | Band | Source |
|---|---|---|
| Buy | Upper Band | Close |
| Sell | Lower Band | Close |
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.
| Field | Range / options |
|---|---|
| Period | 1 – 100 (default 20) |
| Threshold | Number (step 0.01; default 0.02 = 2% bandwidth) |
| Smoothing | None, SMA, EMA, WMA |
| Smoothing Length | 1 – 100 (when Smoothing ≠ None; default 5) |
| Source | Close, 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.
| Field | Range / options |
|---|---|
| Direction | Up (breaks above Upper) · Down (breaks below Lower) |
| Threshold | Number (step 0.01; 0 = band edge only) |
| Period | 1 – 50 bars (default 14; use 5 for responsive breakouts) |
| Confirmation | 1 – 10 bars (default 1) |
Classic breakout recipe:
| Tab | Direction | Threshold | Period | Confirmation |
|---|---|---|---|---|
| Buy | Up | 0 | 5 | 1 |
| Sell | Down | 0 | 5 | 1 |
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.
| Field | Options |
|---|---|
| Pattern Type | Double Top, Double Bottom, Head & Shoulders, Inverse H&S, Triangle, Wedge |
| Min Height | Number (step 0.01; price units) |
| Min Width | Number (bars between pattern points) |
| Volume Confirmation | None · 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.
| Field | Range / options |
|---|---|
| Direction | Up · Down |
| Period | 1 – 50 (default 14) |
| Min Slope | Number (0 = any slope; step 0.01) |
| Smoothing | None, SMA, EMA, WMA |
| Smoothing Length | 1 – 100 (when Smoothing ≠ None; default 5) |
| Source | Close, 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.
| Field | Range / options |
|---|---|
| Direction | Up (expanding) · Down (contracting / squeeze) |
| Threshold | Number (step 0.01; e.g. 0.03 = 3% bandwidth) |
| Period | 1 – 50 (default 14) |
| Confirmation | 1 – 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.
| Field | Range / options |
|---|---|
| Operator | >, <, >=, <=, ==, != |
| Value | Number (0–1 typical; 0.2 near lower, 0.8 near upper) |
| Period | 1 – 50 (default 14) |
| Confirmation | 1 – 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)
- Open tab Buy.
- Select timeframe H1.
- Add indicator → Bollinger Bands (Volatility group).
- Parameters:
- Length: 20
- Std Dev: 2
- Source: Close
- Band Type: SMA
- Band Width: Off
- Offset: 0
- Timeframe: 1h (match H1 trading TF)
- Add condition → Breakout.
- 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).
- Open tab Sell.
- 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:
| Setting | Suggestion |
|---|---|
| Lot / risk % | 0.01 lot demo or 1% risk |
| Stop Loss | Fixed pips or ATR-based (breakouts need room beyond the band) |
| Take Profit | Optional; many BB EAs trail or exit on opposite breakout |
| One trade at a time | Avoid 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
- Open Code Generator → select your saved strategy → MQL5 → download
.mq5. - Copy to
MQL5/Experts, compile (F7) in MetaEditor. - Strategy Tester: Every tick, realistic spread, 6–12 months data on H1 EURUSD.
- 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
| Problem | Builder lever |
|---|---|
| False breakouts in ranges | Squeeze AND Breakout; Confirmation 2; Step 4 session filter |
| Entering during contraction | Band Width Direction Up AND Breakout Up |
| Counter-trend breakouts | Add trend filter (see MA Crossover EA) |
| Spread eats profit | Step 4 spread filter; test on ECN/low-spread symbol |
| Over-trading | Step 5 max trades; one position per symbol |
| Late entries | Shorter Breakout Period (3) or Price Cross Upper instead of full Breakout |
Next Steps
- Bollinger Bands Academy guide — squeeze, %B, band walk, and chart examples
- Build EA Without Coding — full six-step builder tour
- RSI Overbought/Oversold EA — No Code — mean-reversion counterpart
- Moving Average Crossover EA — No Code — trend filter partner
- Advanced EA MTF & Filters — session, spread, multi-timeframe
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.