MQL4技术指标函数详解第四篇
MQL4不仅能够计算当前图表中的各类指标,还可以处理任意有效货币对及图表周期的数据。当请求的数据(如货币对名称或图表周期)与当前图表不一致时,若对应图表未在客户端内打开,系统需要从服务器下载所需数据。此时,错误信息ERR_HISTORY_WILL_UPDATED(4066,表示历史数据正在更新中)会被写入last_error变量,此时需要再次发起数据请求(可参考ArrayCopySeries()的示例)。
iAC() – 加速震荡指标
iAD() – 离散指标
iAlligator() – 鳄鱼指标
iADX() – ADX指标
iATR() – ATR指标
iAO() – 动量震荡指标
iBearsPower() – 熊力指标
iBands() – 布林线指标
iBandsOnArray() – 基于数组计算布林线指标
iBullsPower() – 牛力指标
iCCI() – CCI指标
iCCIOnArray() – 基于数组计算CCI指标
iCustom() – 自定义指标
iDeMarker() – DeMarker指标
iEnvelopes() – Envelopes包络线指标
iEnvelopesOnArray() – 基于数组计算包络线指标
iForce() – 强力指标
iFractals() – 分型指标
iGator() – 鳄鱼振荡指标
iIchimoku() – Ichimoku云图指标
iBWMFI() – BWMFI指标
iMomentum() – 动量指标
iMomentumOnArray() – 基于数组计算动量指标
iMFI() – 资金流量指标
iMA() – 移动平均线
iMAOnArray() – 基于数组计算移动平均线
iOsMA() CBCX外汇– OsMA指标
iMACD() – MACD指标
iOBV() – OBV指标
iSAR() – SAR抛物线指标
iRSI() – RSI指标
iRSIOnArray() – 基于数组计算RSI指标
iRVI() – RVI指标
iStdDev() – 标准差指标
iStdDevOnArray() – 基于数组计算标准差
iStochastic() – 随机震荡指标(KDJ)
iWPR() – WPR指标(%R)
iMFI() – 资金流量指标
double iMFI(string symbol, int timeframe, int period, int shift) 用于计算资金流量指标。
参数说明:
symbol – 要计算指标数据的货币对名称,NULL表示当前货币对;timeframe – 时间周期,可为时间周期列表中的任意值,0表示当前图表的时间周期;period – 计算的周期数;shift – 从指标缓冲区中获取值的索引(相对当前柱子向前移动指定数量的偏移量)。示例:
if(iMFI(NULL,0,14,0) < iMFI(NULL,0,14,1)) return(0);
iMA() – 移动平均线
double iMA(string symbol, int timeframe, int period, int ma_shift, int ma_method, int applied_price, int shift) 计算移动平均线。
参数说明:
symbol – 要计算指标数据的货币对名称,NULL表示当前货币对;timeframe – 时间周期,可为时间周期列表中的任意值,0表示当前图表的时间周期;period – MA计算的周期数;ma_shift – MA偏移量;ma_method – MA方法,可为任意移动平均计算方法;applied_price – 应用的价格,可为应用价格枚举中的任意值;shift – 从指标缓冲区中获取值的索引(相对当前柱子向前移动指定数量的偏移量)。示例:
AlligatorJawsBuffer[i]=iMA(NULL,0,13,8,MODE_SMMA,PRICE_MEDIAN,i);
iMAOnArray() – 基于数组计算移动平均线
double iMAOnArray(double array[], int total, int period, int ma_shift, int ma_method, int shift) 基于数值型数组中的数据计算移动平均线。与iMA()不同,该函数不通过货币对名称、图表时段或请求价格获取数据,而是要求价格数据已事先准备好,并从左至右计算。为了能按序列数组方式存取数组元素(即从右到左),需使用ArraySetAsSeries函数。
参数说明:
array[] – 需要计算数据的数组;total – 参与计算的元素个数,0表示使用整个数组;period – MA计算的周期数;ma_shift – MA偏移量;ma_method – MA方法,可为任意移动平均计算方法;shift – 从指标缓冲区中获取值的索引(相对当前柱子向前移动指定数量的偏移量)。示例:
double macurrent=iMAOnArray(ExtBuffer,0,5,0,MODE_LWMA,0); double macurrentslow=iMAOnArray(ExtBuffer,0,10,0,MODE_LWMA,0); double maprev=iMAOnArray(ExtBuffer,0,5,0,MODE_LWMA,1); double maprevslow=iMAOnArray(ExtBuffer,0,10,0,MODE_LWMA,1); //---- if(maprev < macurrentslow && macurrent >= macurrentslow) Alert("穿过");
iOsMA() – OsMA指标
double iOsMA(string symbol, int timeframe, int fast_ema_period, int slow_ema_period, int signal_period, int applied_price, int shift) 计算移动平均震荡指标,在一些系统中显示为MACD直方柱。
参数说明:
symbol – 要计算指标数据的货币对名称,NULL表示当前货币对;timeframe – 时间周期,可为时间周期列表中的任意值,0表示当前图表的时间周期;fast_ema_period – 快速移动平均线计算的周期数;slow_ema_period – 慢速移动平均线计算的周期数;signal_period – 信号线移动平均计算的周期数;applied_price – 应用的价格,可为应用价格枚举中的任意值;shift – 从指标缓冲区中获取值的索引(相对当前柱子向前移动指定数量的偏移量)。示例:
if(iOsMA(NULL,0,12,26,9,PRICE_OPEN,1) < iOsMA(NULL,0,12,26,9,PRICE_OPEN,0)) return(0);
iMACD() – MACD指标
double iMACD(string symbol, int timeframe, int fast_ema_period, int slow_ema_period, int signal_period, int applied_price, int shift) 计算MACD。OsMA被称为MACD直方柱,MACD和OsMA分别显示在不同的窗口。
参数说明:
symbol – 要计算指标数据的货币对名称,NULL表示当前货币对;timeframe – 时间周期,可为时间周期列表中的任意值,0表示当前图表的时间周期;fast_ema_period – 快速移动平均线计算的周期数;slow_ema_period – 慢速移动平均线计算的周期数;signal_period – 信号线移动平均计算的周期数;applied_price – 应用的价格,可为应用价格枚举中的任意值;shift – 从指标缓冲区中获取值的索引(相对当前柱子向前移动指定数量的偏移量)。示例:
if(iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,0) < iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,0)) return(0);
iOBV() – OBV指标
double iOBV(string symbol, int timeframe, int applied_price, int shift) 计算OBV指标(On Balance Volume indicator)。
参数说明:
symbol – 要计算指标数据的货币对名称,NULL表示当前货币对;timeframe – 时间周期,可为时间周期列表中的任意值,0表示当前图表的时间周期;applied_price – 应用的价格,可为应用价格枚举中的任意值;shift – 从指标缓冲区中获取值的索引(相对当前柱子向前移动指定数量的偏移量)。示例:
double val=iOBV(NULL, 0, PRICE_CLOSE, 1);
iSAR() – SAR抛物线指标
double iSAR(string symbol, int timeframe, double step, double maximum, int shift) 计算SAR抛物线指标。
参数说明:
symbol – 要计算指标数据的货币对名称,NULL表示当前货币对;timeframe – 时间周期,可为时间周期列表中的任意值,0表示当前图表的时间周期;step – 步长(增量),通常为0.02;maximum – 最大值,通常为0.2;shift – 从指标缓冲区中获取值的索引(相对当前柱子向前移动指定数量的偏移量)。示例:
if(iSAR(NULL,0,0.02,0.2,0) > Close[0]) return(0);
iRSI() – RSI指标
double iRSI(string symbol, int timeframe, int period, int applied_price, int shift) 计算RSI指标。
参数说明:
symbol – 要计算指标数据的货币对名称,NULL表示当前货币对;timeframe – 时间周期,可为时间周期列表中的任意值,0表示当前图表的时间周期;period – 计算的周期数;applied_price – 应用的价格,可为应用价格枚举中的任意值;shift – 从指标缓冲区中获取值的索引(相对当前柱子向前移动指定数量的偏移量)。示例:
if(iRSI(NULL,0,14,PRICE_CLOSE,0) < iRSI(NULL,0,14,PRICE_CLOSE,1)) return(0);
iRSIOnArray() – 基于数组计算RSI指标
double iRSIOnArray(double array[], int total, int period, int shift) 基于数值型数组中的数据计算RSI。与iRSI()不同,该函数不通过货币对名称、图表时段或请求价格获取数据,而是要求价格数据已事先准备好,并从左至右计算。为了能按序列数组方式存取数组元素(即从右到左),需使用ArraySetAsSeries函数。
参数说明:
array[] – 需要计算数据的数组;total – 参与计算的元素个数,0表示使用整个数组;period – 计算的周期数;shift – 从指标缓冲区中获取值的索引(相对当前柱子向前移动指定数量的偏移量)。示例:
if(iRSIOnArray(ExtBuffer,1000,14,0) < iRSI(NULL,0,14,PRICE_CLOSE,1)) return(0);
iRVI() – RVI指标
double iRVI(string symbol, int timeframe, int period, int mode, int shift) 计算RVI指标。
参数说明:
symbol – 要计算指标数据的货币对名称,NULL表示当前货币对;timeframe – 时间周期,可为时间周期列表中的任意值,0表示当前图表的时间周期;period – 计算的周期数;mode – 指标线的标识符,可为指标线标示符中的对应值;shift – 从指标缓冲区中获取值的索引(相对当前柱子向前移动指定数量的偏移量)。示例:
double val=iRVI(NULL, 0, 10, MODE_MAIN, 0);
iStdDev() – 标准差指标
double iStdDev(string symbol, int timeframe, int ma_period, int ma_shift, int ma_method, int applied_price, int shift) 计算标准差指标。
参数说明:
symbol – 要计算指标数据的货币对名称,NULL表示当前货币对;timeframe – 时间周期,可为时间周期列表中的任意值,0表示当前图表的时间周期;ma_period – MA计算的周期数;ma_shift – MA偏移量;ma_method – MA方法,可为任意移动平均计算方法;applied_price – 应用的价格,可为应用价格枚举中的任意值;shift – 从指标缓冲区中获取值的索引(相对当前柱子向前移动指定数量的偏移量)。示例:
double val=iStdDev(NULL,0,10,0,MODE_EMA,PRICE_CLOSE,0);
iStdDevOnArray() – 基于数组计算标准差
double iStdDevOnArray(double array[], int total, int ma_period, int ma_shift, int ma_method, int shift) 基于数值型数组中的数据计算标准差。与iStdDev()不同,该函数不通过货币对名称、图表时段或请求价格获取数据,而是要求价格数据已事先准备好,并从左至右计算。为了能按序列数组方式存取数组元素(即从右到左),需使用ArraySetAsSeries函数。
参数说明:
array[] – 需要计算数据的数组;total – 参与计算的元素个数,0表示使用整个数组;ma_period – MA计算的周期数;ma_shift – MA偏移量;ma_method – MA方法,可为任意移动平均计算方法;shift – 从指标缓冲区中获取值的索引(相对当前柱子向前移动指定数量的偏移量)。示例:
double val=iStdDevOnArray(ExtBuffer,100,10,0,MODE_EMA,0);
iStochastic() – 随机震荡指标(KDJ)
double iStochastic(string symbol, int timeframe, int %Kperiod, int %Dperiod, int slowing, int method, int price_field, int mode, int shift) 计算随机震荡指标(KDJ指标)。
参数说明:
symbol – 要计算指标数据的货币对名称,NULL表示当前货币对;timeframe – 时间周期,可为时间周期列表中的任意值,0表示当前图表的时间周期;%Kperiod – %K线周期数;%Dperiod – %D线周期数;slowing – 减速值;ma_method – MA方法,可为任意移动平均计算方法;price_field – 价格参数,可为0(Low/High)或1(Close/Close);mode – 指标线的标识符,可为指标线标示符中的对应值;shift – 从指标缓冲区中获取值的索引(相对当前柱子向前移动指定数量的偏移量)。示例:
if(iStochastic(NULL,0,5,3,3,MODE_SMA,0,MODE_MAIN,0) < iStochastic(NULL,0,5,3,3,MODE_SMA,0,MODE_SIGNAL,0)) return(0);
iWPR() – WPR指标(%R)
double iWPR(string symbol, int timeframe, int period, int shift) 计算WPR指标(%R指标)。
参数说明:
symbol – 要计算指标数据的货币对名称,NULL表示当前货币对;timeframe – 时间周期,CBCX外汇可为时间周期列表中的任意值,0表示当前图表的时间周期;period – 计算的周期数;shift – 从指标缓冲区中获取值的索引(相对当前柱子向前移动指定数量的偏移量)。示例:
if(iWPR(NULL,0,14,0) < iWPR(NULL,0,14,1)) return(0);
