Loading…

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

SettingDefaultWhat it does
Swing lookback5Bars required on each side to confirm a swing point
History bars500Bars of history scanned to rebuild the swing list each new bar
Min segments6Minimum historical trend segments required before the age filter is trusted
Young fraction0.6Live trend age must be <= this fraction of the median historical segment length
Min swing len pips20.0Swing legs shorter than this are excluded from the segment-length sample as noise
Stop buffer pips5.0Extra buffer beyond the pullback low/high for the stop
Target r multiple1.5Take profit as a multiple of the stop distance
Use risk sizingtrueSize by percent risk to the stop instead of a fixed lot
Risk percent1.0Percent of equity risked per trade, when risk sizing is on
Fixed lots0.10Lot size when risk sizing is off, or as a sizing fallback
Magic number33001Magic number for orders opened by this EA
Slippage pips3Slippage tolerance, in pips
Max retries5Attempts per trade action before giving up
Retry wait ms500Pause between attempts, milliseconds

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Experts.
  3. Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
  4. Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the expert advisor from the Navigator onto a chart, check the settings, allow Algo/Auto Trading and press OK.
  6. Test it first on a demo account or in the Strategy Tester.

Download the PDF guide

Tags: Trend · Risk & Lot Size · MT4 Expert Advisor · MQL4 Source Code

Expert advisors (EA) for MT4 & MT5 · PolyMaria