ArraySetAsSeries
ArraySetAsSeries
此函数将 AS_SERIES 标志设置为选定的动态数组对象,元素将按时间序列的方式进行索引。
bool ArraySetAsSeries(
const void& array[], // array by reference
bool flag // true denotes reverse order of indexing
);参数
- array[]
[输入][输出] 要设置的数值数组。
- flag
[输入] 数组索引方向。
返回值
成功时函数返回 true,否则返回 - false。
注意
AS_SERIES标志不能用于多维数组或静态数组(在编译阶段大小已预先确定的数组)。时间序列的索引与普通数组不同,时间序列的元素是从末尾向开头索引的(从最新到最旧的数据)。
示例:显示条形图的指标

#property indicator_chart_window
#property indicator_buffers 1
//--- indicator buffers
double NumerationBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,NumerationBuffer,INDICATOR_DATA);
//--- set buffer style
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1,CLR_NONE);
//--- set indexing for the buffer like in timeseries
ArraySetAsSeries(NumerationBuffer,true);
//--- set accuracy of showing in DataWindow
IndicatorSetInteger(INDICATOR_DIGITS,0);
//--- how the name of the indicator arry is displayed in DataWindow
IndicatorShortName("Bar #");
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
//--- we'll store the time of the current zero bar opening
static datetime currentBarTimeOpen=0;
//--- revert access to array time[] - do it like in timeseries
ArraySetAsSeries(time,true);
//--- If time of zero bar differs from the stored one
if(currentBarTimeOpen!=time[0])
{
//--- enumerate all bars from the current to the chart depth
for(int i=rates_total-1;i>=0;i--) NumerationBuffer[i]=i;
currentBarTimeOpen=time[0];
}
//--- return value of prev_calculated for next call
return(rates_total);
}另请参阅
最后更新于