初心者の方からの質問 MQL5 MT5 MetaTrader 5 - ページ 1342

 
Vladimir Karputov #:

OnDeinitでObjectsDeleteAllを 行い、接頭辞で削除する(あなたの場合、接頭辞は "HLine "です)。

HLine」は 何行目に書けばいいのでしょうか?

 
Green handsome #:

HLine」は どの行に書けばいいのでしょうか?

何が明確でないのか?

トレーディング、自動売買システム、ストラテジーテストに関するフォーラム

初心者からのFAQ MQL5 MT5 MetaTrader 5

ウラジミール・カルプトフ, 2021.09.10 15:53

OnDeinit でObjectsDeleteAll を行う必要がある -プレフィックスで削除する(あなたの場合、プレフィックスは "HLine" です)

int  ObjectsDeleteAll(
   long           chart_id,   // идентификатор графика
   const string     prefix,   // префикс имени объекта
   int       sub_window=-1,   // индекс окна
   int      object_type=-1    // тип объекта для удаления
   );


 
Vladimir Karputov #:

具体的に何がはっきりしないのでしょうか?


int  ObjectsDeleteAll(
   long           chart_id,   // идентификатор графика
   const string      HLine,   // префикс имени объекта
   int       sub_window=-1,   // индекс окна
   int      object_type=-1    // тип объекта для удаления
   
   );

ここで私はそれをしました、それはまだそれを削除しません。

 
void OnDeinit(const int reason)
  {
     {
      ObjectsDeleteAll(0,prefix,0);
     }
//---
   //ChartRedraw();
  }

接頭辞は,グラフィックラベルの名称を含む。

プリフィックスの意味を知っていますか?

 
Fast235 #:

接頭辞は,グラフィックラベルの名称を含む。

プリフィックスの意味を知っていますか?

MQLは全然知らないんですけど...。2、3行直せばいいと思っていたのに。

 
Green handsome #:

MQLのことは全然わからないんですけど...。2、3行直せばいいと思っていたのに。

上のコードが参考になると思いますが、そうでない場合は、オブジェクトが作成されるときのプレフィックスを見てください。

 

左上の サブウィンドウにショートネームが表示されない理由は何ですか?


また、チャート上に1つのインジケータをロードすると、2つ目のコピーはもう動作しません - OnInit() = 何もトリガーされず、印刷もされません。しかし、"Input parameters "を他のものに変更すると、うまくいきます。

#property indicator_separate_window

#property indicator_plots 0

input int MASlow = 21; // Период медленной МА
input int MAFast = 8;  // Период быстрой МА

//+------------------------------------------------------------------+
string prog_name,short_name;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnInit(void)
{
  prog_name=MQLInfoString(MQL_PROGRAM_NAME);
  short_name="=Set ("+(string)MASlow+"/"+(string)MAFast+")";
  IndicatorSetString(INDICATOR_SHORTNAME,short_name);
  Print("INIT_SUCCEEDED");
  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[])
{
//---

//--- return value of prev_calculated for next call
  return(rates_total);
}

---

mt4ではこのコードは動作するのですが、どう したのでしょうか?

 
Vitaly Muzichenko #:

左上の サブウィンドウにショートネームが表示されない理由は何ですか?


また、チャート上に1つのインジケータをロードすると、2つ目のコピーはもう動作しません - OnInit() = 何もトリガーされず、印刷もされません。しかし、"Input parameters "を他のものに変更すると、うまくいきます。

---

mt4ではこのコードは動作するのですが、どう したのでしょうか?

短すぎるからかな?マッピングもバッファもない...なぜそんなインジケータの2つ目のコピーを作るのか、だから端末が恣意的になってしまう...。

 
Vitaly Muzichenko #:

左上の サブウィンドウにショートネームが表示されない理由は何ですか?


また、チャート上に1つのインジケータをロードすると、2つ目のコピーはもう動作しません - OnInit() = 何もトリガーされず、印刷もされません。しかし、"Input parameters "を他のものに変更すると、うまくいきます。

---

このコードはmt4で動作するのですが、何がいけない のでしょうか?

私も悩みましたが、インジケータを作り、すべてOKです。

#property copyright "Copyright 2021, IgorM"
#property link      "https://www.mql5.com/ru/users/igorm"
#property version   "1.00"
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots   1
//--- plot Label1
#property indicator_label1  "Label1"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrRed
#property indicator_style1  STYLE_SOLID
#property indicator_width1  2
//--- indicator buffers
double         Label1Buffer[];
input int MASlow = 21; // Период медленной МА
input int MAFast = 8;  // Период быстрой МА
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
   string short_name = MQLInfoString(MQL_PROGRAM_NAME) + "=Set (" + (string)MASlow + "/" + (string)MAFast + ")";
   IndicatorSetString(INDICATOR_SHORTNAME, short_name);
   SetIndexBuffer(0, Label1Buffer, INDICATOR_DATA);
//---
   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[])
{
   for(int i = prev_calculated == 0 ? 0 : prev_calculated - 1; i < rates_total; i++)
   {
      Label1Buffer[i] = close[i];
   }
   return(rates_total);
}
//+------------------------------------------------------------------+

いつサブウィンドウにインジケータの名前を書かなくなるのか、コメントアウトして調べてみようかな.しかし、それは怠慢である。

 
Igor Makanu #:

何かが欠けている - おそらくいくつかの種類のプロパティは、また、これに直面しているが、ここで私は、インジケータをスケッチしている、すべてがOKです。

サブウィンドウにインジケータ名を書き込まなくなったときを探すようにコメントすると怠け者だけど

データは表示されますが、OnInit()関数が動作していない場合、どこから表示されるのでしょうか?チャート上にコピーを投げ、たまたまOnInit()が発動することがありますが、別のコピーであれば、それだけでプリントすらありません。しかし、入力パラメータを変更すれば、うまくいくのです。

#property copyright "Copyright 2021, IgorM"
#property link      "https://www.mql5.com/ru/users/igorm"
#property version   "1.00"
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots   1
//--- plot Label1
#property indicator_label1  "Label1"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrRed
#property indicator_style1  STYLE_SOLID
#property indicator_width1  2


input int MASlow = 21; // Период медленной МА
input int MAFast = 8;  // Период быстрой МА

//+------------------------------------------------------------------+
int wndNum;
string short_name;
double Label1Buffer[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
{
  short_name="Set ("+(string)MASlow+"/"+(string)MAFast+")";
  IndicatorSetString(INDICATOR_SHORTNAME,short_name);
  wndNum=ChartWindowFind();
  Print("INIT SUCCEEDED: "+(string)wndNum);
  SetIndexBuffer(0, Label1Buffer, INDICATOR_DATA);
//---
  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[])
{
   for(int i = prev_calculated == 0 ? 0 : prev_calculated - 1; i < rates_total; i++)
   {
      Label1Buffer[i] = close[i];
   }
   return(rates_total);
}

---

なぜOnInitが 動作しないのか、その解決策は?

理由: