Broken Level Retest System
Buying or selling the moment a level breaks is the naive version of this idea and gives up the edge the retest is supposed to provide: a level worth trading is one price comes back to test, and how it behaves on that second visit is more informative than the initial break itself. This EA tracks one multi-day swing level at a time - the highest high or lowest low of the last InpLevelLookbackDays daily bars, whichever the market is currently closer to - through a small state machine: watching, broken, then resolved. Once a closed bar's close breaks the level, the EA waits up to InpMaxBarsToRetest bars for price to come back within InpRetestTolerancePoints of it. Two outcomes are possible on that retest bar. If it closes on the SAME side as the break (holding), that is a successful retest and the trade continues in the break's own direction, stopped just beyond the level. If it closes back on the OTHER side (failing), the break has proven false - rather than throw that information away, it becomes the entry for the OPPOSITE direction, on the reasoning that a level which held anyway after an apparent break is now confirmed support or resistance. A retest that never arrives within the bar limit sees the level abandoned and a fresh one picked up from scratch. Notes and limitations - Only one level is watched at a time; while a break is pending a retest, no new level is picked up even if a more obvious one forms elsewhere on the chart. - The level is re-derived from scratch every time the state machine returns to watching, so it can shift from one swing extreme to the other as older daily bars age out of InpLevelLookbackDays. - The retest check looks at the closed bar's close, high AND low against the tolerance, so a bar whose wick alone touched the level counts as a retest attempt even if the close did not. - Only one position at a time; the EA does not watch for a second level while a trade from the first is open. - Lot sizing uses MODE_TICKVALUE/MODE_TICKSIZE, not a hardcoded contract size.
Expert advisor · MT5 · v1.0 · Free
About Broken Level Retest System
Broken Level Retest System is an expert advisor (trading robot) for MetaTrader 5 based on ATR. It can size trades from your balance and risk percent. It has 13 settings, such as Level lookback days, Retest tolerance points and Max bars to retest. MQL source code included.
Files in the download: BrokenLevelRetestSystem.ex5, BrokenLevelRetestSystem.mq5, BrokenLevelRetestSystem.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 |
|---|---|---|
| Level lookback days | 20 | Daily bars back used to find the swing high/low level |
| Retest tolerance points | 20 | How close price must come back to the level to count as a retest, in points |
| Max bars to retest | 30 | Bars allowed after the break for the retest to arrive before it is abandoned |
| Atr period | 14 | ATR period used for the stop and target |
| Stop atr multiple | 1.2 | Initial stop distance beyond the level, ATR multiples |
| Target atr multiple | 2.5 | Take profit distance from entry, ATR multiples |
| Use risk sizing | false | Size by percent risk to the initial stop instead of a fixed lot |
| Risk percent | 1.0 | Percent of equity risked per trade, used only when risk sizing is on |
| Fixed lots | 0.10 | Lot size when risk sizing is off, or as a fallback |
| Magic number | 20260368 | 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 5 open File → Open Data Folder, then go to MQL5 → Experts.
- Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
- Open the .mq5 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: Buy/Sell Arrows · Risk & Lot Size · ATR · MT5 Expert Advisor · MQL5 Source Code