Statistical Window Breakout System
Time-of-day filters in published breakout EAs are usually a guessed window (e.g. "only trade 8am-11am") applied without ever checking whether breakouts starting in that window actually worked on the instrument in question. This EA measures it instead. On a schedule (InpRescanIntervalHours) it walks InpHistoryBars of closed history, finds every bar whose close broke the prior InpRangeBars high/low, and tags each one with the server-time hour it occurred in. Each historical breakout is then scored for follow-through: did price move at least InpFollowThroughAtr times ATR further in the breakout's direction over the following InpFollowThroughBars bars? The result is two tallies per hour of day - how many breakouts started in that hour, and how many were still favourable afterward. An hour only stays open for LIVE trading if it clears two bars together: at least InpMinSampleSize historical breakouts (so a single lucky breakout in a thin hour cannot qualify it) AND a follow-through rate at or above InpMinHitRate. Both conditions are required at once - a high hit rate on three samples is not trusted, and a large sample with a mediocre hit rate is not traded either. The qualifying hour set is rebuilt from scratch on the configured schedule, so it adapts as more history accumulates rather than being fixed once at first attach. Notes and limitations - The hourly statistics are server-time hours, not broker-local or user-local time - check your broker's server time offset before interpreting which real-world session an hour corresponds to. - Statistics are rebuilt from scratch on each rescan, which is simple and correct but means the qualifying-hour set can change from one rescan to the next as fresh history rolls in and old history rolls out of the InpHistoryBars window. - Historical follow-through is measured on the SAME symbol/timeframe the EA is attached to; it says nothing about whether an hour that works on this timeframe also works on a different one. - A large InpHistoryBars value on a low timeframe can take a noticeable moment to scan - this only happens on OnInit and on each scheduled rescan, never on every tick. - Lot sizing uses MODE_TICKVALUE/MODE_TICKSIZE, not a hardcoded contract size. - Only one position at a time.
Expert advisor · MT4 · v1.0 · Free
About Statistical Window Breakout System
Statistical Window Breakout System is an expert advisor (trading robot) for MetaTrader 4. It can size trades from your balance and risk percent and trades breakouts. It has 18 settings, such as Range bars, History bars and Atr period. MQL source code included.
Files in the download: StatWindowBreakout.ex4, StatWindowBreakout.mq4, StatWindowBreakout.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 |
|---|---|---|
| Range bars | 20 | Bars defining the breakout range |
| History bars | 2000 | Closed bars scanned when building the hourly statistics |
| Atr period | 14 | ATR period used for the follow-through test and the live stop |
| Follow through bars | 5 | Bars ahead checked for follow-through when scoring each historical breakout |
| Follow through atr | 0.5 | Minimum further move, in ATR multiples, to count a breakout as favourable |
| Min sample size | 8 | Minimum historical breakouts required in an hour before it can be traded |
| Min hit rate | 0.55 | Minimum historical follow-through rate required for an hour to be traded |
| Rescan interval hours | 24 | How often the hourly statistics are rebuilt from history |
| Break buffer pips | 2.0 | Close must clear the range by this many extra pips |
| 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 |
| Stop atr multiple | 1.0 | Stop distance as a multiple of ATR |
| Reward risk ratio | 1.5 | Take-profit distance as a multiple of the stop distance |
| Magic number | 43771 | 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: Breakout · Trading Sessions · Risk & Lot Size · MT4 Expert Advisor · MQL4 Source Code