Loading…

Bollinger Breakout EA

A bare Bollinger breakout - buy any close above the upper band, sell any close below the lower - fires constantly once the bands have already widened, mostly on noise rather than genuine expansion. The Bollinger Squeeze idea, documented for decades under that name, adds a precondition: the bands must have been unusually narrow relative to their own recent history right before the breakout candle. A squeeze means volatility had compressed, and volatility compression resolving into a directional close is a materially stronger signal than a breakout out of already-wide bands. The squeeze condition is deliberately checked on the bar BEFORE the breakout bar, not on the breakout bar itself - the bands widen the instant the breakout candle prints, so requiring the squeeze to still hold at that point would exclude the very breakouts the filter exists to select for. Once in a position, the stop is not a fixed pip distance. It starts at the basis line and trails with it every closed bar, moved only in the trade's favour, using OrderModify - a breakout that falls back through its own moving average has failed on its own terms, so that line is both a tighter and a more honest exit than an arbitrary fixed distance. If price closes back through the basis before the trail can protect it, the EA closes the position outright. Position sizing can run as a fixed lot or, with InpUseRiskSizing on, as a percentage of equity risked to the initial stop distance, using MODE_TICKVALUE and MODE_TICKSIZE rather than a hardcoded contract size so it prices correctly on gold, indices and JPY crosses as well as plain FX pairs. Notes and limitations - The squeeze filter reduces false breakouts; it does not eliminate them. A squeeze followed immediately by another false break is a known failure mode of every squeeze-breakout variant, not specific to this implementation. - The trailing stop only tightens; if the broker's minimum stop distance blocks a particular bar's trail, it is simply skipped and retried next bar rather than forced. - The squeeze average recomputes over InpSqueezeLookback bars on every qualifying breakout bar; on very low timeframes with a long lookback this adds a small, bounded amount of per-bar work. - Signals and the trail are evaluated once per closed bar, not on every tick. - One position at a time, tracked by InpMagicNumber. It will not manage or interfere with trades opened manually or by another EA. - Requires AutoTrading enabled (IsTradeAllowed() on MQL4, the three-way check described above on MQL5); if trading is disabled the EA logs it and skips the entry. - On an MQL5 netting account specifically: if a foreign-magic position already exists on the chart symbol, this EA refuses to open a new one rather than merge into it - see MQL4 VERSUS MQL5 DIFFERENCES above.

Expert advisor · MT5 · v1.0 · Free

About Bollinger Breakout EA

Bollinger Breakout EA is an expert advisor (trading robot) for MetaTrader 5 based on Bollinger Bands. It moves the stop loss behind price (trailing stop / break-even), can size trades from your balance and risk percent and has a news filter. It has 12 settings, such as Bands period, Bands deviation and Squeeze lookback. MQL source code included.

It also trades breakouts.

Files in the download: BollingerBreakoutEa.ex5, BollingerBreakoutEa.mq5, BollingerBreakoutEa.txt.

Trading robots can lose money. Check every setting and test on a demo account before using real funds.

Settings

SettingDefaultWhat it does
Bands period20Bollinger Bands period
Bands deviation2.0Bollinger Bands standard deviation multiplier
Squeeze lookback50Bars averaged to establish normal band width
Squeeze ratio0.80Pre-breakout width must be below (average width x this ratio)
Take profit band mult0.0Take profit, in band-width multiples from entry (0 = none, ride the trail)
Use risk sizingfalseSize by percent risk instead of a fixed lot
Risk percent1.0Percent of equity risked per trade, when risk sizing is on
Fixed lots0.10Lot size when risk sizing is off, or as a fallback
Magic number20260806Magic number for orders opened by this EA
Slippage pips3Slippage tolerance, in pips
Max retries5Attempts per trade action before giving up
Retry wait ms500Pause between attempts, milliseconds

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Experts.
  3. Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
  4. Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the expert advisor from the Navigator onto a chart, check the settings, allow Algo/Auto Trading and press OK.
  6. Test it first on a demo account or in the Strategy Tester.

Download the PDF guide

Tags: Breakout · Bollinger Bands · Buy/Sell Arrows · Trailing Stop & Break-even · Risk & Lot Size · News Trading · MT5 Expert Advisor · MQL5 Source Code

Expert advisors (EA) for MT4 & MT5 · PolyMaria