黄金信号专业EA专为XAUUSD构建,采用严格的七层过滤系统剔除低概率信号。与典型的网格或马丁格尔EA不同,本策略通过多时间框架确认(M5入场、H1趋势、H4主方向)、波动率状态检测和动态质量评分来优先保证信号质量。每个信号都带有基于当前ATR和市场结构计算的TP/SL水平。EA包含每日净值保护、点差监控、时段过滤和周五平仓机制。
推荐加载周期: M15
策略核心逻辑:
``
mql4
//+------------------------------------------------------------------+
//| GoldSignalProEA.mq4 |
//+------------------------------------------------------------------+
#property copyright ""
#property link ""
#property version "1.00"
#property strict
//--- 输入参数及注释
input double LotSize = 0.01; // 固定交易手数(黄金0.01手)
input int FastMAPeriod = 13; // 快SMA周期(13)
input int MidMAPeriod1 = 21; // 中SMA周期(21)
input int MidMAPeriod2 = 75; // 中SMA周期(75)
input int SlowMAPeriod = 100; // 慢SMA周期(100)
input int H1TrendPeriod = 50; // H1 EMA周期(趋势确认)
input int H4TrendPeriod = 50; // H4 EMA周期(主趋势方向)
input int RSIPeriod = 14; // RSI周期(动量过滤)
input int ATRPeriod = 14; // ATR周期(波动率管理)
input double MaxATRMultiplier = 1.6; // 最大ATR倍数(波动率保护)
input double ATRStopMultiplier = 1.4; // 止损倍数(ATR的倍数)
input double ATRTakeMultiplier = 2.5; // 止盈倍数(ATR的倍数)
input double TrailingStartATR = 1.0; // 追踪止损启动(盈利达到x倍ATR)
input double TrailingStepATR = 0.5; // 追踪步长(ATR倍数)
input int MinQualityScore = 2; // 最低质量评分(1-3,3为最高)
input int MagicNumber = 202420; // EA魔术号
input int MaxSpread = 35; // 最大允许点差(单位:点)
input double DailyLossLimit = 5.0; // 每日亏损限额(账户余额百分比)
input bool UseLondonSessionOnly = true; // 仅在伦敦/纽约重叠时段交易
input bool UseFridayClose = true; // 周五20:00 GMT前平仓
//--- 全局变量
double dailyStartBalance = 0;
datetime lastBarTime = 0;
bool fridayCloseExecuted = false;
double avgATR = 0;
//+------------------------------------------------------------------+
//| EA初始化函数 |
//+------------------------------------------------------------------+
int OnInit()
{
dailyStartBalance = AccountBalance();
lastBarTime = 0;
fridayCloseExecuted = false;
avgATR = iATR(Symbol(), PERIOD_M15, ATRPeriod, 1);
if(avgATR <= 0) avgATR = 180 Point;
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| EA退出函数 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
Comment("");
}
//+------------------------------------------------------------------+
//| 获取更高时间框架趋势方向(H4) |
//+------------------------------------------------------------------+
int GetH4Trend()
{
double closeH4 = iClose(Symbol(), PERIOD_H4, 1);
double emaH4 = iMA(Symbol(), PERIOD_H4, H4TrendPeriod, 0, MODE_EMA, PRICE_CLOSE, 1);
if(closeH4 > emaH4) return 1;
if(closeH4 < emaH4) return -1;
return 0;
}
//+------------------------------------------------------------------+
//| 获取H1趋势确认 |
//+------------------------------------------------------------------+
int GetH1Trend()
{
double closeH1 = iClose(Symbol(), PERIOD_H1, 1);
double emaH1 = iMA(Symbol(), PERIOD_H1, H1TrendPeriod, 0, MODE_EMA, PRICE_CLOSE, 1);
if(closeH1 > emaH1) return 1;
if(closeH1 < emaH1) return -1;
return 0;
}
//+------------------------------------------------------------------+
//| 检查MA结构排列 |
//+------------------------------------------------------------------+
bool IsMAStructured()
{
double sma13 = iMA(Symbol(), PERIOD_M15, FastMAPeriod, 0, MODE_SMA, PRICE_CLOSE, 1);
double sma21 = iMA(Symbol(), PERIOD_M15, MidMAPeriod1, 0, MODE_SMA, PRICE_CLOSE, 1);
double sma75 = iMA(Symbol(), PERIOD_M15, MidMAPeriod2, 0, MODE_SMA, PRICE_CLOSE, 1);
double sma100 = iMA(Symbol(), PERIOD_M15, SlowMAPeriod, 0, MODE_SMA, PRICE_CLOSE, 1);
// 多头排列:13 > 21 > 75 > 100
bool bullish = (sma13 > sma21 && sma21 > sma75 && sma75 > sma100);
// 空头排列:13 < 21 < 75 < 100
bool bearish = (sma13 < sma21 && sma21 < sma75 && sma75 < sma100);
return (bullish || bearish);
}
//+------------------------------------------------------------------+
//| 检查MA斜率(非平坦) |
//+------------------------------------------------------------------+
bool IsMASloping()
{
double sma21_current = iMA(Symbol(), PERIOD_M15, MidMAPeriod1, 0, MODE_SMA, PRICE_CLOSE, 1);
double sma21_prev = iMA(Symbol(), PERIOD_M15, MidMAPeriod1, 0, MODE_SMA, PRICE_CLOSE, 4);
double slope = (sma21_current - sma21_prev) / Point;
// 要求有意义的斜率(不平坦)
return (MathAbs(slope) > 15);
}
//+------------------------------------------------------------------+
//| 计算信号质量评分(1-3) |
//+------------------------------------------------------------------+
int CalculateQualityScore(int direction, double rsi, double atrRatio)
{
int score = 1; // 基础分
// 检查共振因素
bool h4Align = (direction == GetH4Trend());
bool h1Align = (direction == GetH1Trend());
bool maStructured = IsMAStructured();
bool maSloping = IsMASloping();
bool rsiValid = (direction == 1 && rsi > 50 && rsi < 70) || (direction == -1 && rsi < 50 && rsi > 30);
bool lowVolatility = (atrRatio < 1.2);
int confluence = 0;
if(h4Align) confluence++;
if(h1Align) confluence++;
if(maStructured) confluence++;
if(maSloping) confluence++;
if(rsiValid) confluence++;
if(lowVolatility) confluence++;
if(confluence >= 5) score = 3; // ★★★ 强信号
else if(confluence >= 3) score = 2; // ★★ 标准信号
else score = 1; // ★ 谨慎信号
return score;
}
//+------------------------------------------------------------------+
//| 基于价格行为和过滤器检查入场信号 |
//+------------------------------------------------------------------+
bool CheckEntry(int direction, double &entryPrice, double &sl, double &tp, double atr, int qualityScore)
{
if(qualityScore < MinQualityScore) return false;
double close1 = iClose(Symbol(), PERIOD_M15, 1);
double open1 = iOpen(Symbol(), PERIOD_M15, 1);
double high1 = iHigh(Symbol(), PERIOD_M15, 1);
double low1 = iLow(Symbol(), PERIOD_M15, 1);
double ema21 = iMA(Symbol(), PERIOD_M15, MidMAPeriod1, 0, MODE_SMA, PRICE_CLOSE, 1);
if(direction == 1) // 做多
{
// 阳线收盘且价格在/接近EMA21上方
bool bullishClose = (close1 > open1);
bool aboveEMA = (low1 > ema21 || close1 > ema21);
bool noUpperWick = ((high1 - close1) < (close1 - open1) 0.5);
if(bullishClose && aboveEMA && noUpperWick)
{
entryPrice = Ask;
sl = entryPrice - (atr ATRStopMultiplier);
tp = entryPrice + (atr ATRTakeMultiplier);
return true;
}
}
else if(direction == -1) // 做空
{
// 阴线收盘且价格在/接近EMA21下方
bool bearishClose = (close1 < open1);
bool belowEMA = (high1 < ema21 || close1 < ema21);
bool noLowerWick = ((close1 - low1) < (open1 - close1) 0.5);
if(bearishClose && belowEMA && noLowerWick)
{
entryPrice = Bid;
sl = entryPrice + (atr ATRStopMultiplier);
tp = entryPrice - (atr ATRTakeMultiplier);
return true;
}
}
return false;
}
//+------------------------------------------------------------------+
//| 检查当前时间是否在伦敦/纽约交易时段 |
//+------------------------------------------------------------------+
bool IsValidSession()
{
if(!UseLondonSessionOnly) return true;
datetime currentTime = TimeCurrent();
int hour = TimeHour(currentTime);
int minute = TimeMinute(currentTime);
int currentMinutes = hour 60 + minute;
// 伦敦时段:08:00 - 16:00 GMT
int londonStart = 8 60;
int londonEnd = 16 60;
// 纽约时段:13:00 - 22:00 GMT
int nyStart = 13 60;
int nyEnd = 22 60;
// 伦敦-纽约重叠:13:00 - 16:00 GMT(流动性最佳)
bool inOverlap = (currentMinutes >= 13 60 && currentMinutes < 16 60);
bool inLondon = (currentMinutes >= londonStart && currentMinutes < londonEnd);
bool inNewYork = (currentMinutes >= nyStart && currentMinutes < nyEnd);
return (inOverlap || inLondon || inNewYork);
}
//+------------------------------------------------------------------+
//| 管理持仓的追踪止损 |
//+------------------------------------------------------------------+
void ManageTrailingStop(double atr)
{
for(int i = OrdersTotal()-1; i >= 0; i--)
{
if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if(OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber)
{
double activate = atr TrailingStartATR;
double step = atr TrailingStepATR;
double newSL = 0;
if(OrderType() == OP_BUY)
{
double profit = Bid - OrderOpenPrice();
if(profit >= activate)
{
newSL = Bid - step;
if(newSL > OrderStopLoss())
OrderModify(OrderTicket(), OrderOpenPrice(), newSL, OrderTakeProfit(), 0, clrNONE);
}
}
else if(OrderType() == OP_SELL)
{
double profit = OrderOpenPrice() - Ask;
if(profit >= activate)
{
newSL = Ask + step;
if(newSL < OrderStopLoss() || OrderStopLoss() == 0)
OrderModify(OrderTicket(), OrderOpenPrice(), newSL, OrderTakeProfit(), 0, clrNONE);
}
}
break;
}
}
}
}
//+------------------------------------------------------------------+
//| EA主循环函数(每Tick执行) |
//+------------------------------------------------------------------+
void OnTick()
{
// 每日净值保护
double currentEquity = AccountEquity();
double lossPercent = (dailyStartBalance - currentEquity) / dailyStartBalance 100;
if(lossPercent >= DailyLossLimit)
{
Comment("已达每日亏损上限,停止开新仓");
return;
}
// 周五收盘前平仓(规避周末跳空)
if(UseFridayClose && !fridayCloseExecuted)
{
datetime currentTime = TimeCurrent();
if(TimeDayOfWeek(currentTime) == 5 && TimeHour(currentTime) >= 20)
{
CloseAllOrders();
fridayCloseExecuted = true;
return;
}
if(TimeDayOfWeek(currentTime) != 5)
fridayCloseExecuted = false;
}
// 时段过滤
if(!IsValidSession())
{
Comment("非伦敦/纽约交易时段");
return;
}
// 点差过滤
if(MarketInfo(Symbol(), MODE_SPREAD) > MaxSpread)
{
Comment("当前点差过大:", MarketInfo(Symbol(), MODE_SPREAD));
return;
}
// 仅在新K线开始时检测入场(M15)
if(Time[0] == lastBarTime)
return;
lastBarTime = Time[0];
// 管理现有持仓
int posCount = CountPositions();
if(posCount > 0)
{
double atr = iATR(Symbol(), PERIOD_M15, ATRPeriod, 1);
if(atr > 0) ManageTrailingStop(atr);
return;
}
// 获取指标
double close1 = iClose(Symbol(), PERIOD_M15, 1);
double rsi = iRSI(Symbol(), PERIOD_M15, RSIPeriod, PRICE_CLOSE, 1);
double atr = iATR(Symbol(), PERIOD_M15, ATRPeriod, 1);
// 更新平均ATR用于波动率过滤
if(atr > 0) avgATR = (avgATR 0.95) + (atr 0.05);
// 波动率保护
double atrRatio = atr / avgATR;
if(atr > avgATR MaxATRMultiplier && avgATR > 0)
{
Comment("当前波动率过高,ATR比率: ", atrRatio);
return;
}
// 获取H4主趋势
int h4Trend = GetH4Trend();
if(h4Trend == 0)
{
Comment("H4无明确趋势方向");
return;
}
// RSI动量过滤
if(h4Trend == 1 && rsi < 50)
{
Comment("RSI低于50,无上涨动能");
return;
}
if(h4Trend == -1 && rsi > 50)
{
Comment("RSI高于50,无下跌动能");
return;
}
// 计算质量评分
int qualityScore = CalculateQualityScore(h4Trend, rsi, atrRatio);
// 在图表上显示质量评分
string scoreStars = (qualityScore == 3) ? "★★★ 强信号" : ((qualityScore == 2) ? "★★ 标准信号" : "★ 谨慎信号");
Comment("信号质量: ", scoreStars, " | H4趋势: ", (h4Trend==1?"多头":"空头"), " | ATR比率: ", DoubleToStr(atrRatio,2));
// 检查入场条件
double entryPrice = 0, sl = 0, tp = 0;
if(CheckEntry(h4Trend, entryPrice, sl, tp, atr, qualityScore))
{
int cmd = (h4Trend == 1) ? OP_BUY : OP_SELL;
int ticket = OrderSend(Symbol(), cmd, LotSize, entryPrice, 5, sl, tp, "Gold Signal Pro", MagicNumber, 0, clrNONE);
if(ticket < 0)
Print("开仓失败,错误码:", GetLastError());
else
Print("开仓成功,方向:", cmd==OP_BUY?"买入":"卖出", " | 质量评分: ", qualityScore);
}
}
//+------------------------------------------------------------------+
//| 统计当前魔术号的持仓数量 |
//+------------------------------------------------------------------+
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, 5, clrNONE);
else if(OrderType() == OP_SELL)
OrderClose(OrderTicket(), OrderLots(), Ask, 5, clrNONE);
}
}
}
}
//+------------------------------------------------------------------+
`
参考来源: 原创MQL4代码,策略架构参考了专业黄金交易系统的多层过滤与信号评分方法论。
免责声明: 黄金交易因高波动性具有重大风险。本EA按“原样”提供,不保证盈利。实盘部署前请在模拟账户充分测试。历史表现不代表未来结果。
``