Gold Scalper MA Trend Averaging EA
- Uzmanlar
- Sürüm: 2.5
MA_Trend_Averaging_v2 — Automated Expert Advisor for MetaTrader 5
MA_Trend_Averaging_v2 is an automated Expert Advisor (EA) designed specifically for the MetaTrader 5 platform . This EA combines a trend-following strategy based on Moving Average indicators with a structured Averaging (Grid/Layering) risk management system.
The EA works by opening positions in the direction of the major market trend, backed by a safety system that opens incremental positions if the price moves against the initial entry before eventually reversing into profit.
🚀 Key Features & Logic
1. Entry Strategy & Multi-Layer Trend Filters
The EA uses strict signal filtering to avoid sideways or false market conditions:
-
Major Trend Filter (MA 200 HTF): Ensures BUY positions are only opened when the price is above MA 200 and SELL positions when below MA 200 on a Higher Timeframe.
-
MA Slope Filter: Measures the angle inclination of the MA 200 (based on the InpMinMASlopePips parameter) to ensure strong active trend momentum.
-
ADX Filter: Confirms sufficient market volatility and trend strength via the ADX indicator (minimum level of 20.0).
-
Crossover Signal (MA 5 & MA 20): Executes Golden Cross (Buy) and Death Cross (Sell) entries on the current timeframe.
2. Grid & Averaging Management
-
Dynamic/Fixed Grid Distance ( GetGridDistance ): Additional positions are opened when prices move against the trade, with options for fixed pips or dynamic scaling based on the ATR (Average True Range) indicator.
-
Martingale Option ( InpUseMartingale ): Provides a choice to scale lot sizes proportionally on subsequent layers or use a Fixed Lot.
-
Maximum Trades Limit ( InpMaxTrades ): Controls the total number of layered positions to protect account margin health.
3. Exit & Protection Logic
-
Collective Basket TP/SL Target: Calculates the Average Price of all open positions and collectively updates the Take Profit (TP) or Stop Loss (SL) targets.
-
Opposite Crossover Exit: Automatically closes all positions if an opposite Moving Average crossover occurs against the current trend.
-
Break-Even Point (BEP): Secures positions to breakeven ( InpBEPTrigger & InpBEPOffset ) once the basket reaches a specific profit target.
-
Trailing Stop: Dynamically locks in profits as the market moves further in favor of the trade.
4. Additional Features & Filters
-
Trading Hour Filter: Restricts EA operation to specific high-volume trading sessions (e.g., London/New York sessions).
-
Max Spread Filter: Prevents the EA from opening trades during broker spread expansions.
-
Compounding Lot ( InpUseCompounding ): Automatically scales initial lot sizes proportionally as the account balance grows.
📋 Main Input Parameters
| Parameter | Description |
| InpMinMASlopePips | Minimum threshold for MA 200 slope angle as a trend filter. |
| GetGridDistance | Pip distance between averaging (grid/layer) positions. |
| InpUseMartingale | Enable/Disable lot multiplier for averaging layers. |
| InpMaxTrades | Maximum allowed total layer positions. |
| InpBEPTrigger | Profit target in pips to activate the Break-Even Point feature. |
| InpBEPOffset | Safety pip offset above/below the average price when BEP is active. |
| InpUseCompounding | Enable automated lot sizing based on balance growth. |
⚠️ Important Note
This EA is classified as a Semi-Grid Trend-Following system and features highly selective trend filtering . However, because it utilizes an averaging system (especially with Martingale enabled), proper capital allocation, adequate margin resilience, and wise grid distance settings are crucial to avoid Margin Call risks during prolonged, one-sided market trends .
It is highly recommended to run a Strategy Tester (Backtest) in MetaTrader 5 before deploying it on a live account.
Setting :
XAU
Timeframe 15m
----
; this file contains input parameters for testing/optimizing Gold Scalper MA Trend Averaging EA expert advisor
; to use it in the strategy tester, click Load in the context menu of the Inputs tab
;
; --- Trading Settings ---
InpInitialLot=0.25
InpMagicNumber=123456
InpTakeProfit=0
InpStopLoss=0
InpMaxTrades=5
InpMaxTotalVolume=10
; --- Filter Settings ---
InpMaxSpread=150
InpUseTimeFilter=false
InpStartHour=0
InpEndHour=23
; --- Enhanced Trend & Volatility Filters ---
InpUseHTF=true
InpHTFPeriod=16385
InpUseMASlope=true
InpMinMASlopePips=1.5
InpUseADX=true
InpADXPeriod=14
InpMinADXLevel=20.0
; --- Compounding Settings ---
InpUseCompounding=false
InpRefBalance=1000.0
; --- Averaging Settings ---
InpUseMartingale=false
InpLotMultiplier=1.5
InpUseATRGrid=false
InpFixedGridPips=300
InpATRPeriod=14
InpATRMultiplier=1.5
; --- BEP & Trailing Settings ---
InpUseBEP=false
InpBEPTrigger=20
InpBEPOffset=2
InpUseTrailing=false
InpTrailingStart=40
InpTrailingStop=20
; --- Indicator Settings ---
InpMA200Period=200
InpMA20Period=20
InpMA5Period=5
InpMAMethod=1
