MT4におけるチャートIDについて

MetaTrader 4
GogoJungle
2019/08/02 20:31
3157

チャートIDとは、MT4のチャート毎に割り振られた数字です。
MT4のプログラムは基本的に稼働中のチャートでの動作しますが、
チャートIDを指定することで他のチャートへオブジェクトを表示したり、
テンプレートを適用するといった操作が可能となります。

MT4に表示中の全チャートのチャートIDを取得するには、ChartFirst関数とChartNext関数を使用します。

long ChartFirst();

long ChartNext(
   long chart_id
);

ChartFirst関数はMT4で表示中のチャートで一番最初に表示されたチャートのチャートIDを返します。

ChartNext関数は引数のchart_idでチャートIDを指定すると、
引数に指定したチャートの次に表示されたチャートのチャートIDを返します。
例えば以下のコードは2番目に表示されたチャートのチャートIDを取得できます。

long second = ChartNext(ChartFirst());

次に開かれたチャートが存在しない場合は、ChartNext関数の結果は-1となります。

以下は全てのチャートのチャートIDを取得するサンプルです。
ChartSymbol関数とChartPeriod関数を利用して、MT4に表示中の全チャートの通貨ペア名、時間足、チャートIDを表示します。

#property copyright "Copyright 2016, gogojungle"
#property link      "http://labo.fx-on.com"
#property version   "1.00"
#property strict
#property indicator_chart_window

int OnInit(){
   string comment = "";
   long   id      = ChartFirst();
   
   comment  = ChartSymbol(ChartFirst()) + " : ";
   comment += IntegerToString(ChartPeriod(ChartFirst())) + " : ";
   comment += IntegerToString(ChartFirst()) + "¥n";
   
   while(ChartNext(id) >= 0){
      id = ChartNext(id);
      
      comment += ChartSymbol(id) + " : ";
      comment += IntegerToString(ChartPeriod(id)) + " : ";
      comment += IntegerToString(id) + "¥n";
   }
   
   Comment(comment);

   return(INIT_SUCCEEDED);
}

void OnDeinit(const int reason){
   Comment("");
}

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[])
  {
   return(rates_total);
}

コメント

関連トピックス

検索結果がありません。

ノーコードで誰でも簡単EA開発!MQL言語学習にも使える! | GogoJungle

注目トピックス

検索結果がありません。