#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots 1
//---- プロット記数
#property indicator_label1 "Numeration"
#property indicator_type1 DRAW_LINE
#property indicator_color1 CLR_NONE
//--- 指標バッファ
double NumerationBuffer[];
//+------------------------------------------------------------------+
//| カスタム指標を初期化する関数 |
//+------------------------------------------------------------------+
int OnInit()
{
//--- 指標バッファマッピング
SetIndexBuffer(0,NumerationBuffer,INDICATOR_DATA);
//--- バッファのインデックスを時系列式に付ける
ArraySetAsSeries(NumerationBuffer,true);
//--- データウィンドウに表示する精度を設定する
IndicatorSetInteger(INDICATOR_DIGITS,0);
//--- 指標配列の名称の データウィンドウでの表示の仕方
PlotIndexSetString(0,PLOT_LABEL,"Bar #");
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| カスタム指標の反復関数 |
//+------------------------------------------------------------------+
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[])
{
//--- 現在のゼロバー開口部の時間を保存する
static datetime currentBarTimeOpen=0;
//--- time[] 配列へのアクセスを元に返す - 時系列のようにアクセスする
ArraySetAsSeries(time,true);
//--- ゼロバーの時間が格納されているものと異なる場合
if(currentBarTimeOpen!=time[0])
{
//--- 現在からチャートの深さまで全てのバーを列挙する
for(int i=rates_total-1;i>=0;i--) NumerationBuffer[i]=i;
currentBarTimeOpen=time[0];
}
//--- 次の呼び出しのために prev_calculated の値を返す
return(rates_total);
}
|