ArrayGetAsSeries

配列の索引付けの方向をチェックします。

bool  ArrayGetAsSeries(
  const void&  array[]   // チェックされる配列
  );

パラメータ

array

[in]  チェックされた配列

戻り値

指定された配列にAS_SERIESフラグが設定され、すなわち配列へのアクセスは、時系列のように前後反対に行われる場合 trueを返します。時系列と通常の配列の違いは、時系列のインデックスが後ろから前へ(最新のデータから古いデータへ)つけられていることです。

注意事項

配列が時系列であるかどうかをチェックするには ArrayIsSeries() 関数を使用します。OnCalculate() 関数に入力パラメータとして渡された価格データの配列は時系列と同じインデックス方向を持っていません。必要なインデックス方向は ArraySetAsSeries() 関数を使用して設定出来ます。

例:

#property description "Indicator calculates absolute values of the difference between"
#property description "Open and Close or High and Low prices displaying them in a separate subwindow"
#property description "as a histrogram."
//--- 指標の設定
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots   1
//---- プロット
#property indicator_type1   DRAW_HISTOGRAM
#property indicator_style1 STYLE_SOLID
#property indicator_width1  3
//--- 入力パラメータ
input bool InpAsSeries=true; // 指標バッファでの索引付けの方向
input bool InpPrices=true;   // 計算価格(true - 始/終、false - 高/低)
//--- 指標バッファ
double ExtBuffer[];
//+------------------------------------------------------------------+
//| 指標値の計算                                                       |
//+------------------------------------------------------------------+
void CandleSizeOnBuffer(const int rates_total,const int prev_calculated,
                      const double &first[],const double &second[],double &buffer[])
 {
//--- バーを計算する start 変数
  int start=prev_calculated;
//--- 指標値が前のティックで計算されている場合には最後のバーを使用する
  if(prev_calculated>0)
     start--;
//--- 配列の索引付けの方向を定義する
  bool as_series_first=ArrayGetAsSeries(first);
  bool as_series_second=ArrayGetAsSeries(second);
  bool as_series_buffer=ArrayGetAsSeries(buffer);
//--- 必要に応じて、索引付け方向を直接なものにする
  if(as_series_first)
    ArraySetAsSeries(first,false);
  if(as_series_second)
    ArraySetAsSeries(second,false);
  if(as_series_buffer)
    ArraySetAsSeries(buffer,false);
//--- 指標値を計算する
  for(int i=start;i<rates_total;i++)
     buffer[i]=MathAbs(first[i]-second[i]);
 }
//+------------------------------------------------------------------+
//| カスタム指標を初期化する関数                                            |
//+------------------------------------------------------------------+
int OnInit()
 {
//--- 指標バッファを結合する
  SetIndexBuffer(0,ExtBuffer);
//--- 指標バッファのインデックス要素を設定する
  ArraySetAsSeries(ExtBuffer,InpAsSeries);
//--- 指標が計算されている価格をチェックする
  if(InpPrices)
    {
    //--- 価格を開け閉めする
    PlotIndexSetString(0,PLOT_LABEL,"BodySize");
    //--- 指標の色を設定する
    PlotIndexSetInteger(0,PLOT_LINE_COLOR,clrOrange);
    }
  else
    {
    //--- 高値と安値
    PlotIndexSetString(0,PLOT_LABEL,"ShadowSize");
    //--- 指標の色を設定する
    PlotIndexSetInteger(0,PLOT_LINE_COLOR,clrDodgerBlue);
    }
//---
  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[])
 {
//---フラグの値に応じた指標を計算する
  if(InpPrices)
     CandleSizeOnBuffer(rates_total,prev_calculated,open,close,ExtBuffer);
  else
     CandleSizeOnBuffer(rates_total,prev_calculated,high,low,ExtBuffer);
//--- 次の呼び出しのために prev_calculated の値を返す
  return(rates_total);
 }

参照

時系列へのアクセスArraySetAsSeries