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