English
中文
日本語
ID
Vietnam
한국어
Filipino
 
   学院导航

MQL4 趋势指标 EA

MQL4 Trend Indicator EA

大多数交易系统使用指标来确定交易信号。 Metatrader 包括 20 多种常用指标,包括移动平均线、MACD、RSI 和随机指标。 MQL 内置了股票指标函数。 您还可以在您的智能交易系统中使用自定义指标。 在这篇 MQL4 趋势指标 EA 文章中了解如何对 Expert Advisor 进行编程以使用最流行的趋势指标进行交易。

趋势指标

移动平均线是最著名的趋势指标。 它显示价格在指标期间是上涨还是下跌。 我们已经了解了如何构造移动平均线交叉的条件。 让我们检查策略进入和退出的其他趋势指标的条件。


如果您转到您的 MT4 控制台并单击插入/指标/趋势,您将获得以下指标列表:


平均方向指数

布林带

商品通道指数

移动平均线

抛物线 SAR

标准偏差

使用注意事项

如果您有兴趣在您的自定义 EA 中插入任何代码,您可以将外部变量复制并粘贴到您的外部变量部分。 然后,使用我的模板作为指导,将指标调用变量复制并粘贴到 start() 函数中的某处,在这些模板下方,您可以复制并粘贴买卖条件。 或者,您可以下载并使用我围绕每个指标构建的 EA。


 

ParamsAverage Directional Index
Intent

//买入:+DI线高于-DI线,ADX大于一定值

并增长(即趋势加强)

//卖出:-D线高于+DI线,ADX大于一定值

并增长(即趋势加强)

Externextern int adx=0; //Indicator period
extern int adu=14; //Period of averaging for index calculation
extern double minadx=20; //Minimal threshold value of ADX
Indicator
Calling
PosDLine =iADX(NULL,adx,adu,PRICE_CLOSE,MODE_PLUSDI,0);
NegDLine =iADX(NULL,adx,adu,PRICE_CLOSE,MODE_MINUSDI,0);
ADXCurrent =iADX(NULL,adx,adu,PRICE_CLOSE,MODE_MAIN,0);
ADXPrevious =iADX(NULL,adx,adu,PRICE_CLOSE,MODE_MAIN,1);
BuyCondif (PosDLine > NegDLine && ADXCurrent >= minadx
&& ADXCurrent > ADXPrevious)
SellCondif (NegDLine > PosDLine && ADXCurrent >= minadx
&& ADXCurrent > ADXPrevious)

ParamsBollinger Band
Intent//Buy: price crossed lower line upwards (returned to it from below)
//Sell: price crossed upper line downwards (returned to it from above)
Externextern int bandp=0; //Indicator period
extern int bandpx=20; //Period of averaging for indicator calculation
extern int banddev=2; //Deviation from the main line
Indicator
Calling
BBLowCurrent=iBands(NULL,bandp, bandpx, banddev,0,PRICE_CLOSE,MODE_LOWER,0);
BBLowPrevious=iBands(NULL,bandp, bandpx, banddev,0,PRICE_CLOSE,MODE_LOWER,1);
BBUpCurrent=iBands(NULL,bandp, bandpx, banddev,0,PRICE_CLOSE,MODE_UPPER,0);
BBUpPrevious=iBands(NULL,bandp, bandpx, banddev,0,PRICE_CLOSE,MODE_UPPER,1);
BBCurrentClose = iClose (NULL, 0,0);
BBPreviousClose = iClose (NULL, 0,1);
BuyCondif (BBLowPrevious<BBPreviousClose
&& BBLowCurrent>=BBCurrentClose)
SellCondif (BBUpPrevious>BBPreviousClose
&& BBUpCurrent<=BBCurrentClose)

 Commodity Chanel Index
Intent//Buy: 1. indicator crosses +100 from below upwards. 2. Crossing -100 from below upwards. 3.
//Sell: 1. indicator crosses -100 from above downwards. 2. Crossing +100 downwards. 3.
Externextern int CCp=0; //Indicator period
extern int CCpx=14; //Period of averaging for indicator calculation
extern int CCLine = 100;
Indicator
Calling
CCCurrent = iCCI(NULL,CCp,CCpx,PRICE_TYPICAL,0);
CCPrevious = iCCI(NULL,CCp,CCpx,PRICE_TYPICAL,1);
CCCrossLinePos = CCLine;
CCCrossLineNeg =-CCLine;
BuyCondif ((CCPrevious<CCCrossLinePos && CCCurrent >= CCCrossLinePos) || (CCPrevious <=CCCrossLineNeg&& CCCurrent>=CCCrossLineNeg) )
SellCondif ((CCPrevious>CCCrossLinePos && CCCurrent <= CCCrossLinePos)||
(CCPrevious >=CCCrossLineNeg&& CCCurrent<=CCCrossLineNeg) )

 Parabolic Sar
Note//Buy: Parabolic SAR crosses price downwards
//Sell: Parabolic SAR crosses price upwards
Externextern int sar=0; //Indicator period
extern double sarstep=0.02; //Stop level increment
extern double sarstop=0.2; //Maximal stop level
extern int sar2=0; //Price period
Indicator
Calling
sarcurrent = iSAR(NULL,sar,sarstep,sarstop,0);
sarprevious = iSAR(NULL,sar,sarstep,sarstop,1);
closecurrent = iClose(NULL,0,0);
closeprevious = iClose(NULL,0,1);
BuyCondif (sarprevious>closeprevious&&sarcurrent<=closecurrent)
SellCondif (sarprevious<closeprevious&&sarcurrent>=closecurrent)

 MA Rising or Falling
Intent//Buy: MA grows
//Sell: MA falls
Externextern int maperiod=14; //Period of averaging for indicator calculation
extern int mamode = 1; // Type of moving average, 1= Exponential
Indicator
Calling
macurrent = iMA(NULL,0,maperiod,0,mamode,0);
maprevious = iMA(NULL,0,maperiod,0,mamode,1);
maprevious2 =iMA(NULL,0,maperiod,0,mamode,2);
BuyCondif(maprevious2 > maprevious && maprevious > macurrent)
SellCondif (maprevious2 < maprevious && maprevious < macurrent)