MQL Parts

 MQL のプログラミングに役立つパーツを集めたページです。

「 ロウソク1本にアラート1回 」の設定方法

最新バーの時刻を比較する方法

static datetime lastBar ;

datatime curBar = Time[0];

if(lastBar != curBar)

  {

  lastBar = curBar;

  Alert(alert_msg);

  PlaySound("alert");

}

 

バーの総数を比較する方法

static int allBarNum = 0;

if(allBarNum == 0 || allBarNum < Bars)

  {

  allBarNum=Bars;

  Alert(alert_msg);

  PlaySound("alert");

  }

IndicatorBuffers(max 8) の節約

 MT4 の神 fai さんが紹介されていた方法です。とても役にたつので、すぐに引用できるよう、このページに転載しました。

  //---< alternative buffer >---

  ArrayResize(FastMA, Bars);

  ArrayResize(SlowMA, Bars);

 

  int diff=Bars-IndicatorCounted();

  if(diff>1 && IndicatorCounted()!=0)

    {

    for(int buffCnt=Bars-diff-1; buffCnt>=0; buffCnt--)

      {

      FastMA[buffCnt+diff-1]=FastMA[buffCnt];

      SlowMA[buffCnt+diff-1]=SlowMA[buffCnt];

      }

    }

  //---

maMethod と appliedPrice

 パラメーターの解説で使うネタ
 0=SMA, 1=EMA, 2=SMMA, 3=LWMA
 0=Close, 1=Open, 2=High, 3=Low, 4=(H+L)/2, 5=(H+L+C)/3, 6=(H+L+C+C)/4
 0=実線, 1=破線, 2=点線, 3=一点鎖線, 4=二点鎖線
← true : MA の値を表示、false : 非表示
← true : BBands 表示、false : 非表示
← true : 画面右上にロウソク完成までの時間を表示、false : 非表示

チャート上のドット

#property indicator_width1 4

 

int init()

  {

  int buffNum=0;

    SetIndexLabel (buffNum, NULL);

    SetIndexBuffer(buffNum, dotBuff);

    SetIndexStyle  (buffNum, DRAW_ARROW, EMPTY);

    SetIndexArrow(buffNum, 158);

    SetIndexDrawBegin(buffNum, draw_begin);

 

  return(0);

  }

while 的 for ループ

 ループ回数がわかっている場合は、

for(barCnt=limit; barCnt>=0; barCnt--)

  {

  処理

  }

というループを使いますが、

回数が不明で条件を満たした時にループを終了させる場合には、

while(k<n)

  {

   y=y*x;

   k++;

  }

というループを使います。

 

下に挙げたループは、for ループを while 的に使ったループです。ちょっと感動しました。

int init()

  {

  int x;

  string bekijo="";

  for(;;)

    {

    bekijo=bekijo+x+"^2 = "+DoubleToStr(MathPow(x, 2), 0)+"\n";

    x++;

    if(MathPow(x, 2)>100) break;

    }

  Comment(bekijo);

  return(0);

  }

サブメニュー

Mql Parts