Expansion Bar Follow System
The widest bar in a recent window is the market's most decisive move during that stretch - the bar where the most genuine directional information was expressed in a single session. This EA identifies that bar directly (by true range, not just high-low, so gap bars are counted correctly) and follows its direction: a bullish widest bar (close above open) triggers a long, a bearish one triggers a short. Two filters keep this from firing on noise. First, the widest bar must be MUCH wider than the window's average true range, not merely the largest of several similarly-sized bars - a bar that barely edges out its neighbours carries little extra signal. Second, only the most recently closed bar is eligible to be "the" widest bar; if the true widest bar in the window happened several bars ago, that information is stale by the time it would be noticed and the EA does not act on it. The stop sits just beyond the expansion bar's own opposite extreme - its low for a long, its high for a short - on the reasoning that a genuine follow-through should not revisit the origin bar's far side. The target is a fixed multiple of that stop distance. Notes and limitations - This project reimplements the catalogue's standard helper functions (retryable-error classification, pip/lot normalisation, position lookup by magic number) locally rather than including another project's file, per house style - each submission is self-contained. - A doji-close expansion bar (close exactly equal to open) gives no directional bias and is skipped even if it is the widest bar in the window. - True range uses the standard high/low plus prior-close gap formula; on symbols with frequent weekend or session gaps this can inflate the measured range on the first bar after a gap. - Pure momentum-follow logic with no confirmation beyond the single trigger bar; a wide reversal bar at the end of a trend will be followed in the wrong direction just as readily as a genuine breakaway bar. - Signals are evaluated once per closed bar, not on every tick. - One position at a time, tracked by InpMagicNumber. - Requires AutoTrading enabled (IsTradeAllowed()); if trading is disabled the EA logs it and skips the entry.
Expert advisor · MT4 · v1.0 · Free
About Expansion Bar Follow System
Expansion Bar Follow System is an expert advisor (trading robot) for MetaTrader 4. It can size trades from your balance and risk percent. It has 11 settings, such as Lookback bars, Min range ratio and Stop buffer pips. MQL source code included.
Files in the download: ExpansionBarFollow.ex4, ExpansionBarFollow.mq4, ExpansionBarFollow.txt.
Trading robots can lose money. Check every setting and test on a demo account before using real funds.
Settings
| Setting | Default | What it does |
|---|---|---|
| Lookback bars | 10 | Bars scanned (excluding the current forming bar) for the widest range |
| Min range ratio | 1.5 | Widest bar's range must be at least this multiple of the window average |
| Stop buffer pips | 5 | Buffer beyond the expansion bar's opposite extreme for the stop |
| Reward multiple | 1.5 | Take profit, as a multiple of the stop distance |
| Use risk sizing | false | Size by percent risk instead of a fixed lot |
| Risk percent | 1.0 | Percent of equity risked per trade, when risk sizing is on |
| Fixed lots | 0.10 | Lot size when risk sizing is off, or as a fallback |
| Magic number | 20260606 | Magic number for orders opened by this EA |
| Slippage pips | 3 | Slippage tolerance, in pips |
| Max retries | 5 | Attempts per trade action before giving up |
| Retry wait ms | 500 | Pause between attempts, milliseconds |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Experts.
- Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
- Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the expert advisor from the Navigator onto a chart, check the settings, allow Algo/Auto Trading and press OK.
- Test it first on a demo account or in the Strategy Tester.
Tags: Trading Sessions · Risk & Lot Size · MT4 Expert Advisor · MQL4 Source Code