Errors, bugs, questions - page 561

 

ArrayInitialize does not work code is attached, if we uncomment the loop, everything is fine.

And when declaring variables in class and indicator on global level with the same name - warning pops up.

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_plots   2
//--- plot Line1
#property indicator_label1  "Line1"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrRed
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- plot Line2
#property indicator_label2  "Line2"
#property indicator_type2   DRAW_LINE
#property indicator_color2  clrBlue
#property indicator_style2  STYLE_SOLID
#property indicator_width2  1
//--- indicator buffers
double         Line1Buffer[];
double         Line2Buffer[];
//+------------------------------------------------------------------+
int OnInit()
  {
   SetIndexBuffer(0,Line1Buffer,INDICATOR_DATA);
   SetIndexBuffer(1,Line2Buffer,INDICATOR_DATA);
   ArraySetAsSeries(Line1Buffer,true) ;
   ArraySetAsSeries(Line2Buffer,true) ;
   ArrayInitialize(Line1Buffer,EMPTY_VALUE) ;
   ArrayInitialize(Line2Buffer,EMPTY_VALUE);
   return(0);
  }
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const int begin,
                const double &price[])
  {
      ArraySetAsSeries(price,true) ;
      int i ;
     /* for(i=0; i<rates_total;i++)
         {
            Line1Buffer[i]=EMPTY_VALUE;
            Line2Buffer[i]=EMPTY_VALUE ;
         }*/
      for(i=0;i<100;i++)
         {
            Line1Buffer[i]=price[i] ;
         }
   return(rates_total);
  }
//+------------------------------------------------------------------+
 

Over the weekend, while there were no ticks, I debugged the indicator on demo accounts, running it on the last build of two instances of MT5 terminal, but from different companies: MetaQuotes and EGlobal. Settings are the same everywhere. To be sure I checked it off-line, so the tick factor is excluded.

The problem is that the simplest code of the "underindicator" (not to mention the full-fledged and more complex indicator) displays a different number of results in different terminals of different companies:

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots   1

double Buffer[];
int handle;

int OnInit()
  {
   SetIndexBuffer(0,Buffer,INDICATOR_DATA);

   handle=iFractals(_Symbol,PERIOD_CURRENT);
   if(handle==INVALID_HANDLE) return(-1);

   return(0);
  }

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[])
  {
   Print(1);

   return(rates_total);
  }

1. EGlobal. 2. MetaQuotes.EGlobalMetaQuotes

I completely unloaded both terminals (checked with Task Manager by memory processes), loaded them again and recompiled both codes just in case. In the end - no changes.

 
It's not surprising, that's the way it should be.
 

MathRound() works differently in 4 and 5, and should be the same.

4p's code:

int start()
{
  double minlot=0.01;
  double step  =0.01;
  Print(minlot+step*MathRound((0.005 - minlot)/step));
  return(0);
}

5-sec code:

void OnStart()
{
  double minlot=0.01;
  double step  =0.01;
  Print(minlot+step*MathRound((0.005 - minlot)/step));
}
 
joo:

MathRound() works differently in 4 and 5, and should be the same.

4-sec code:

5-sec code:

The problem is here:

  double y=MathRound(-0.5);
  Print("Округление -0.5 до ",y);

This value is rounded differently in 4 and 5.

 
Loky:
No surprise there, that's the way it should be.
And more specifically?
 

Why does MT5 not save order history, etc., if testing is interrupted? In MT4 it was saved.

Also there is no positioning in the order history from the testing chart - it was convenient to view orders in the area of large drawdowns by clicking on the chart.

 

Good evening.

Can you explain me please, how SLeep() method works?

It should pause the Expert Advisor for a certain period of time, or am I wrong?


{for (int sleep=0;sleep<10000;sleep++)

if(BarsCalculated(Handle)>=o_bars_reoptimizate)

{ Print(BarsCalculated(Handle)); break; } else Sleep(100);}

For this code, I expect the result - if the number of bars calculated for a certain indicator is greater than a certain value, the loop is broken; otherwise there is a 100ms delay in further code execution. Total possible total delay is 100*10000ms....That's enough time for calculation of indicator. Then why code continues to run? (which follows this cycle) Or in the tester, this function does not work as I assume. Thanks in advance for the clarification.

 
mi__x__an:

Good evening.

Can you explain me please, how SLeep() method works?

It should pause the Expert Advisor for a certain period of time, or am I wrong?


{for (int sleep=0;sleep<10000;sleep++)

if (BarsCalculated(Handle)>=o_bars_reoptimizate)

{ Print(BarsCalculated(Handle)); break; } else Sleep(100);}

For this code, I expect the result - if the number of bars calculated for a certain indicator is greater than a certain value, the loop is broken; otherwise there is a 100ms delay in further code execution. Total possible total delay is 100*10000ms....That's enough time for calculation of indicator. Then why code continues to run? (which follows this cycle) Or in the tester, this function does not work as I assume. Thanks in advance for the clarification.

Sleep does not work in indicators
 

The documentation, for example, CopyBuffer, causes brain rattling: "If you want to make a partial copying of indicator values into another array (not the indicator buffer), you should use the intermediate array for this purpose, in which the required values are copied. And already from this intermediate array perform element-by-element copying of the required number of values to the right places of the receiving array. "

int  CopyBuffer(
   int       indicator_handle,     // handle индикатора
   int       buffer_num,           // номер буфера индикатора
   [...]
   );

Ifbuffer_num is explicitly referred to, the necessity of preliminary binding of the receiving array to the indicator buffer with one or another sequence number through SetIndexBuffer is certainly implied. But,"if we want to copy some values of the indicator to another array (not the indicator buffer)", we can't talk aboutbuffer_num, since it's not indicator and we, by definition, haven't connected it with anything.

A contradiction?

Ambiguity?

Or maybe I'm completely programmed?

I tried to find a clear definition of an indicator buffer and failed. Is it really any buffer linked via SetIndexBuffer or it is not enough and it should be an array with the INDICATOR_DATA identifier ?

Reason: