Summary: 黄金新星爆发EA是一款专为XAUUSD设计的高暴利MQL4智能交易系统。使用布林带挤压检测+动量突破入场,反马丁格尔仓位管理,适合H1周期。




黄金新星爆发EA专为黄金(XAUUSD)设计,通过捕捉强劲的动量爆发来实现高暴利潜力。EA利用布林带挤压检测识别波动率突然扩张,然后在第一个强劲的方向性K线上入场。与增加风险的网格/马丁格尔不同,本EA采用反马丁格尔方法:仅在盈利交易后增加手数(正强化)。动态保本止损和利润追踪锁定收益。每日亏损限制和时段过滤器即使在不利的黄金行情下也能提供稳定性。

推荐加载周期: H1
策略核心逻辑:
  • 挤压检测:布林带(20,2)宽度 < 过去50根K线平均宽度的0.5倍 → 波动率收缩。

  • 动量入场:挤压之后,第一根H1 K线实体 > 1.5倍ATR(14)时,朝实体方向入场。

  • 反马丁格尔手数:基础手数0.01。每盈利一单,下一单手数增加0.01(上限0.1)。亏损后重置为基础手数。

  • 风险控制:固定止损=2.5倍ATR,止盈=5倍ATR(盈亏比2:1)。盈利达3倍ATR后启动追踪止损。每日亏损上限6%。最大同时持仓2单。


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

    //--- 输入参数及注释
    input double BaseLotSize = 0.01; // 基础手数(最小0.01)
    input double MaxLotSize = 0.10; // 最大手数上限
    input int BBPeriod = 20; // 布林带周期
    input double BBDeviation = 2.0; // 布林带标准差倍数
    input double SqueezeRatio = 0.5; // 挤压阈值(带宽/平均带宽)
    input int ATRPeriod = 14; // ATR周期(用于止损止盈和动量过滤)
    input double MomentumBodyRatio = 1.5; // 最小K线实体为ATR的倍数(触发入场)
    input double StopLossATRMult = 2.5; // 止损为ATR的倍数
    input double TakeProfitATRMult = 5.0; // 止盈为ATR的倍数(2:1盈亏比)
    input int TrailingStartATR = 3; // 盈利达到此ATR倍数时启动追踪止损
    input int TrailingStepATR = 1; // 追踪步长(ATR倍数)
    input double DailyLossLimit = 6.0; // 每日亏损限额(账户余额百分比)
    input int MaxConcurrentTrades = 2; // 最大同时持仓数量
    input int MagicNumber = 202415; // EA魔术号
    input int MaxSpread = 35; // 最大允许点差(单位:点)

    //--- 全局变量
    double dailyStartBalance = 0;
    datetime lastBarTime = 0;
    double lastTradeResult = 0; // 0=无结果, 1=盈利, -1=亏损
    double currentLotSize = 0.01;
    int consecutiveWins = 0;
    double avgBBWidth = 0;

    //+------------------------------------------------------------------+
    //| EA初始化函数 |
    //+------------------------------------------------------------------+
    int OnInit()
    {
    dailyStartBalance = AccountBalance();
    lastBarTime = 0;
    lastTradeResult = 0;
    consecutiveWins = 0;
    currentLotSize = BaseLotSize;
    avgBBWidth = 0;
    return(INIT_SUCCEEDED);
    }

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

    //+------------------------------------------------------------------+
    //| 根据上次交易结果更新反马丁格尔手数 |
    //+------------------------------------------------------------------+
    void UpdateLotSizeFromLastTrade()
    {
    // 查找本EA最近一笔平仓记录
    datetime lastCloseTime = 0;
    double lastProfit = 0;

    for(int i = OrdersHistoryTotal()-1; i >= 0; i--)
    {
    if(OrderSelect(i, SELECT_BY_POS, MODE_HISTORY))
    {
    if(OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber)
    {
    if(OrderCloseTime() > lastCloseTime)
    {
    lastCloseTime = OrderCloseTime();
    lastProfit = OrderProfit() + OrderSwap() + OrderCommission();
    }
    }
    }
    }

    if(lastCloseTime > 0)
    {
    if(lastProfit > 0)
    {
    consecutiveWins++;
    // 反马丁格尔:盈利后增加手数
    currentLotSize = BaseLotSize + (consecutiveWins 0.01);
    if(currentLotSize > MaxLotSize) currentLotSize = MaxLotSize;
    lastTradeResult = 1;
    }
    else
    {
    consecutiveWins = 0;
    currentLotSize = BaseLotSize;
    lastTradeResult = -1;
    }
    }
    }

    //+------------------------------------------------------------------+
    //| 计算布林带宽度(百分比) |
    //+------------------------------------------------------------------+
    double GetBBWidth(int shift)
    {
    double upper = iBands(Symbol(), PERIOD_H1, BBPeriod, BBDeviation, 0, PRICE_CLOSE, MODE_UPPER, shift);
    double lower = iBands(Symbol(), PERIOD_H1, BBPeriod, BBDeviation, 0, PRICE_CLOSE, MODE_LOWER, shift);
    if(upper > 0 && lower > 0)
    return (upper - lower) / iClose(Symbol(), PERIOD_H1, shift);
    return 0;
    }

    //+------------------------------------------------------------------+
    //| EA主循环函数(每Tick执行) |
    //+------------------------------------------------------------------+
    void OnTick()
    {
    // 每日净值保护
    double currentEquity = AccountEquity();
    double lossPercent = (dailyStartBalance - currentEquity) / dailyStartBalance
    100;
    if(lossPercent >= DailyLossLimit)
    {
    Comment("已达每日亏损上限,停止开新仓");
    return;
    }

    // 点差过滤
    if(MarketInfo(Symbol(), MODE_SPREAD) > MaxSpread)
    {
    Comment("当前点差过大:", MarketInfo(Symbol(), MODE_SPREAD));
    return;
    }

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

    // 每根新K线更新手数(基于上次交易结果)
    UpdateLotSizeFromLastTrade();

    // 统计当前持仓数量
    int currentPositions = CountPositions();

    // 管理现有持仓的追踪止损
    if(currentPositions > 0)
    {
    ManageTrailingStop();
    }

    // 入场条件 - 不超过最大同时持仓数
    if(currentPositions >= MaxConcurrentTrades)
    return;

    // 布林带挤压检测
    double currentWidth = GetBBWidth(1);
    double widthSum = 0;
    int widthCount = 0;
    for(int i = 2; i <= 51; i++)
    {
    double w = GetBBWidth(i);
    if(w > 0)
    {
    widthSum += w;
    widthCount++;
    }
    }
    double avgWidth = (widthCount > 0) ? widthSum / widthCount : currentWidth;
    if(avgWidth > 0)
    avgBBWidth = (avgBBWidth == 0) ? avgWidth : (avgBBWidth 0.9 + avgWidth 0.1);

    bool isSqueeze = (currentWidth < avgBBWidth SqueezeRatio);
    if(!isSqueeze)
    {
    Comment("未检测到挤压。BB宽度比:", currentWidth/avgBBWidth);
    return;
    }

    // 动量K线检测
    double atr = iATR(Symbol(), PERIOD_H1, ATRPeriod, 1);
    if(atr <= 0) return;

    double body1 = MathAbs(iClose(Symbol(), PERIOD_H1, 1) - iOpen(Symbol(), PERIOD_H1, 1));
    double body2 = MathAbs(iClose(Symbol(), PERIOD_H1, 2) - iOpen(Symbol(), PERIOD_H1, 2));

    bool strongMomentum = (body1 > atr
    MomentumBodyRatio);
    if(!strongMomentum)
    {
    Comment("无强劲动量K线。实体:", body1/Point, " ATR:", atr/Point);
    return;
    }

    // 判断方向
    double close1 = iClose(Symbol(), PERIOD_H1, 1);
    double open1 = iOpen(Symbol(), PERIOD_H1, 1);
    double close2 = iClose(Symbol(), PERIOD_H1, 2);

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

    // 多头动量:收盘>开盘 且 收盘>前一根收盘
    if(close1 > open1 && close1 > close2)
    {
    cmd = OP_BUY;
    entryPrice = Ask;
    sl = entryPrice - (atr StopLossATRMult);
    tp = entryPrice + (atr
    TakeProfitATRMult);
    }
    // 空头动量:收盘<开盘 且 收盘<前一根收盘
    else if(close1 < open1 && close1 < close2)
    {
    cmd = OP_SELL;
    entryPrice = Bid;
    sl = entryPrice + (atr StopLossATRMult);
    tp = entryPrice - (atr
    TakeProfitATRMult);
    }

    if(cmd != -1)
    {
    double lotToUse = currentLotSize;
    if(lotToUse < BaseLotSize) lotToUse = BaseLotSize;
    if(lotToUse > MaxLotSize) lotToUse = MaxLotSize;

    int ticket = OrderSend(Symbol(), cmd, lotToUse, entryPrice, 3, sl, tp, "Gold Nova Surge", MagicNumber, 0, clrNONE);
    if(ticket > 0)
    {
    Print("入场触发。手数:", lotToUse, " 方向:", (cmd==OP_BUY?"买入":"卖出"));
    }
    else
    {
    Print("开仓失败,错误码:", GetLastError());
    }
    }
    }

    //+------------------------------------------------------------------+
    //| 管理所有持仓的追踪止损 |
    //+------------------------------------------------------------------+
    void ManageTrailingStop()
    {
    for(int i = OrdersTotal()-1; i >= 0; i--)
    {
    if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
    {
    if(OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber)
    {
    double atr = iATR(Symbol(), PERIOD_H1, ATRPeriod, 1);
    if(atr <= 0) continue;

    double newSL = 0;
    double profitInPoints = 0;

    if(OrderType() == OP_BUY)
    {
    profitInPoints = (Bid - OrderOpenPrice()) / Point;
    if(profitInPoints >= TrailingStartATR (atr/Point))
    {
    newSL = Bid - (TrailingStepATR
    atr);
    if(newSL > OrderStopLoss())
    {
    if(OrderModify(OrderTicket(), OrderOpenPrice(), newSL, OrderTakeProfit(), 0, clrNONE))
    Print("买入追踪止损更新 #", OrderTicket());
    }
    }
    }
    else if(OrderType() == OP_SELL)
    {
    profitInPoints = (OrderOpenPrice() - Ask) / Point;
    if(profitInPoints >= TrailingStartATR (atr/Point))
    {
    newSL = Ask + (TrailingStepATR
    atr);
    if(newSL < OrderStopLoss() || OrderStopLoss() == 0)
    {
    if(OrderModify(OrderTicket(), OrderOpenPrice(), newSL, OrderTakeProfit(), 0, clrNONE))
    Print("卖出追踪止损更新 #", OrderTicket());
    }
    }
    }
    }
    }
    }
    }

    //+------------------------------------------------------------------+
    //| 统计当前魔术号的持仓数量 |
    //+------------------------------------------------------------------+
    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;
    }
    //+------------------------------------------------------------------+
    `
    参考来源: 原创MQL4代码,仅供学习参考。
    免责声明: 外汇及黄金交易具有重大风险。本高暴利EA使用反马丁格尔仓位管理,在连续亏损时可能导致更大损失。本EA按“原样”提供,不保证盈利。实盘交易前请至少在模拟账户测试3个月。历史表现不代表未来结果。
    ``