High hopes

  1. FX
  2. 626 view

移動平均線のMTF化

移動平均線は裁量のfxするなら必須のテクニカルだと思います。
また環境認識では上位足を見るのも必須、その時にMTF(マルチタイムライン)の移動平均線は非常に役立ちます。
現在の時間足に上位足の移動平均線を表示すればチャートを切り替えなくても大体の環境認識が出来ます。
mtfの移動平均線のインジケーター沢山出回っていますし、少しMQL4の知識があれば簡単にインジケーター作成できます。
下記に一般的だと思いますが、僕が作ったコード全文を載せています。

//+------------------------------------------------------------------+
//|                                                       mtf_ma.mq4 |
//|                                         Copyright 2020, be-kind. |
//|                                      http://be-kind.okanasen.jp/ |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, be-kind."
#property link      "http://be-kind.okanasen.jp/"
#property version   "1.00"
#property strict

// プログラムの説明
#property description "移動平均線のmtf化"

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots   1
//--- plot Label1
#property indicator_label1  "mtf_ma"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrGold
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1

//--- indicator buffers
double         buffer[];

input int mtf = 60;//MTFの時間足
input int period = 20;//移動平均線の期間
input ENUM_MA_METHOD mode=MODE_EMA; //移動平均線の種類
int mtf_s;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   IndicatorBuffers(1); 
   SetIndexBuffer(0,buffer);
   mtf_s = mtf;
   if(mtf_s < _Period )mtf_s = _Period;
   IndicatorShortName("mtf_ma : 期間:" + string(period) + "  時間足:" + string(mtf_s) + "分");   
   
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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; //プロットするバーの数 
      //次のmtfの時間足までのロウソク足の数
      int limit_mtf = iBarShift(NULL, _Period, iTime(NULL, mtf_s, 0));
      for(int i=0; i<MathMax(limit_mtf, limit); i++)
      {
         int z = iBarShift(NULL,mtf_s,Time[i]);
         buffer[i] = iMA(NULL, mtf_s, period, 0, mode, PRICE_CLOSE, z);
      }
   
   
//--- return value of prev_calculated for next call
   return(rates_total-1);
}



ただ上記インジケーターや出回っているmtf_maのインジケーターを使っていると初めての通貨ペアの4時間足以上などの時間足でうまく表示出来ない不具合があります。更新すればちゃんと動くようにはなります。
この不具合は、(MQL5 iTime リファレンスから抜粋)
------------------------------------
最初の関数呼び出し中に準備のできたデータが存在しない場合、結果を準備するのに時間がかかることを意味します。
------------------------------------
上記が理由だと思います。たぶん??

何とか上記不具合解消できないかとゆるりと試行錯誤始めて完成致しました。
近々DL出来るようにしてみますので、良かったら使ってみて下さい。

FXの最近記事

  1. 価格の流れの正常性と勢いを見極める

  2. 保護中: プライベート投稿

  3. Total_Method_CSet アップデートV6

  4. Break_Back

  5. Total_Method_CSet アップデート

関連記事

コメント

  1. この記事へのコメントはありません。

  1. この記事へのトラックバックはありません。

PAGE TOP