Buffer copies and bar-search results need validation before their values are used.
Moving Average: Trend Pullback
Tracks moving-average slope changes, then looks for a percentage pullback from the subsequent high or low.
How the source is structured
- Detect changes in the slope of the H1 moving average.
- 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.
- Submit a fixed-volume trade with percentage-based stop and target levels.
Default inputs
| Moving average | H1 / 200-period SMA / close |
|---|---|
| Trigger distance | 1% |
| Volume | 0.1 lot |
| Stop / target | 1% / 1% |
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.
The trigger is marked as used without checking the trade result. The sell request passes ask as its price.
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.
Inspect the original source
The browser preview is decoded for reading; the download keeps the original file bytes.
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); } }Educational source material, not investment advice. No profitability, execution quality or live-readiness claim is made for this upload.