【MQL4】計算の重たいインジケーターの軽量化とは?

全足計算して重たすぎて、MT4落ちるときありますよね?

シンプルですが、このような処理でも簡単に回数は減らせます。

//新しい足が出たら処理
static datetime s_dt = 0;
if(s_dt != iTime(NULL, 0, 0))
{
    s_dt = iTime(NULL, 0, 0);
    //処理内容        
}

//こちらはチャートを開いて、チャートバーをダウンロードして更新した場合に役に立つ
int counted_bar = IndicatorCounted();
if(Bars - counted_bar >= 2 )
{
    //処理内容
}

//指定の期間だけ計算する(毎回)
extern int limit = 1000;//グローバル変数で記述
if(limit >= Bars) limit = Bars - counted_bar -1;
for(int i = 0; i < limit; i++)
{
    //処理内容
}


//王道な書き方
int limit = Bars - IndicatorCounted() -1;
for(int i = 0; i < limit; i++)
{
    //処理内容
}

参考にしてみてください。

では、まただお。

Twitterでフォローしよう

おすすめの記事