Trend Age Filtered Entry System
Trend-following entries taken deep into an already-mature trend carry worse risk/reward than the same entry taken early - the move has already used up more of its typical run. Most systems either ignore this entirely or use an arbitrary fixed bar count as an "age" cutoff. This system measures both halves of that idea directly from the instrument's own history. Trend age is counted in bars since the last confirmed swing point that broke the prior trend - a real, objectively confirmed pivot, not a guess. The "young" cutoff itself is also measured: the system walks the confirmed-swing history, records how many bars each historical same-direction run lasted before the structure flipped, and takes the MEDIAN of that distribution (scaled down by a configurable fraction) as the age ceiling a live trend must still be under to qualify. A trend already older than half this market's typical run is not "young" by this market's own history, whatever an arbitrary constant might have said. Entries themselves are a simple same-direction continuation breakout of the immediately preceding bar's extreme, confirmed by that bar's own close - the age filter decides WHETHER the system is willing to look for that signal at all, it is not the signal itself. Notes and limitations - The historical segment measurement is an approximation built from runs of consecutive same-direction confirmed swing legs, not a formal trend-detection algorithm - it is deliberately simple and said so here. - With too little history or an instrument with very few confirmed swings, InpMinSegments may never be reached, in which case the EA stays flat - check the chart Comment. - The young-trend statistic is recomputed from scratch every new bar over a bounded history window and can shift as the window rolls forward. - Only one position at a time. - Lot sizing uses MODE_TICKVALUE/MODE_TICKSIZE, not a hardcoded contract size.
Expert advisor · MT4 · v1.0 · Free
About Trend Age Filtered Entry System
Trend Age Filtered Entry System is an expert advisor (trading robot) for MetaTrader 4. It can size trades from your balance and risk percent. It has 14 settings, such as Swing lookback, History bars and Min segments. MQL source code included.
Files in the download: TrendAgeFilteredSystem.ex4, TrendAgeFilteredSystem.mq4, TrendAgeFilteredSystem.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 |
| Min segments | 6 | Minimum historical trend segments required before the age filter is trusted |
| Young fraction | 0.6 | Live trend age must be <= this fraction of the median historical segment length |
| Min swing len pips | 20.0 | Swing legs shorter than this are excluded from the segment-length sample as noise |
| Stop buffer pips | 5.0 | Extra buffer beyond the pullback low/high 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 | 33001 | 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: Trend · Risk & Lot Size · MT4 Expert Advisor · MQL4 Source Code