Loading…

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

SettingDefaultWhat it does
Trend ma period200Period of the long trend-defining moving average
Trend ma methodMODE_EMAMethod of the trend moving average
Pullback ma period20Period of the short pullback moving average
Pullback ma methodMODE_EMAMethod of the pullback moving average
Min trend distance pips30Minimum pips price must clear the trend MA by to count as trending
Swing lookback bars5Bars scanned for the stop-loss swing extreme
Stop loss buffer pips5Extra pips beyond the swing extreme for the stop-loss
Reward multiple1.5Take-profit as a multiple of the stop distance (0 = no take-profit)
Use risk sizingfalseSize by percent risk 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 fallback
Magic number20260820Magic 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 5 open File → Open Data Folder, then go to MQL5 → Experts.
  3. Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
  4. Open the .mq5 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: Moving Average · Trend · Risk & Lot Size · MT5 Expert Advisor · MQL5 Source Code

Expert advisors (EA) for MT4 & MT5 · PolyMaria