int _AppliedTo
_AppliedTo变量可以找出用于指标计算的数据类型:
| 数据类型 | 含义 | 用于指标计算的数据描述。 |
|---|---|---|
| — | 0 | 这个指标使用第二个OnCalculate()调用表格 - 计算的数据不由某个缓冲区或数据数组指定 |
| 关闭 | 1 | 收盘价 |
| 打开 | 2 | 开盘价 |
| 高级别 | 3 | 最高价 |
| 低级别 | 4 | 最低价 |
| 中间价(HL/2) | 5 | 中间价 = (High+Low)/2 |
| 典型价格(HLC/3) | 6 | 典型价格 = (High+Low+Close)/3 |
| 加权价格(HLCC/4) | 7 | 加权价格= (Open+High+Low+Close)/4 |
| 之前指标数据 | 8 | 该指标之前,图表上启用的指标数据。 |
| 第一个指标数据 | 9 | 图表上最先启用的指标数据 |
| 指标句柄 | 10+ | 使用指标句柄传递到iCustom()函数的指标数据。_AppliedTo值包含指标句柄 |
例如:
//+------------------------------------------------------------------+
//| 自定义指标初始化函数 |
//+------------------------------------------------------------------+
int OnInit()
{
//--- 指标缓冲映射
SetIndexBuffer(0,Label1Buffer,INDICATOR_DATA);
// 获得用于指标计算的数据类型
Print("_AppliedTo=",_AppliedTo);
Print(getIndicatorDataDescription(_AppliedTo));
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| 用于指标计算的数据描述 |
//+------------------------------------------------------------------+
string getIndicatorDataDescription(int data_id)
{
string descr="";
switch(data_id)
{
case(0):descr="It's first type of OnCalculate() - no data buffer";
break;
case(1):descr="Indicator calculates on Close price";
break;
case(2):descr="Indicator calculates on Open price";
break;
case(3):descr="Indicator calculates on High price";
break;
case(4):descr="Indicator calculates on Low price";
break;
case(5):descr="Indicator calculates on Median Price (HL/2)";
break;
case(6):descr="Indicator calculates on Typical Price (HLC/3)";
break;
case(7):descr="Indicator calculates on Weighted Price (HLCC/4)";
break;
case(8):descr="Indicator calculates Previous Indicator's data";
break;
case(9):descr="Indicator calculates on First Indicator's data";
break;
default: descr="Indicator calculates on data of indicator with handle="+string(data_id);
break;
}
//---
return descr;
}