Trend Pullback EA
This is a published trend-following idea, offered here for study and as a template to adapt, not a guaranteed edge. A long moving average (InpTrendMaPeriod) defines the trend direction, and price must clear it by InpMinTrendDistancePips before the market counts as trending at all - a market only marginally above or below a slow moving average is sideways chop wearing a trend indicator, and this filter keeps the EA out of it. The entry trigger is a short moving average (InpPullbackMaPeriod) used as the pullback line. In an uptrend, the signal bar must dip to touch or cross below that line with its low, then still close back above it, and close bullish (close above open) on the same bar. A plain moving-average crossover would fire a bar later, after the pullback has already turned - this fires on the bar the reversal actually happens, at the cost of being a stricter, less frequent signal. The downtrend case is the exact mirror. The stop-loss sits beyond the lowest low (uptrend) or highest high (downtrend) of the last InpSwingLookbackBars closed bars, plus InpStopLossBufferPips - the recent swing structure the pullback happened against, not an arbitrary fixed distance. Notes and limitations - One position at a time, tracked by InpMagicNumber. A new signal is ignored while a position from this EA is already open. - Requires at least InpTrendMaPeriod plus InpSwingLookbackBars bars of history before the first signal can be evaluated. - The touch-and-reject trigger is intentionally strict - it will sit idle through trends that never produce a clean single-bar pullback, rather than force a marginal entry. - Requires AutoTrading enabled (IsTradeAllowed() on MQL4, the three-way check described above on MQL5); if trading is disabled the EA logs it and skips the entry. - On an MQL5 netting account specifically: if a foreign-magic position already exists on the chart symbol, this EA refuses to open a new one rather than merge into it - see MQL4 VERSUS MQL5 DIFFERENCES above. - A published pattern, not a strategy with a documented statistical edge on any specific symbol - test on your own data before trusting it.
Expert advisor · MT5 · v1.0 · Free
About Trend Pullback EA
Trend Pullback EA is an expert advisor (trading robot) for MetaTrader 5 based on Moving Average. It can size trades from your balance and risk percent. It has 15 settings, such as Trend ma period, Trend ma method and Pullback ma period. MQL source code included.
Files in the download: TrendPullbackEa.ex5, TrendPullbackEa.mq5, TrendPullbackEa.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 |
|---|---|---|
| Trend ma period | 200 | Period of the long trend-defining moving average |
| Trend ma method | MODE_EMA | Method of the trend moving average |
| Pullback ma period | 20 | Period of the short pullback moving average |
| Pullback ma method | MODE_EMA | Method of the pullback moving average |
| Min trend distance pips | 30 | Minimum pips price must clear the trend MA by to count as trending |
| Swing lookback bars | 5 | Bars scanned for the stop-loss swing extreme |
| Stop loss buffer pips | 5 | Extra pips beyond the swing extreme for the stop-loss |
| Reward multiple | 1.5 | Take-profit as a multiple of the stop distance (0 = no take-profit) |
| Use risk sizing | false | Size by percent risk 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 fallback |
| Magic number | 20260820 | 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: Moving Average · Trend · Risk & Lot Size · MT5 Expert Advisor · MQL5 Source Code