見出し画像

【MQL】N本連続陽線で矢印を表示

N本連続で陽線が発生すると矢印を表示するプログラムを作成しました。

input変数を使用することにより外部から陽線連続本数を指定できるようにしました。ただし、0以下の整数を入れた場合のエラーは考慮していません…

//・・・・・・・・・・・・・・・・・・・・・・・・・・・
//N本連続陽線で矢印を表示(確定足で判断する場合)
//・・・・・・・・・・・・・・・・・・・・・・・・・・・

#property version   "1.00"
#property strict

#property indicator_chart_window
#property indicator_buffers 1

#property indicator_color1 clrRed
#property indicator_width1 2

double BarsUp[];
input int bars = 5;  //陽線の連続回数

int OnInit()
{
 SetIndexBuffer(0, BarsUp);
 SetIndexStyle(0, DRAW_ARROW, STYLE_SOLID);
 SetIndexArrow(0, SYMBOL_ARROWUP);
 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[]        )
{
 int limit = rates_total - prev_calculated;
 int n = bars-1;                  //array out of range対処
 if(limit > 1)                    //初期状態(インジケータ挿入直後)の場合のlimit定義
 {
    limit = rates_total -n -1;
 }
 
 for(int i=limit; i>=1; i --)     //足が更新されていない場合は、rates_total - prev_calculated = 0 となるので何もしない。
 {
    int count = 0;
    for(int j = 1; j<=bars; j++)
    {
        if(open[j+i-1] < close[j+i-1])
        {
           count = count + 1;
        }
        
        if(count == bars)
        {
           BarsUp[i] = high[i] + 20*Point;
        }
    }
 }
 return(rates_total);
}


【実行結果】

陽線連続本数を5本とした場合は以下のとおりです。


この記事が気に入ったらサポートをしてみませんか?