MT5 EA源码:XAUUSD Adaptive Mean-Reversion Grid EA XAUUSD 自适应均值回归网格|星钻会员尊享 - 资源合集论坛 - Meta Trade 4 - BBTrading

MT5 EA源码:XAUUSD Adaptive Mean-Reversion Grid EA XAUUSD 自适应均值回归网格|星钻会员尊享

此资源为星钻会员专享,每日更新,收录于《大白EA宝库:星钻会员专属合集》。

这个 EA 是针对 XAUUSD 的自适应均值回归网格 EA,价格回调时按 ATR 动态间距分批加仓摊平,属于网格加仓逻辑,高风险。本帖文件为 MT5 源码,打包成 zip 下载,解压后在 MetaEditor 里编译使用,参数与文件开头见下方源码预览。

源码预览(先看代码,再决定下不下)

本帖是源码 EA:xauusd_adaptive_meanreversion.mq5,全文共 1129 行。下面是它的全部可调参数与文件开头,完整源码在上方下载区,星钻会员可见。

可调参数(53 个)

  • ulong InpMagicNumber = 20250301;(Magic Number)
  • string InpTradeComment = "XAU_MeanRev";(Order Comment Prefix)
  • bool InpAllowNewEntries = true;(Allow Opening New Baskets)
  • ENUM_TIMEFRAMES InpEntryTF = PERIOD_M15;(Entry Timeframe (M15 Recommended))
  • ENUM_TIMEFRAMES InpTrendTF = PERIOD_H1;(Trend Filter Timeframe (H1 Recommended))
  • int InpEMA_Fast = 50;([H1] Fast EMA Period)
  • int InpEMA_Slow = 200;([H1] Slow EMA Period)
  • int InpMaxEMADiffPoints = 2000;([H1] Max Distance between EMA50 & EMA200 (Points))
  • int InpADX_Period = 14;([H1] ADX Period)
  • double InpMaxADXForEntry = 28.0;([H1] Max ADX for Entry (Above this = Strong Trend))
  • double InpTrendEscapeADX = 32.0;([H1] Trend Escape ADX (Trigger Emergency Freeze))
  • int InpRSI_Period = 14;([M15] RSI Period)
  • double InpBuyRSI_Level = 35.0;([M15] Buy Oversold RSI Level (RSI < Level))
  • double InpSellRSI_Level = 65.0;([M15] Sell Overbought RSI Level (RSI > Level))
  • int InpBB_Period = 20;([M15] Bollinger Bands Period)
  • double InpBB_Deviation = 2.0;([M15] Bollinger Bands Deviation)
  • int InpATR_Period = 14;([M15] ATR Period)
  • double InpGridATRMultiplier = 1.4;(Grid Step ATR Multiplier)
  • double InpMinGridStepUSD = 3.5;(Minimum Grid Step ($ USD price distance, e.g. $3.50))
  • double InpMaxGridStepUSD = 12.0;(Maximum Grid Step ($ USD price distance, e.g. $12.00))
  • int InpMaxGridLevels = 5;(Maximum Grid Levels per Basket (Strict Cap))
  • ENUM_LOT_STRATEGY InpLotStrategy = LOT_STRAT_FIXED;(Lot Strategy (Fixed / Mild Mult / Dynamic))
  • double InpInitialLot = 0.01;(Initial Lot Size)
  • double InpLotMultiplier = 1.15;(Mild Lot Multiplier (Keep <= 1.20))
  • double InpMaxSingleLot = 0.10;(Max Lot Size per Single Order)
  • double InpMaxExposureLots = 0.25;(Max Cumulative Lots in a Basket)
  • double InpRiskPerBasketPct = 3.0;(Max Equity Risk % per Basket (for Dynamic Sizing))
  • ENUM_TP_MODE InpTPMode = TP_MODE_HYBRID;(Take Profit Mode)
  • double InpBasketTPPercent = 0.50;(Basket TP (% of Balance, e.g. 0.5%))
  • double InpBasketTPUSD = 15.0;(Basket TP ($ USD Fixed, e.g. $15.00))
  • double InpBasketTP_ATR_Factor = 0.30;(TP Distance from Weighted Average (ATR_M15 * Factor))
  • bool InpUseBasketTrailing = true;(Enable Basket Trailing Stop)
  • double InpTrailStartUSD = 10.0;(Trail Start Target ($ USD))
  • double InpTrailStepUSD = 3.0;(Trail Step / Lock-in Distance ($ USD))
  • double InpEquityStopPercent = 8.0;(Equity Drawdown Hard Stop % (Close All & Pause))
  • bool InpUseEmergencyATR_SL = true;(Emergency SL based on ATR(H1) from First Entry)
  • double InpEmergencySL_ATR_Mult = 3.5;(Emergency SL ATR(H1) Multiplier (e.g. 3.5x H1 ATR))
  • bool InpUseTrendEscape = true;(Enable Trend Escape Safety Cut)
  • double InpTrendEscapeMaxLossUSD= 60.0;(Max Loss to Trigger Trend Escape Cut ($ USD))
  • double InpMarginLevelFreeze = 200.0;(Margin Guard: Stop New Grid if Margin Level % < threshold)
//+------------------------------------------------------------------+
//|                             XAUUSD_Adaptive_MeanReversion_EA.mq5 |
//|                                  Copyright 2026, BlamzKunG        |
//|                          https://www.b123.com/ |
//+------------------------------------------------------------------+
#property copyright   "Copyright 2026, BlamzKunG"
#property link        "https://www.b123.com/"
#property version     "1.10"
#property description "High-Performance Adaptive Mean-Reversion Grid EA for XAUUSD (Gold)"
#property description "Optimized: Single-Pass Basket Stats, Cached Indicators & Multi-TF Filters"
#property strict

//--- Standard Library Includes
#include <Trade\Trade.mqh>
#include <Trade\PositionInfo.mqh>
#include <Trade\AccountInfo.mqh>
#include <Trade\SymbolInfo.mqh>

//+------------------------------------------------------------------+
//| ENUMERATIONS                                                     |
//+------------------------------------------------------------------+
enum ENUM_TP_MODE
{
   TP_MODE_HYBRID         = 0, // Hybrid (Money Target OR ATR Distance)
   TP_MODE_PERCENT_BALANCE= 1, // % of Balance Target (e.g. 0.5%)
   TP_MODE_FIXED_USD      = 2, // Fixed USD Target ($)
   TP_MODE_ATR_DISTANCE   = 3  // Weighted Average Entry +/- (ATR * Factor)
};

enum ENUM_LOT_STRATEGY
{
   LOT_STRAT_FIXED        = 0, // Fixed Lot (e.g. 0.01 every level)
   LOT_STRAT_MILD_MULT    = 1, // Mild Multiplier (1.10x - 1.20x max)
   LOT_STRAT_RISK_DYNAMIC = 2  // Dynamic Lot (Calculated from Equity % Risk)
};

风险提示:这类 EA 带网格/马丁类加仓逻辑,顺风时看不出来,单边行情里仓位和浮亏会一起放大。上实盘前先在模拟盘跑够样本,把最大层数和总手数按自己能承受的回撤设死,不要用默认参数直接跑。

版本说明:资源随 MT4/MT5 版本迭代可能失效,如遇失效请在本帖留言反馈。

请登录后发表评论