//+------------------------------------------------------------------+
//| DRAW_NONE.mq5 |
//| Copyright 2011, MetaQuotes Software Corp. |
//| https://www.MQL5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2011, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots 1
//--- 目に見えないプロット
#property indicator_label1 "Bar Index"
#property indicator_type1 DRAW_NONE
#property indicator_style1 STYLE_SOLID
#property indicator_color1 clrRed
#property indicator_width1 1
//--- 指標バッファ
double InvisibleBuffer[];
//+------------------------------------------------------------------+
//| カスタム指標を初期化する関数 |
//+------------------------------------------------------------------+
int OnInit()
{
//--- 配列と指標バッファを関連付ける
SetIndexBuffer(0,InvisibleBuffer,INDICATOR_DATA);
//--- データウィンドウに表示される値の精度を設定する
IndicatorSetInteger(INDICATOR_DIGITS,0);
//---
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 lastbar=0;
//--- 指標の初めての計算の場合
if(prev_calculated==0)
{
//--- バーの番号を始めて変更
CalcValues(rates_total,close);
//--- lastbar で現在足のオープン時間を保存
lastbar=(datetime)SeriesInfoInteger(_Symbol,_Period,SERIES_LASTBAR_DATE);
}
else
{
//--- 新しいバーが出来た場合、オープン時間が lastbar と異なる
if(lastbar!=SeriesInfoInteger(_Symbol,_Period,SERIES_LASTBAR_DATE))
{
//--- バーの番号をまた変更
CalcValues(rates_total,close);
//--- 現在足のオープン時間を lastbar で更新
lastbar=(datetime)SeriesInfoInteger(_Symbol,_Period,SERIES_LASTBAR_DATE);
}
}
//--- 次の呼び出しのために prev_calculated の値を返す
return(rates_total);
}
//+------------------------------------------------------------------+
//| 時系列のようにバーを番号付け |
//+------------------------------------------------------------------+
void CalcValues(int total,double const &array[])
{
//--- 時系列のように指標バッファの索引付けを設定
ArraySetAsSeries(InvisibleBuffer,true);
//--- それぞれのバーに番号を書き込む
for(int i=0;i<total;i++) InvisibleBuffer[i]=i;
}
|