Statistical Pullback Depth System
Most "fib pullback" EAs enter at 38.2%, 50% or 61.8% because those numbers are famous, not because the instrument in front of them has ever actually stalled there. This system replaces the assumption with a measurement: it rebuilds a confirmed-swing list from recent price history, walks every completed pullback leg it finds, and records what percentage of the impulse leg before it each pullback gave back. It then builds a simple histogram of those percentages and takes the MODE - the bin the market's pullbacks have actually clustered in - as the depth a live pullback is traded at. A confirmed swing point requires a set number of bars failing to make a new extreme on either side (the same technique used elsewhere in this catalogue), so the swing list itself is objective, not hand-drawn. Impulse legs shorter than a configurable pip floor are excluded from the sample so a run of tiny noise swings cannot dilute the measured depth. Trading only begins once enough completed pullbacks have been collected to trust the statistic; before that, the EA sits flat and reports its sample count on the chart. Once the live pullback's current retracement percentage enters a tolerance band around the measured depth, and the pullback bar's own close confirms resumption in the trend direction, the entry fires. The stop sits beyond the pullback's own extreme; the target is a fixed reward multiple of that stop distance - the measured statistic tells the system WHERE to enter, not an equally rigorous target, and this description does not pretend otherwise. Notes and limitations - The empirical depth is recomputed from scratch every new bar over a bounded history window - it adapts as the market's behaviour changes, but also means the measured depth can drift meaningfully between one attach and the next on the same symbol. - With InpHistoryBars too small or an illiquid symbol, the sample may never reach InpMinSampleSize, in which case the EA simply never trades - check the chart Comment if no trades appear. - The take-profit is a plain reward multiple of the stop distance, not a second empirically-measured statistic - stated plainly so it is not mistaken for more rigour than it has. - Only one position at a time; a fresh pullback while already positioned is not treated as a new signal. - Lot sizing uses MODE_TICKVALUE/MODE_TICKSIZE, not a hardcoded contract size, so it is correct on gold, indices and JPY crosses as well as plain FX pairs. - Like any pullback-continuation system, a genuine trend reversal disguised as a deep pullback will be traded as a continuation and stopped out - this is inherent to the method.
Expert advisor · MT4 · v1.0 · Free
About Statistical Pullback Depth System
Statistical Pullback Depth System is an expert advisor (trading robot) for MetaTrader 4. It can size trades from your balance and risk percent. It has 16 settings, such as Swing lookback, History bars and Sample size. MQL source code included.
Files in the download: StatisticalPullbackSystem.ex4, StatisticalPullbackSystem.mq4, StatisticalPullbackSystem.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 |
|---|---|---|
| Swing lookback | 5 | Bars required on each side to confirm a swing point |
| History bars | 500 | Bars of history scanned to rebuild the swing list each new bar |
| Sample size | 20 | Most recent completed pullback legs used to build the empirical distribution |
| Min sample size | 8 | Minimum completed samples required before the system will trade |
| Bin width pct | 5.0 | Histogram bin width, percent, used to find the empirical mode |
| Tolerance band pct | 4.0 | +/- band around the measured depth that counts as "at the level" |
| Min impulse len pips | 20.0 | Impulse legs shorter than this are excluded from the sample as noise |
| Stop buffer pips | 5.0 | Extra buffer beyond the pullback's own extreme for the stop |
| Target r multiple | 1.5 | Take profit as a multiple of the stop distance |
| Use risk sizing | true | Size by percent risk to the stop 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 sizing fallback |
| Magic number | 32601 | 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: Fibonacci · Risk & Lot Size · MT4 Expert Advisor · MQL4 Source Code