Skip to content
← Back to the research library
MQL5 SOURCE COLLECTION / Trend Following

Moving Average: Trend Pullback

Tracks moving-average slope changes, then looks for a percentage pullback from the subsequent high or low.

MT5 / MQL5Original sourceUnverified source

H1 SMA / M1 checks · Published 28 October 2026

Source inspectionLimited static review
MetaEditor compilationNot performed
Backtest / live recordNot supplied

How the source is structured

  1. Detect changes in the slope of the H1 moving average.
  2. During an upward slope, look for a 1% pullback from a qualifying high; during a downward slope, look for a 1% rebound from a qualifying low.
  3. Submit a fixed-volume trade with percentage-based stop and target levels.

Default inputs

As supplied; these are not optimized or recommended settings.
Moving averageH1 / 200-period SMA / close
Trigger distance1%
Volume0.1 lot
Stop / target1% / 1%
BEFORE YOU TEST

Source-review notes

These observations come from reading this uploaded version. They are not compiler output or a complete code audit. The download retains the source as supplied.

SOURCE LINES 35–37, 48–50, 65–67

Buffer copies and bar-search results need validation before their values are used.

SOURCE LINES 52–57, 69–74

The trigger is marked as used without checking the trade result. The sell request passes ask as its price.

SOURCE LINES 13–16, 28–80

There is no explicit open-position cap or magic-number setup. State is not restored after a restart.

Dependencies

Built-in moving average; MetaTrader 5 standard Trade library.

Source & attribution

The original filename includes 'Rene'; the source contains no author or license declaration.

Included in the Edge Quant source collection with existing notices preserved. Free download does not imply a new license grant.

Original filename: Moving Average Trading Strategy Rene.mq5
Encoding: UTF-8

Inspect the original source

The browser preview is decoded for reading; the download keeps the original file bytes.

Direct .mq5 file ↓
Expand full MQL5 source · 80 lines
#include <trade/trade.mqh>input double TriggerPercent = 1;input double Lots = 0.1;input double TpPercent = 1;input double SlPercent = 1;input ENUM_TIMEFRAMES MaTimeframe = PERIOD_H1;input int MaPeriods = 200;input ENUM_MA_METHOD MaMethod = MODE_SMA;input ENUM_APPLIED_PRICE MaAppPrice = PRICE_CLOSE;CTrade trade;int handleMa;datetime maDirChange;double lastTrigger;int OnInit(){   handleMa = iMA(_Symbol,MaTimeframe,MaPeriods,0,MaMethod,MaAppPrice);   return(INIT_SUCCEEDED);}void OnDeinit(const int reason){}void OnTick(){      datetime time0 = iTime(_Symbol,PERIOD_M1,0);   static datetime timestamp = time0;   if(timestamp != time0){      timestamp = time0;               double ma[];      CopyBuffer(handleMa,MAIN_LINE,1,3,ma);      ArraySetAsSeries(ma,true);            double ask = SymbolInfoDouble(_Symbol,SYMBOL_ASK);      double bid = SymbolInfoDouble(_Symbol,SYMBOL_BID);            if(ma[0] > ma[1]){         if(ma[1] < ma[2]){            maDirChange = time0;            lastTrigger = 0;         }                  int indexChange = iBarShift(_Symbol,MaTimeframe,maDirChange);         int highest = iHighest(_Symbol,MaTimeframe,MODE_HIGH,indexChange+1);         double high = iHigh(_Symbol,MaTimeframe,highest);                  if(maDirChange > 0 && highest > 0 && high > lastTrigger && bid < high - high * TriggerPercent / 100){            double tp = ask + ask * TpPercent / 100;            double sl = ask - ask * SlPercent / 100;                        trade.Buy(Lots,_Symbol,ask,sl,tp);            lastTrigger = high;         }      }else if(ma[0] < ma[1]){         if(ma[1] > ma[2]){            maDirChange = time0;            lastTrigger = INT_MAX;           }         int indexChange = iBarShift(_Symbol,MaTimeframe,maDirChange);         int lowest = iLowest(_Symbol,MaTimeframe,MODE_LOW,indexChange+1);         double low = iLow(_Symbol,MaTimeframe,lowest);                  if(maDirChange > 0 && lowest > 0 && low < lastTrigger && bid > low + low * TriggerPercent / 100){            double tp = bid - bid * TpPercent / 100;            double sl = bid + bid * SlPercent / 100;                        trade.Sell(Lots,_Symbol,ask,sl,tp);            lastTrigger = low;         }               }            Comment("\nDirection Change: ",maDirChange);   }  }

SHA-256: b26408fbf69b8ba8f40236fa9a673f11ea7072ceaff6b9a5e57249e8159ae7ca

Educational source material, not investment advice. No profitability, execution quality or live-readiness claim is made for this upload.