Summary: 黄金雷霆EA是一款专为XAUUSD设计的高暴利MQL4智能交易系统。使用波动率突破入场配合受控网格回血系统,动态手数进阶,适合M15周期。




黄金雷霆EA专门为黄金(XAUUSD)设计,旨在捕捉高暴利机会,同时维持适合黄金剧烈波动的风险控制。EA识别波动率压缩形态,并在突破时顺势入场。经过精心管理的网格回血系统(最多3层)帮助挽回回撤,同时避免无限风险。基于权益百分比的动态手数确保复利增长。EA包含最大回撤限制器和时间过滤器,避开低流动性时段。

推荐加载周期: M15
策略核心逻辑:
  • 波动率检测:计算ATR(20)并检测区间收窄(当前区间 < 0.6倍平均区间)。

  • 突破入场:当价格突破近期20周期最高/最低价并伴随动量确认(收盘价 > 前高+点差)。

  • 网格回血:若首单方向错误,在1.5倍距离处以2倍手数加仓(最多3层)。

  • 风险控制:基于权益的动态手数(每$1000权益0.01手),总风险不超过权益的8%,避开亚盘时段(00:00-08:00 GMT)。


  • ``mql4
    //+------------------------------------------------------------------+
    //| GoldThunderboltEA.mq4 |
    //+------------------------------------------------------------------+
    #property copyright ""
    #property link ""
    #property version "1.00"
    #property strict

    //--- 输入参数及注释
    input double RiskPercent = 2.0; // 每笔风险占权益百分比(2%)
    input int ATRPeriod = 20; // ATR波动率周期
    input double RangeCompression = 0.6; // 区间压缩比率(当前区间/平均区间)触发入场
    input int BreakoutPeriod = 20; // 突破高低点的周期
    input double GridDistanceMultiplier = 1.5; // 网格层级距离倍数(相对于初始止损)
    input double GridLotMultiplier = 2.0; // 回血仓手数倍数(2倍)
    input int MaxGridLevels = 3; // 最大网格回血层数(0=禁用网格)
    input double MaxDrawdownPercent = 15.0; // 最大允许回撤百分比(硬止损)
    input bool UseAsianFilter = true; // 过滤亚盘时段(低波动)
    input int MagicNumber = 202414; // EA魔术号
    input int Slippage = 30; // 最大滑点(单位:点)

    //--- 全局变量
    double currentEquityStart = 0;
    datetime lastBarTime = 0;
    bool drawdownStop = false;
    double baseLotSize = 0.01;
    double initialATR = 0;

    //+------------------------------------------------------------------+
    //| EA初始化函数 |
    //+------------------------------------------------------------------+
    int OnInit()
    {
    currentEquityStart = AccountEquity();
    drawdownStop = false;
    baseLotSize = NormalizeDouble(AccountEquity() RiskPercent / 10000.0, 2);
    if(baseLotSize < 0.01) baseLotSize = 0.01;
    if(baseLotSize > 1.0) baseLotSize = 1.0;
    initialATR = iATR(Symbol(), PERIOD_M15, ATRPeriod, 1);
    return(INIT_SUCCEEDED);
    }

    //+------------------------------------------------------------------+
    //| EA退出函数 |
    //+------------------------------------------------------------------+
    void OnDeinit(const int reason)
    {
    Comment("");
    }

    //+------------------------------------------------------------------+
    //| EA主循环函数(每Tick执行) |
    //+------------------------------------------------------------------+
    void OnTick()
    {
    // 最大回撤保护
    double currentEquity = AccountEquity();
    double drawdownPercent = (currentEquityStart - currentEquity) / currentEquityStart
    100;
    if(drawdownPercent >= MaxDrawdownPercent)
    {
    if(!drawdownStop)
    {
    CloseAllOrders();
    drawdownStop = true;
    Comment("已达最大回撤,EA停止");
    }
    return;
    }

    // 亚盘时段过滤(GMT: 00:00 至 08:00)
    if(UseAsianFilter)
    {
    datetime currentTime = TimeCurrent();
    int hourGMT = TimeHour(currentTime);
    if(hourGMT >= 0 && hourGMT < 8)
    {
    Comment("亚盘时段,暂停交易");
    return;
    }
    }

    // 仅在新K线开始时检测入场(M15)
    if(Time[0] == lastBarTime)
    return;
    lastBarTime = Time[0];

    // 基于权益动态更新基础手数
    baseLotSize = NormalizeDouble(AccountEquity() RiskPercent / 10000.0, 2);
    if(baseLotSize < 0.01) baseLotSize = 0.01;
    if(baseLotSize > 1.0) baseLotSize = 1.0;

    // 检查现有持仓并管理网格回血
    int currentLevels = CountPositions();
    if(currentLevels > 0)
    {
    ManageGridRecovery();
    return;
    }

    // 波动率压缩检测
    double currentRange = iHigh(Symbol(), PERIOD_M15, 1) - iLow(Symbol(), PERIOD_M15, 1);
    double avgRange = iATR(Symbol(), PERIOD_M15, ATRPeriod, 1);
    if(avgRange <= 0) avgRange = currentRange;

    bool isCompressed = (currentRange < avgRange
    RangeCompression);
    if(!isCompressed)
    {
    Comment("未检测到波动率压缩");
    return;
    }

    // 突破检测
    int highIdx = iHighest(Symbol(), PERIOD_M15, MODE_HIGH, BreakoutPeriod, 2);
    int lowIdx = iLowest(Symbol(), PERIOD_M15, MODE_LOW, BreakoutPeriod, 2);
    double highBreakout = iHigh(Symbol(), PERIOD_M15, highIdx);
    double lowBreakout = iLow(Symbol(), PERIOD_M15, lowIdx);
    double close1 = iClose(Symbol(), PERIOD_M15, 1);
    double open1 = iOpen(Symbol(), PERIOD_M15, 1);
    double ask = Ask;
    double bid = Bid;

    int cmd = -1;
    double sl = 0, tp = 0;

    // 向上突破:收盘价高于突破高点且收阳线
    if(close1 > highBreakout && close1 > open1)
    {
    cmd = OP_BUY;
    sl = bid - (initialATR 1.5);
    tp = bid + (initialATR
    3.0);
    }
    // 向下突破:收盘价低于突破低点且收阴线
    else if(close1 < lowBreakout && close1 < open1)
    {
    cmd = OP_SELL;
    sl = ask + (initialATR 1.5);
    tp = ask - (initialATR
    3.0);
    }

    if(cmd != -1)
    {
    double lot = baseLotSize;
    int ticket = OrderSend(Symbol(), cmd, lot, (cmd==OP_BUY?ask:bid), Slippage, sl, tp, "Gold Thunderbolt", MagicNumber, 0, clrNONE);
    if(ticket < 0)
    Print("开仓失败,错误码:", GetLastError());
    }
    }

    //+------------------------------------------------------------------+
    //| 管理现有持仓的网格回血系统 |
    //+------------------------------------------------------------------+
    void ManageGridRecovery()
    {
    // 计算总浮动盈亏
    double floatingProfit = 0;
    int buyCount = 0, sellCount = 0;
    double avgBuyPrice = 0, avgSellPrice = 0;

    for(int i = OrdersTotal()-1; i >= 0; i--)
    {
    if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
    {
    if(OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber)
    {
    floatingProfit += OrderProfit() + OrderSwap() + OrderCommission();
    if(OrderType() == OP_BUY)
    {
    buyCount++;
    avgBuyPrice += OrderOpenPrice();
    }
    else if(OrderType() == OP_SELL)
    {
    sellCount++;
    avgSellPrice += OrderOpenPrice();
    }
    }
    }
    }

    if(buyCount > 0) avgBuyPrice /= buyCount;
    if(sellCount > 0) avgSellPrice /= sellCount;

    int totalOrders = buyCount + sellCount;

    // 检查是否需要添加网格层
    if(totalOrders > 0 && totalOrders < MaxGridLevels)
    {
    double atr = iATR(Symbol(), PERIOD_M15, ATRPeriod, 1);
    double gridDistance = atr GridDistanceMultiplier;

    // 获取首单方向
    OrderSelect(0, SELECT_BY_POS, MODE_TRADES);
    int firstCmd = OrderType();
    double currentPrice = (firstCmd == OP_BUY) ? Bid : Ask;
    double entryPrice = OrderOpenPrice();

    double distanceFromEntry = MathAbs(currentPrice - entryPrice) / Point;
    double requiredDistance = gridDistance / Point;

    // 如果价格向不利方向移动了网格距离,添加回血仓
    if(distanceFromEntry >= requiredDistance && totalOrders < MaxGridLevels)
    {
    double newLot = baseLotSize
    MathPow(GridLotMultiplier, totalOrders);
    if(newLot > 1.0) newLot = 1.0;

    int newCmd = firstCmd;
    double sl = 0, tp = 0;

    if(newCmd == OP_BUY)
    {
    sl = currentPrice - (atr 1.5);
    tp = currentPrice + (atr
    2.5);
    }
    else
    {
    sl = currentPrice + (atr 1.5);
    tp = currentPrice - (atr
    2.5);
    }

    int ticket = OrderSend(Symbol(), newCmd, newLot, currentPrice, Slippage, sl, tp, "Grid Recovery", MagicNumber, 0, clrNONE);
    if(ticket > 0)
    Print("网格第 ", totalOrders+1, " 层已开仓");
    }
    }

    // 当总浮动盈亏为正时平仓获利
    if(floatingProfit > 0 && totalOrders > 0)
    {
    CloseAllOrders();
    Print("网格获利平仓:", floatingProfit);
    }
    }

    //+------------------------------------------------------------------+
    //| 统计当前魔术号的持仓数量 |
    //+------------------------------------------------------------------+
    int CountPositions()
    {
    int count = 0;
    for(int i = OrdersTotal()-1; i >= 0; i--)
    {
    if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
    {
    if(OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber)
    count++;
    }
    }
    return count;
    }

    //+------------------------------------------------------------------+
    //| 平仓当前品种下所有属于该EA的订单 |
    //+------------------------------------------------------------------+
    void CloseAllOrders()
    {
    for(int i = OrdersTotal()-1; i >= 0; i--)
    {
    if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
    {
    if(OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber)
    {
    if(OrderType() == OP_BUY)
    OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, clrNONE);
    else if(OrderType() == OP_SELL)
    OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, clrNONE);
    }
    }
    }
    }
    //+------------------------------------------------------------------+
    `
    参考来源: 原创MQL4代码,仅供学习参考。
    免责声明: 本EA使用网格回血系统,在不利行情下可能放大亏损。高暴利策略伴随相应高风险。本EA按“原样”提供,不保证盈利。实盘交易前请至少在模拟账户测试3个月。历史表现不代表未来结果。
    ``