Errors, bugs, questions - page 12

 

During the night I noticed one very strange thing, the start time of the bar is reflected with an error - the error was more than a minute. Now I want to check it and I made a test indicator

#property indicator_chart_window
datetime old_time=0;
int      MaxBars=10;    // ограничение 
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()  {return(0);}
//+------------------------------------------------------------------+
//| 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[])
  {
   if(rates_total<10) return(0);  // ничего не считаем и ничего не рисуем на графике         
   
   int      start_pos,   // точка старта
            count_tick;
   MqlDateTime str1,str2;
   

   if(prev_calculated==0) 
      {
      old_time=0;
      count_tick=0;
      start_pos=rates_total-3;
      }
   else start_pos=prev_calculated-1;
//--- расчет 
   for(int i=start_pos;i<rates_total;i++)
     {
      TimeToStruct(TimeCurrent(),str1); // время сервера
      TimeToStruct(time[i],      str2); // время бара  
      if(str1.min!=str2.min) {
      // Сбой - тик принадлежит не своему бару
         count_tick++;
         Print("тик №=",count_tick," i=", i," c=",close[i]," time[i]=",time[i]," time=",TimeCurrent()," delta=",str1.sec);
      }   
      } // end for(...
   return(rates_total);
  }
Log

2010.06.18 10:42:03 prov_tick (EURUSD,M1) tick #=6 i=50558 c=1.23797 time[i]=2010.06.18 08:41:00 time=2010.06.18 08:42:05 delta=5

2010.06.18 10:40:59 prov_tick (EURUSD,M1) tick #=5 i=50557 c=1.23848 time[i]=2010.06.18 08:40:00 time=2010.06.18 08:41:01 delta=1

2010.06.18 10:40:01 prov_tick (EURUSD,M1) tick #=4 i=50556 c=1.23862 time[i]=2010.06.18 08:39:00 time=2010.06.18 08:40:04 delta=4

2010.06.18 10:39:03 prov_tick (EURUSD,M1) tick #=3 i=50555 c=1.23881 time[i]=2010.06.18 08:38:00 time=2010.06.18 08:39:05 delta=5

2010.06.18 10:38:30 prov_tick (EURUSD,M1) tick#2 i=50554 c=1.23859 time[i]=2010.06.18 08:37:00 time=2010.06.18 08:38:31 delta=31

2010.06.18 10:38:30 prov_tick (EURUSD,M1) tick#1 i=50553 c=1.23858 time[i]=2010.06.18 08:36:00 time=2010.06.18 08:38:31 delta=31

The first two ticks are clear, it's an indicator start. But next ones .... It turns out that there is a new bar according to the server time, while this tick belongs to the old bar. At night this delta is a nightmare...

Question to the developers is a bug ? Or so it was conceived?

Z.I. while writing this is what appears in the log

2010.06.18 10:45:09 prov_tick (EURUSD,M1) tick #=9 i=50561 c=1.23787 time[i]=2010.06.18 08:44:00 time=2010.06.18 08:45:12 delta=12

Files:
prov_tick.mq5  2 kb
 
Prival:

During the night I noticed one very strange thing, the start time of the bar is reflected with an error - the error was more than a minute. Now I've decided to check it and created a test indicator


If you add rates_total to the output, you will see that errors occur when comparing the current minutes with the minutes of the previous bar.

2010.06.18 11:53:18     prov_tick_src (EURUSD,M1)       тик №=4 i=51420 rates_total=51422 c=1.23997 time[i]=2010.06.18 09:51:00 time=2010.06.18 09:52:06 delta=6
2010.06.18 11:52:12     prov_tick_src (EURUSD,M1)       тик №=3 i=51419 rates_total=51421 c=1.24061 time[i]=2010.06.18 09:50:00 time=2010.06.18 09:51:00 delta=0

That is, time[rates_total-2].

Also, the delta output is not entirely clear.

https://www.mql5.com/ru/docs/basis/function/events#oncalculate says:

Parameters open[], high[], low[] and close[] contain arrays with the opening, maximum, minimum and closing prices of the current timeframe. Parameter time[] contains an array of open time values, parameter spread[] contains an array with the history of spreads (if a spread is specified for a trade instrument). Parameters volume[] and tick_volume[] contain the history of trade and tick volume, respectively.

Документация по MQL5: Основы языка / Функции / Функции обработки событий
Документация по MQL5: Основы языка / Функции / Функции обработки событий
  • www.mql5.com
Основы языка / Функции / Функции обработки событий - Документация по MQL5
 
Prival:

During the night I noticed one very strange thing, the start time of the bar is reflected with an error - the error was more than a minute. I've decided to check it now and made a test indicator

Log

2010.06.18 10:42:03 prov_tick (EURUSD,M1) tick #=6 i=50558 c=1.23797 time[i]=2010.06.18 08:41:00 time=2010.06.18 08:42:05 delta=5

2010.06.18 10:40:59 prov_tick (EURUSD,M1) tick #=5 i=50557 c=1.23848 time[i]=2010.06.18 08:40:00 time=2010.06.18 08:41:01 delta=1

2010.06.18 10:40:01 prov_tick (EURUSD,M1) tick #=4 i=50556 c=1.23862 time[i]=2010.06.18 08:39:00 time=2010.06.18 08:40:04 delta=4

2010.06.18 10:39:03 prov_tick (EURUSD,M1) tick #=3 i=50555 c=1.23881 time[i]=2010.06.18 08:38:00 time=2010.06.18 08:39:05 delta=5

2010.06.18 10:38:30 prov_tick (EURUSD,M1) tick #=2 i=50554 c=1.23859 time[i]=2010.06.18 08:37:00 time=2010.06.18 08:38:31 delta=31

2010.06.18 10:38:30 prov_tick (EURUSD,M1) tick #1 i=50553 c=1.23858 time[i]=2010.06.18 08:36:00 time=2010.06.18 08:38:31 delta=31

The first two ticks are clear, it's an indicator start. But next ones .... It turns out that there is a new bar according to the server time, while this tick belongs to the old bar. At night this delta is a nightmare...

Question to developers, is it a bug or it was designed that way ?

Z.I. while writing this is what appears in the log

2010.06.18 10:45:09 prov_tick (EURUSD,M1) tick #=9 i=50561 c=1.23787 time[i]=2010.06.18 08:44:00 time=2010.06.18 08:45:12 delta=12

Try to test as follows. Without loop.

      TimeToStruct(TimeCurrent(),      str1); // время сервера
      TimeToStruct(time[rates_total-1],str2); // время последнего бара  

Further on the text.

 
stringo:

Try checking as follows. Without cycle.

Next in the text.

Oops. Got it. Thanks. I did a check inside the loop.

   if(old_time<time[i]) 
         {
         Print("НОВЫЙ бар");
         old_time=time[i];
         //...
         }  
// а нужно вот так
   if(old_time<time[rates_total-1]) // работаем только по завершенным барам
         {
         Print("НОВЫЙ бар");
         old_time=time[rates_total-1];
         //...
         } 

At the time of the new bar i has not changed. Not economical, the same data is repeatedly calculated. Although...

is this situation https://book.mql4.com/ru/samples/icustom fig.119 excluded in MQL5 if not ? and this indicator template will always output correct close ? or are there any pitfalls ?

input int   MaxBars=240;
datetime old_time=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()  {return(0);}
//+------------------------------------------------------------------+
//| 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[])
  {
//---
   if(prev_calculated==0) 
      {
      //... расчитать историю
      //...
      old_time=time[rates_total-1];
      }
// работаем только по завершенным барам
   if(old_time<time[rates_total-1]) 
      {
      old_time=time[rates_total-1];
      Print("НОВЫЙ бар close[1]=", close[rates_total-2]);
      }  
//--- return value of prev_calculated for next call
   return(rates_total);
  }
P.S. thanks for the science
Создание пользовательских индикаторов - Простые программы на MQL4 - Учебник по MQL4
  • book.mql4.com
Создание пользовательских индикаторов - Простые программы на MQL4 - Учебник по MQL4
 
sergey1294:
When I start to run my EA the entire terminal crashes in the tester, but if I put it on a chart everything is fine.

It is proven by experience that about 110 parameters can be digested (and there are questions). At 120, the terminal crashes if the Expert Advisor is specified in the tester.


I have already given some solutions in private, but if something happens, you can also ask the developers. I think they might be able to help with this limitation...

 
Interesting:

It is proven by experience that about 110 parameters can be digested (and there are questions). At 120 the terminal crashes if the Expert Advisor is specified in the tester.


I have already given some solutions in private, but if anything, you can ask the developers. I think they might be able to help with this limitation...

strange, of course, that such a restriction affects the tester. In quad, for example, there is no such problem
 

now the weekend quotes are not coming. running the script

Print(TimeCurrent());

result

2010.06.20 00:26:06 00 (USDJPY,M1) 2010.06.18 22:35:52

although the last bar has the time 2010.06.18 23:00:00

it seems strange, very inconvenient to test the correctness of some functions.

 

The "Apply" button in the indicator settings window is missing.


 
Interesting:

It is proven by experience that about 110 parameters can be digested (and there are questions). At 120 the terminal crashes if the Expert Advisor is specified in the tester.

I have already given some solutions in private, but if anything, you can ask the developers. I think they might be able to help with this limitation...

You can optimise a maximum of 64 parameters.
 
stringo:
A maximum of 64 parameters can be optimised.
Optimize 64 and use approximately 110 in the tester (without optimization). Although 110, of course, is already a "nightmare" number of parameters for the Expert Advisor (but it happens)...
Reason: