ソースコード完成例
各処理の説明
■プロパティの設定
①#property indicator_separate_window
②#property indicator_buffers 1
③#property indicator_color1 Blue
④#property indicator_style1 STYLE_SOLID
⑤#property indicator_width1 3
①#property indicator_separate_window
インジゲータをサブウインドウに表示する。
②#property indicator_buffers 1
インジゲータのバッファを格納する。
③#property indicator_color1 Blue
インジゲータの色を指定する。今回は青(Blue)を使用。
④#property indicator_style1 STYLE_SOLID
インジゲータのラインの種類を指定する。今回は実線を使用。
⑤#property indicator_width1 3
インジゲータのラインの太さ(幅)を指定する。今回は3を使用。
■変数の設定
①double BufCCI[];
①double BufCCI[];
double型の変数を指定。ここでは、BufCCIという配列を指定。
■初期化関数の設定
int init(){
①SetIndexBuffer(0,BufCCI);
return(0);
}
①SetIndexBuffer(0,BufCCI);
インジケーターバッファーをインジケーターバッファー領域に割り当てる。
ここでは、0番目のインデックスを指定し、BufCCIという配列を指定。
■指標計算関数の設定
int start()
{
① int limit = Bars-IndicatorCounted();
②for(int i=0; i < limit; i++)
{
③ BufCCI[i] = iCCI(NULL,0,20,0,i);
}
return(0);
}
①int limit = Bars-IndicatorCounted();
int型の変数limitにBars-IndicatorCounted()を代入。
Barsは、
表示されているバーの本数を格納しているint型の変数。
IndicatorCounted()は、インジケーターの確定値が計算されたバー(現在のバー以外)の本数を取得する関数。
②for(int i=0; i<limit; i++){ }
for文。
③BufCCI[i] = iCCI(NULL,0,20,0,i);
配列BufCCIにiCCIの値を代入。
ここでは、現在のチャートの通貨ペア、時間足、期間20、終値、現在の足を指定。