内置指标概述
终端提供了大量常用指标,这些指标也可以通过 API 访问。因此,你无需在 MQL5 中实现其算法。此类指标通过类似于iCustom的内置函数创建。例如,我们之前出于教学目的创建了自定义版本的 WPR 和 EMA。不过,可直接通过 iWPR和iTEMA 函数使用相应的指标。下表列出了所有可用指标。
所有内置指标均以字符串形式的工作交易品种和时间范围作为前两个参数,并返回一个整数作为指标描述符。通常,所有函数的原型如下:
int iFunction(const string symbol, ENUM_TIMEFRAMES timeframe, ...)
省略号部分将由特定指标的具体参数替代。它们的数量和类型各不相同。部分指标没有参数。
例如,WPR 与我们自建版本一样,只有一个参数,即周期:int iWPR(const string symbol, ENUM_TIMEFRAMES timeframe, int period)。与我们的版本不同,内置分形指标没有特殊参数:int iFractals(const string symbol, ENUM_TIMEFRAMES period)。在此情况下,分形的阶数采用硬编码,值为 2,即极值点(顶部或底部)前后必须分别至少有两根柱线的 high和 low 价不超过该极值点。
允许将值设置为 NULL,而非交易品种。NULL 表示当前图表的工作交易品种,而 timeframe参数中的值 0 对应于当前图表的时间范围,因为它也是 ENUM_TIMEFRAMES 枚举中的 PERIOD_CURRENT 值(请参阅 交易品种和时间范围章节)。
还需要注意,不同类型的指标具有不同数量的缓冲区。例如,移动平均线或 WPR 只有一个缓冲区,而分形指标有两个。缓冲区数量也会在表格的单独一列中注明。
函数 |
指标名称 |
选项 |
缓冲区数量 |
---|---|---|---|
iAC |
Accelerator Oscillator |
― |
1* |
iAD |
Accumulation / Distribution |
ENUM_APPLIED_VOLUME volume |
1* |
iADX |
Average Directional Index |
int period |
3* |
iADXWilder |
Average Directional Index by Welles Wilder |
int period |
3* |
iAlligator |
Alligator |
int jawPeriod, int jawShift, int teethPeriod,int teethShift, int lipsPeriod, int lipsShift, ENUM_MA_METHOD method, ENUM_APPLIED_PRICE price |
3 |
iAMA |
Adaptive Moving Average |
int period, int fast, int slow, int shift, ENUM_APPLIED_PRICE price |
1 |
iAO |
Awesome Oscillator |
― |
1* |
iATR |
Average True Range |
int period |
1* |
iBands |
Bollinger Bands |
int period, int shift, double deviation, ENUM_APPLIED_PRICE price |
3 |
iBearsPower |
Bears Power |
int period |
1* |
iBullsPower |
Bulls Power |
int period |
1* |
iBWMFI |
Market Facilitation Index by Bill Williams |
ENUM_APPLIED_VOLUME volume |
1* |
iCCI |
Commodity Channel Index |
int period, ENUM_APPLIED_PRICE price |
1* |
iChaikin |
Chaikin Oscillator |
int fast, int slow, ENUM_MA_METHOD method, ENUM_APPLIED_VOLUME volume |
1* |
iDEMA |
Double Exponential Moving Average |
int period, int shift, ENUM_APPLIED_PRICE price |
1 |
iDeMarker |
DeMarker |
int period |
1* |
iEnvelopes |
Envelopes |
int period, int shift, ENUM_MA_METHOD method, ENUM_APPLIED_PRICE price, double deviation |
2 |
iForce |
Force Index |
int period, ENUM_MA_METHOD method, ENUM_APPLIED_VOLUME volume |
1* |
iFractals |
Fractals |
― |
2 |
iFrAMA |
Fractal Adaptive Moving Average |
int period, int shift, ENUM_APPLIED_PRICE price |
1 |
iGator |
Gator Oscillator |
int jawPeriod, int jawShift, int teethPeriod, int teethShift, int lipsPeriod, int lipsShift, ENUM_MA_METHOD method, ENUM_APPLIED_PRICE price |
4* |
iIchimoku |
Ichimoku Kinko Hyo |
int tenkan, int kijun, int senkou |
5 |
iMomentum |
Momentum |
int period, ENUM_APPLIED_PRICE price |
1* |
iMFI |
Money Flow Index |
int period, ENUM_APPLIED_VOLUME volume |
1* |
iMA |
Moving Average |
int period, int shift, ENUM_MA_METHOD method, ENUM_APPLIED_PRICE price |
1 |
iMACD |
Moving Averages Convergence-Divergence |
int fast, int slow, int signal, ENUM_APPLIED_PRICE price |
2* |
iOBV |
On Balance Volume |
ENUM_APPLIED_VOLUME volume |
1* |
iOsMA |
Moving Average of Oscillator (MACD histogram) |
int fast, int slow, int signal, ENUM_APPLIED_PRICE price |
1* |
iRSI |
Relative Strength Index |
int period, ENUM_APPLIED_PRICE price |
1* |
iRVI |
Relative Vigor Index |
int period |
1* |
iSAR |
Parabolic Stop And Reverse System |
double step, double maximum |
1 |
iStdDev |
Standard Deviation |
int period, int shift, ENUM_MA_METHOD method, ENUM_APPLIED_PRICE price |
1* |
iStochastic |
Stochastic Oscillator |
int Kperiod, int Dperiod, int slowing, ENUM_MA_METHOD method, ENUM_APPLIED_PRICE price |
2* |
iTEMA |
Triple Exponential Moving Average |
int period, int shift, ENUM_APPLIED_PRICE price |
1 |
iTriX |
Triple Exponential Moving Averages Oscillator |
int period, ENUM_APPLIED_PRICE price |
1* |
iVIDyA |
Variable Index Dynamic Average |
int momentum, int smooth, int shift, ENUM_APPLIED_PRICE price |
1 |
iVolumes |
Volumes |
ENUM_APPLIED_VOLUME volume |
1* |
iWPR |
Williams Percent Range |
int period |
1* |
在右侧列中,带有独立窗口的指标均已标注星号 * (它们显示在主图表下方)。
最常用的参数是定义指标周期的参数(period、fast、slow 等变体),以及线条 shift:当为正数时,绘图向右移动;当为负数时,绘图向左移动指定柱线数量。
许多参数具有应用枚举类型:ENUM_APPLIED_PRICE、ENUM_APPLIED_VOLUME、ENUM_MA_METHOD。我们已经在 枚举章节中介绍过 ENUM_APPLIED_PRICE。所有可用类型及其说明如下表所示。
标识符 |
说明 |
值 |
---|---|---|
PRICE_CLOSE |
柱线收盘价 |
1 |
PRICE_OPEN |
柱线开盘价 |
2 |
PRICE_HIGH |
柱线最高价 |
3 |
PRICE_LOW |
柱线最低价 |
4 |
PRICE_MEDIAN |
中间价,即 (最高价 + 最低价)/2 |
5 |
PRICE_TYPICAL |
典型价,即 (最高价 + 最低价 + 收盘价)/3 |
6 |
PRICE_WEIGHTED |
加权平均价,即 (最高价 + 最低价 + 收盘价 + 收盘价)/4 |
7 |
与成交量相关的指标可基于分时报价成交量(实际为分时报价计数器)或实际成交量(通常仅适用于交易所金融工具)运行。这两种类型都汇总在 ENUM_APPLIED_VOLUME 枚举中。
标识符 |
说明 |
值 |
---|---|---|
VOLUME_TICK |
分时报价成交量 |
0 |
VOLUME_REAL |
交易成交量 |
1 |
许多技术指标会对时间序列进行平滑处理(或求平均)。终端支持四种最常见的平滑方法,这些方法在 MQL5 中通过 ENUM_MA_METHOD 枚举的元素来指定。
标识符 |
说明 |
值 |
---|---|---|
MODE_SMA |
简单平均 |
0 |
MODE_EMA |
指数平均 |
1 |
MODE_SMMA |
平滑平均 |
2 |
MODE_LWMA |
线性加权平均 |
3 |
对于 Stochastic 指标(我们将在下一节讨论其示例),有两个计算选项:基于 Close价或基于High/Low 价。这些值在专用枚举 ENUM_STO_PRICE 中提供。
标识符 |
说明 |
值 |
---|---|---|
STO_LOWHIGH |
基于最低价/最高价计算 |
0 |
STO_CLOSECLOSE |
基于收盘价/收盘价计算 |
1 |
对于包含多个缓冲区的指标,其缓冲区用途和编号如下表所示。
指标 |
常量 |
说明 |
值 |
---|---|---|---|
ADX, ADXW |
|||
|
MAIN_LINE |
主线 |
0 |
|
PLUSDI_LINE |
+DI 线 |
1 |
|
MINUSDI_LINE |
-DI 线 |
2 |
iAlligator |
|||
|
GATORJAW_LINE |
颚线 |
0 |
|
GATORTEETH_LINE |
齿线 |
1 |
|
GATORLIPS_LINE |
唇线 |
2 |
iBands |
|||
|
BASE_LINE |
主线 |
0 |
|
UPPER_BAND |
上轨 |
1 |
|
LOWER_BAND |
下轨 |
2 |
iEnvelopes, iFractals |
|||
|
UPPER_LINE |
上轨线 |
0 |
|
LOWER_LINE |
下轨线 |
1 |
iGator |
|||
|
UPPER_HISTOGRAM |
上直方图 |
0 |
|
LOWER_HISTOGRAM |
下直方图 |
2 |
iIchimoku |
|||
|
TENKANSEN_LINE |
Tenkan-sen 线 |
0 |
|
KIJUNSEN_LINE |
Kijun-sen 线 |
1 |
|
SENKOUSPANA_LINE |
Senkou Span A 线 |
2 |
|
SENKOUSPANB_LINE |
Senkou Span B 线 |
3 |
|
CHIKOUSPAN_LINE |
Chikou span 线 |
4 |
iMACD, iRVI, iStochastic |
|||
|
MAIN_LINE |
主线 |
0 |
|
SIGNAL_LINE |
信号线 |
1 |
所有指标的计算公式在 MetaTrader 5 文档中提供。
关于调用指标函数的完整技术信息(包括源代码示例)可以在 MQL5 文档中找到。本书后续将探讨部分相关示例。