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