価格定数

テクニカル指標の計算には、価格値及び/または計算が実行されたボリュームの値が必要です。計算に使用する価格ベースを指定するための ENUM_APPLIED_PRICE 列挙には 7 つの事前定義された識別子があります。

ENUM_APPLIED_PRICE

ID

説明

PRICE_CLOSE

終値。

PRICE_OPEN

始値。

PRICE_HIGH

期間の高値。

PRICE_LOW

期間の安値。

PRICE_MEDIAN

中間価格(高 + 低)÷  2 。

PRICE_TYPICAL

典型的価格(高 + 低 + 終)÷  3 。

PRICE_WEIGHTED

平均価格(高 + 低 + 終 + 終)÷  4 。

ボリュームが計算に使用された場合、ENUM_APPLIED_VOLUME 列挙の 2 つの値のいずれかを指定する必要があります。

ENUM_APPLIED_VOLUME

ID

説明

VOLUME_TICK

ティックボリューム。

VOLUME_REAL

取引高。

iStochastic() テクニカル指標の計算法は 2 つあります。

  • 終値のみ
  • 高値と安値

計算に必要なバージョンを選択するには、ENUM_STO_PRICE 列挙体の値のいずれかを指定します。

ENUM_STO_PRICE

ID

説明

STO_LOWHIGH

計算は、低/高価格に基づいています。

STO_CLOSECLOSE

計算は、クローズ(ローソク足の形成が終わった時点での価格)/終値に基づいています。

テクニカル指標が ENUM_APPLIED_PRICE によって設定されている種類の価格データを計算に使用する場合、(端末機に内蔵あるいはユーザに書かれた)指標ハンドルが入力価格シリーズとして使用可能になります。この場合には、指標のゼロバッファの値が計算に使用されます。これは、他の指標の値を使用しての指標値の構築を容易にします。カスタム指標ハンドルは iCustom() 関数の呼び出しで作成されます。

例:

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_plots   2
//--- 入力パラメータ
input int      RSIperiod=14;         // RSI を計算するための期間
input int      Smooth=8;             // 平滑化期間 RSI
input ENUM_MA_METHOD meth=MODE_SMMA; // 平滑化の方法
//---- RSI をプロットする
#property indicator_label1 "RSI"
#property indicator_type1   DRAW_LINE
#property indicator_color1 clrRed
#property indicator_style1 STYLE_SOLID
#property indicator_width1  1
//---- RSI_Smoothed をプロットする
#property indicator_label2 "RSI_Smoothed"
#property indicator_type2   DRAW_LINE
#property indicator_color2 clrNavy
#property indicator_style2 STYLE_SOLID
#property indicator_width2  1
//--- 指標バッファ
double         RSIBuffer[];         // RSI 値を収納
double         RSI_SmoothedBuffer[]; // スムーズにされたRSI 値
int            RSIhandle;           // RSI 指標ハンドル
//+------------------------------------------------------------------+
//| カスタム指標を初期化する関数                                            |
//+------------------------------------------------------------------+
void OnInit()
 {
//--- 指標バッファマッピング
  SetIndexBuffer(0,RSIBuffer,INDICATOR_DATA);
  SetIndexBuffer(1,RSI_SmoothedBuffer,INDICATOR_DATA);
  IndicatorSetString(INDICATOR_SHORTNAME,"iRSI");
  IndicatorSetInteger(INDICATOR_DIGITS,2);
//---
  RSIhandle=iRSI(NULL,0,RSIperiod,PRICE_CLOSE);
//---
 }
//+------------------------------------------------------------------+
//| カスタム指標の反復関数                                                |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const int begin,
                const double &price[]
                )
 
 {
//---  直近エラーの値をリセットする
  ResetLastError();
//--- RSIBuffer[] 配列でRSIの指標データを取得する
  int copied=CopyBuffer(RSIhandle,0,0,rates_total,RSIBuffer);
  if(copied<=0)
    {
    Print("Unable to copy the values of the indicator RSI. Error = ",
          GetLastError(),",  copied =",copied);
    return(0);
    }
//--- RSI 値を用いて平均値の指標を作成する
  int RSI_MA_handle=iMA(NULL,0,Smooth,0,meth,RSIhandle);
  copied=CopyBuffer(RSI_MA_handle,0,0,rates_total,RSI_SmoothedBuffer);
  if(copied<=0)
    {
    Print("Unable to copy the smoothed indicator of RSI. Error = ",
          GetLastError(),",  copied =",copied);
    return(0);
    }
//--- 次の呼び出しのために prev_calculated の値を返す
  return(rates_total);
 }