エラー、バグ、質問 - ページ 3148

 
Roman #:

それは、IndBuffがrates_total + 1
に割り当てられていないためで、ArrayResizeは 適用できない。
彼らは構築のために壊したのです。もうif-arsesを使うしかないのでしょうか?

for(int i=limit - 1;....

せめて

 
Roman #:

これは、IndBuffがrates_total + 1
に割り当てられておらず、ArrayResizeが 適用できないためである。


ここでマイナス1が必要になります :))
プリントアウトすると、寸法に問題がないことがわかります。
ロジックを使う。
limit = 0 ならば、新しいティックとなります。
limit = 1の場合、新しいバーを意味します(rates_totalバッファの最後の要素は-1であり、rates_totalがあります - したがって、オーバーフローが発生します)。
limit > 1の場合、インジケータ全体を再計算した方が良い
 
Maxim Kuznetsov #:

for(int i=limit - 1;....

せめて

何が一番迷惑かわかる?どんな行動も、何の前触れもなく黙ってごまかされること。
そして、人が傷つくのです。このメタトレーダーにはうんざりです。

 
Roman #:

何が一番迷惑かわかる?どんな行動も、何の前触れもなく黙ってごまかされること。
そして、人が傷つくのです。このメタトレーダーにはうんざりです。

すべてが以前のままです。
あなたのせいです。
ヒント - デバッガの使い方を覚えれば、校正をする必要がなく、自分の欠点を一度に見ることができます。
 
Roman #:

何が一番迷惑かわかる?どんな行動も、何の前触れもなく黙ってごまかされること。
そして、人が傷つくのです。このメタトレーダーにはうんざりです。

指標の計算方法については、特に変化は感じられません。上にあるように、Nikolayはrate_total-prev_calculatedとして計算された限界値が何を意味するのかを正しく説明しています。

そして、それは第4ターミナル以来、何年も機能しています。

 
Nikolai Semko #:
ここでマイナス1が必要になります :))
プリントアウトすると、寸法に問題がないことがわかります。
ロジックを使う。
limit = 0 の場合、新しいティック
limit = 1の場合、新しいバーを意味します(rates_totalバッファの最後の要素は-1であり、rates_totalがあるため、オーバーフローが発生します)。
limit > 1の場合、インジケータ全体を再計算した方が良い

ニコライ 私はifとfor oneの構文を知っています。
でも、いつもforで作業していました。慣れてしまって、その方が便利なんです。
でも、ずっと前からforでおかしいと気づいていて、解明するのを先延ばしにしていたんです。
以前は正常に動作していた

for i>=0 ticks
for i>0 bars

そして、もしもは必要なかった。

 
Roman #:



ステップ1:「MQL5 Wizard」を使ってテンプレートを作成します。

//+------------------------------------------------------------------+
//|                                                       Simple.mq5 |
//|                              Copyright © 2022, Vladimir Karputov |
//|                      https://www.mql5.com/en/users/barabashkakvn |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2022, Vladimir Karputov"
#property link      "https://www.mql5.com/en/users/barabashkakvn"
#property version   "1.00"
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots   1
//--- plot Close
#property indicator_label1  "Close"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrRed
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- input parameters
input int      Input1=9;
//--- indicator buffers
double         CloseBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,CloseBuffer,INDICATOR_DATA);
   
//---
   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);
  }
//+------------------------------------------------------------------+


ステップ2:'limit'のスペルを正しく入力し、close配列を使用 する - iCloseコールではありません!

//+------------------------------------------------------------------+
//|                                                       Simple.mq5 |
//|                              Copyright © 2022, Vladimir Karputov |
//|                      https://www.mql5.com/en/users/barabashkakvn |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2022, Vladimir Karputov"
#property link      "https://www.mql5.com/en/users/barabashkakvn"
#property version   "1.00"
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots   1
//--- plot Close
#property indicator_label1  "Close"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrRed
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- input parameters
input int      Input1=9;
//--- indicator buffers
double         CloseBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,CloseBuffer,INDICATOR_DATA);
//---
   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=prev_calculated-1;
   if(prev_calculated==0)
      limit=0;
   for(int i=limit; i<rates_total; i++)
     {
      CloseBuffer[i]=close[i];
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+


結果

そして、エラーもない。

ファイル:
Simple.mq5  5 kb
 
Vladimir Karputov #:

ステップ1:「MQL5 Wizard」を使ってテンプレートを作成します。


ステップ2:'limit'のスペルは正しく、close配列を使用 する - iCloseコールではない!!!


結果

で、エラーはありません。

もちろん、直接的なi++の例もありがとうございます。
しかし、私が逆ループを持っていることに、あなたは気づいていない。
また、iCloseを例に挙げるなら、その後にiインデックスが他の関数で使用されることを示すために使用しなければならない。

 
Roman #:

ニコライ ifとfor oneの構文は知っています。

でなければ

ニコライ・セムコ#:
ロジックを使う。
limit = 0 の場合、新しいティック
limit = 1の場合、新しいバーを意味します(rates_totalバッファの最後の要素は-1であり、rates_totalがあるため、オーバーフローが発生します)。
limit > 1の 場合、インジケータ全体を再計算した方が良い。

これは
が間違っているところです。limit != 1 ならば
を使うのがよいでしょう。

だから、全体のロジックはだいたいそうなっている。

limit = rates_total - prev_calculated;
if (limit == 0) {..} // новый тик
else if ( limit == 1) {..} // новый бар
else {..} // полный пересчет всего индикатора
limit == 2ならなんで全部再計算しないといけないんだ、と憤慨される方もいらっしゃるかと思いますが、
limitが1にも0にもならない場合は、インジケータの最初の初期化であるか、何か問題が発生した(例えば接続障害やサーバ障害)ことを意味します
さらに、prev_calculatedがrates_totalより高い状況に何度も出くわしたことがあります。おそらく、以前は何らかの不具合があり、現在は修正されているのでしょうが、それ以来、安全対策としてこのデザインを使用しています。
 
Nikolai Semko #:

if limit != 1

ゼロを下回ることができるのか?