Summary: 黄金高暴利EA是一款专为XAUUSD设计的高收益潜力MQL4智能交易系统。使用波动率突破+网格加仓策略,适合M15周期,带有严格回撤控制。
黄金高暴利EA专门为黄金(XAUUSD)设计,旨在捕捉高收益机会的同时保持结构化的风险控制。该EA在M15周期上采用波动率突破策略,当价格突破近期高低点且ATR确认足够波动时入场。独特的层级网格加仓系统在市场逆向运动时按预设间隔加仓,但限制最多3层以控制回撤。EA基于波动率动态计算止盈,并首单带有硬止损。每日止盈目标和最大回撤限制保护账户。
推荐加载周期: M15
策略核心逻辑:
1. 突破检测:价格收盘突破M15周期20根K线高点(做多)或低点(做空)。
2. 波动率确认:ATR(14)高于阈值(避免超低波动行情)。
3. 网格加仓:首单浮亏达到GridStepPoints点数时,按LotMultiplier倍数加仓同向第二单,最多3层。
4. 出场:所有仓位平均价格达到TakeProfitPoints点数时整体止盈。首单设有StopLossPoints硬止损。
5. 风控:每日最大亏损10%,最大点差40点,新闻时段自动暂停交易。
```mql4
//+------------------------------------------------------------------+
//| GoldHighYieldEA.mq4 |
//+------------------------------------------------------------------+
#property copyright ""
#property link ""
#property version "1.00"
#property strict
//--- 输入参数及注释
input double BaseLotSize = 0.01; // 首单手数
input double LotMultiplier = 1.5; // 每层加仓倍数(1.5倍、2.0倍等)
input int BreakoutPeriod = 20; // 突破高低点周期(K线数量)
input int ATRPeriod = 14; // ATR波动率指标周期
input double ATRMinThreshold = 1.2; // 最小ATR倍数(相对150点基准)
input int GridStepPoints = 250; // 网格加仓间隔点数(黄金250点)
input int MaxLayers = 3; // 最大加仓层数(1-5层推荐)
input int TakeProfitPoints = 400; // 整体止盈点数(从均价计算)
input int StopLossPoints = 800; // 首单硬止损点数
input int MagicNumber = 202414; // EA魔术号
input int MaxSpread = 40; // 最大允许点差(黄金点差)
input double DailyProfitTarget = 15.0; // 每日止盈目标(百分比,达到后全平)
input double DailyLossLimit = 10.0; // 每日亏损限额(百分比)
input bool UseNewsFilter = true; // 重大新闻前后30分钟暂停交易
//--- 全局变量
double dailyStartBalance = 0;
datetime lastBarTime = 0;
bool isDailyTargetHit = false;
string newsTimes[] = {"13:30","15:00","18:00"}; // 示例新闻时间(美盘时段)
//+------------------------------------------------------------------+
//| EA初始化函数 |
//+------------------------------------------------------------------+
int OnInit()
{
dailyStartBalance = AccountBalance();
lastBarTime = 0;
isDailyTargetHit = false;
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| EA退出函数 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
Comment("");
}
//+------------------------------------------------------------------+
//| EA主循环函数 |
//+------------------------------------------------------------------+
void OnTick()
{
// 每日止盈目标与亏损限额
double currentEquity = AccountEquity();
double profitPercent = (currentEquity - dailyStartBalance) / dailyStartBalance * 100;
double lossPercent = (dailyStartBalance - currentEquity) / dailyStartBalance * 100;
if(profitPercent >= DailyProfitTarget && !isDailyTargetHit)
{
CloseAllOrders();
isDailyTargetHit = true;
Comment("已达每日止盈目标,全平台仓");
return;
}
if(lossPercent >= DailyLossLimit)
{
Comment("已达每日亏损上限,停止开新仓");
return;
}
// 新交易日重置当日余额
if(TimeDayOfYear(TimeCurrent()) != TimeDayOfYear(TimeCurrent() - PeriodSeconds(PERIOD_D1)))
{
dailyStartBalance = AccountBalance();
isDailyTargetHit = false;
}
// 新闻过滤
if(UseNewsFilter && IsNewsTime())
{
Comment("新闻时段,暂停交易");
return;
}
// 点差过滤
if(MarketInfo(Symbol(), MODE_SPREAD) > MaxSpread)
{
Comment("点差过大: ", MarketInfo(Symbol(), MODE_SPREAD));
return;
}
// 新K线逻辑(M15)
if(Time[0] == lastBarTime)
return;
lastBarTime = Time[0];
// 已有持仓时检查网格止盈和加仓
if(CountPositions() > 0)
{
CheckGridTakeProfit();
CheckAddGridLayer();
return;
}
// ATR波动率过滤
double atr = iATR(Symbol(), PERIOD_M15, ATRPeriod, 1);
double atrMin = ATRMinThreshold * 150;
if(atr < atrMin)
{
Comment("波动率过低,ATR: ", atr);
return;
}
// 突破检测
double high20 = iHigh(Symbol(), PERIOD_M15, iHighest(Symbol(), PERIOD_M15, MODE_HIGH, BreakoutPeriod, 1));
double low20 = iLow(Symbol(), PERIOD_M15, iLowest(Symbol(), PERIOD_M15, MODE_LOW, BreakoutPeriod, 1));
double close1 = iClose(Symbol(), PERIOD_M15, 1);
int cmd = -1;
double sl = 0, tp = 0;
if(close1 > high20)
{
cmd = OP_BUY;
sl = SymbolInfoDouble(Symbol(), SYMBOL_BID) - StopLossPoints * Point;
tp = SymbolInfoDouble(Symbol(), SYMBOL_BID) + TakeProfitPoints * Point;
}
else if(close1 < low20)
{
cmd = OP_SELL;
sl = SymbolInfoDouble(Symbol(), SYMBOL_ASK) + StopLossPoints * Point;
tp = SymbolInfoDouble(Symbol(), SYMBOL_ASK) - TakeProfitPoints * Point;
}
if(cmd != -1)
{
int ticket = OrderSend(Symbol(), cmd, BaseLotSize, (cmd==OP_BUY?Ask:Bid), 3, sl, tp, "Gold HighYield", MagicNumber, 0, clrNONE);
if(ticket < 0)
Print("开仓失败,错误码:", GetLastError());
}
}
//+------------------------------------------------------------------+
//| 检查网格整体止盈条件 |
//+------------------------------------------------------------------+
void CheckGridTakeProfit()
{
double totalProfit = 0;
double totalLots = 0;
double weightedPrice = 0;
for(int i = OrdersTotal()-1; i >= 0; i--)
{
if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if(OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber)
{
totalProfit += OrderProfit() + OrderSwap() + OrderCommission();
totalLots += OrderLots();
weightedPrice += OrderOpenPrice() * OrderLots();
}
}
}
if(totalLots == 0) return;
double avgPrice = weightedPrice / totalLots;
double currentPrice = 0;
int tempType = -1;
for(int i = OrdersTotal()-1; i >= 0; i--)
{
if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if(OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber)
{
tempType = OrderType();
break;
}
}
}
currentPrice = (tempType == OP_BUY) ? Bid : Ask;
double profitPoints = (tempType == OP_BUY) ? (currentPrice - avgPrice) / Point : (avgPrice - currentPrice) / Point;
if(profitPoints >= TakeProfitPoints)
{
CloseAllOrders();
Print("网格整体止盈达成:", profitPoints, " 点");
}
}
//+------------------------------------------------------------------+
//| 检查并添加下一层网格 |
//+------------------------------------------------------------------+
void CheckAddGridLayer()
{
int positions = CountPositions();
if(positions >= MaxLayers)
return;
double avgPrice = 0;
double totalLots = 0;
double weightedPrice = 0;
int orderType = -1;
for(int i = OrdersTotal()-1; i >= 0; i--)
{
if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if(OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber)
{
orderType = OrderType();
totalLots += OrderLots();
weightedPrice += OrderOpenPrice() * OrderLots();
}
}
}
if(totalLots == 0) return;
avgPrice = weightedPrice / totalLots;
double currentPrice = (orderType == OP_BUY) ? Bid : Ask;
double distance = (orderType == OP_BUY) ? (avgPrice - currentPrice) / Point : (currentPrice - avgPrice) / Point;
if(distance >= GridStepPoints)
{
double newLotSize = BaseLotSize * MathPow(LotMultiplier, positions);
if(newLotSize < 0.01) newLotSize = 0.01;
double sl = 0, tp = 0;
if(orderType == OP_BUY)
{
sl = SymbolInfoDouble(Symbol(), SYMBOL_BID) - StopLossPoints * Point;
tp = SymbolInfoDouble(Symbol(), SYMBOL_BID) + TakeProfitPoints * Point;
int ticket = OrderSend(Symbol(), OP_BUY, newLotSize, Ask, 3, sl, tp, "Gold HighYield L" + IntegerToString(positions+1), MagicNumber, 0, clrNONE);
if(ticket > 0)
Print("添加网格第 ", positions+1, " 层 Buy 于 ", Ask);
}
else if(orderType == OP_SELL)
{
sl = SymbolInfoDouble(Symbol(), SYMBOL_ASK) + StopLossPoints * Point;
tp = SymbolInfoDouble(Symbol(), SYMBOL_ASK) - TakeProfitPoints * Point;
int ticket = OrderSend(Symbol(), OP_SELL, newLotSize, Bid, 3, sl, tp, "Gold HighYield L" + IntegerToString(positions+1), MagicNumber, 0, clrNONE);
if(ticket > 0)
Print("添加网格第 ", positions+1, " 层 Sell 于 ", Bid);
}
}
}
//+------------------------------------------------------------------+
//| 判断是否为新闻时段 |
//+------------------------------------------------------------------+
bool IsNewsTime()
{
datetime currentTime = TimeCurrent();
string currentHourMin = TimeToString(currentTime, TIME_MINUTES);
for(int i = 0; i < ArraySize(newsTimes); i++)
{
datetime newsTime = StringToTime(TimeToString(currentTime, TIME_DATE) + " " + newsTimes[i]);
if(MathAbs(currentTime - newsTime) < 1800)
return true;
}
return false;
}
//+------------------------------------------------------------------+
//| 统计当前魔术号的持仓数量 |
//+------------------------------------------------------------------+
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;
}
//+------------------------------------------------------------------+
//| 平仓所有订单 |
//+------------------------------------------------------------------+
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, 3, clrNONE);
else if(OrderType() == OP_SELL)
OrderClose(OrderTicket(), OrderLots(), Ask, 3, clrNONE);
}
}
}
}
//+------------------------------------------------------------------+
```
参考来源: 原创MQL4代码,仅供学习参考。
免责声明: 高暴利策略如网格交易存在较大回撤风险。本EA按“原样”提供,不保证盈利。“高暴利”指潜在收益可能性,并非确定性。实盘前请在模拟账户充分测试至少3个月。历史表现不代表未来结果。
```