ChartNavigate during initialisation - page 2

 
Ihor Herasko:

What if there are no ticks, weekends? Then a timer will have to be connected.

And there is only one question to solve: how to determine whether ChartNavigate has been successfully executed? The fact that it returns true, it's just "for ticks", it does not help in real work.

I need to check the code I posted above in my Expert Advisor...

 
Vladimir Karputov:

I need to check the code I posted above in the EA...

What does the EA have to do with it?

 
Ihor Herasko:

What does this have to do with the councillor?

We should check...

//+------------------------------------------------------------------+
//|                                                  Test EA.mq5.mq5 |
//|                        Copyright 2018, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
//--- input parameters
input bool redraw=true;
input ENUM_CHART_POSITION position=CHART_BEGIN;
//---
long count=0;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   count=0;
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   Comment("");
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   count++;
//Comment(count);
   if(count==9 || count==19)
     {
      ResetLastError();
      if(position==CHART_BEGIN)
        {
         if(ChartNavigate(ChartID(),CHART_BEGIN,100))
            Print("Успешно. redraw ",redraw,". position ",EnumToString(position));
         else
            Print("Ошибка №",GetLastError(),". redraw ",redraw,". position ",EnumToString(position));
        }
      if(position==CHART_END)
        {
         if(ChartNavigate(ChartID(),CHART_END,-100))
            Print("Успешно. redraw ",redraw,". position ",EnumToString(position));
         else
            Print("Ошибка №",GetLastError(),". redraw ",redraw,". position ",EnumToString(position));
        }
      if(redraw)
         ChartRedraw();
     }
//--- получим номер самого первого видимого на графике бара (нумерация как в таймсерии) 
   long first_bar=ChartGetInteger(0,CHART_FIRST_VISIBLE_BAR,0);
//--- добавим символ переноса строки 
   string comm="\r\n";
//--- дополним коментарий 
   comm=comm+"Первый бар на графике имеет номер "+IntegerToString(first_bar)+"\r\n";
//--- выведем комментарий 
   Comment(comm);
  }
//+------------------------------------------------------------------+
Files:
Test_EA.mq5  6 kb
 

Vladimir Karputov:

This is the indicator - I specifically put a delay of nine ticks, two types of chart movement and a forced re-draw flag (on/off)

You are not a beginner. Why are you misleading? Why are you ignoring what Renat Fatkhullin said?

In your code (as here, so here) it's forced to redraw the chart on every tick by creating comments on every tick.


I.e., regardless of whether the flag in the input parameters is enabled or disabled.


And the inclusion of your flag in the input parameters, in this case, only causes an additional redraw viaChartRedraw().

I.e., instead of being useful, it creates an additional load on the already existing ones by creating comments

P./S.:

Forum on trading, automated trading systems and testing of trading strategies

Errors, bugs, questions

Renat Fatkhullin, 2017.12.05 02:51

...

In MT5, the Comment function explicitly causes the chart to be redrawn...

The difference is just that.


If in MT4 after calling Comment you put ChartRedraw() forcibly, the behavior is still not the same as in MT5. ChartRedraw() in Metatrader 4 ignores the comment value and decides for itself whether or not to update the chart from the last frame. Of course, in the absence of hundreds of quotes per second which would cause a disabling of chart data, ChartRedraw decides "why draw an unchanged chart" and skips drawing the frame.

Metatrader 5 also has the same system, but there are many more cases where unconditional drawing is given priority.

Terminals are graphical applications and can provide hundreds of frames per second and run in lean display mode for the sake of performance.


Hence additional conclusions when running benchmarks:

  • one should not consider a ChartRedraw call to be a real chart drawing

  • you must always know and prove statements "why a chart will be redrawn" and "am I invalidating the internal picture of the market so that the terminal decides to redraw the chart".

  • you should not make multiple conclusions in MT5 during the benchmarks, you should always think about how you are affecting the rendering

  • MT5 has a more correct system of changing objects on the chart and it is necessary to clearly understand the consequences of read/write commands mixing
    it is recommended not to mix read/write commands, and to do mass read and mass write separately.

  • frequent redrawing of charts in benchmarks leads to a high dependency of the results on the graphics card.
    in fact, some tests may end up testing the graphics card rather than the algorithms or functions. the test on a laptop and a desktop computer may show multiple times different results simply because of a 3-5 times slower graphics card

These errors are made all the time by everyone.


 

Forum on trading, automated trading systems and strategy testing

ChartNavigate during initialization

Vladimir Karputov, 2018.06.25 18:52

Gotta check it...

...
void OnTick()
  {
//---
   count++;
//Comment(count);
   if(count==9 || count==19)
     {
      ResetLastError();
      if(position==CHART_BEGIN)
        {
         if(ChartNavigate(ChartID(),CHART_BEGIN,100))
            Print("Успешно. redraw ",redraw,". position ",EnumToString(position));
         else
            Print("Ошибка №",GetLastError(),". redraw ",redraw,". position ",EnumToString(position));
        }
      if(position==CHART_END)
        {
         if(ChartNavigate(ChartID(),CHART_END,-100))
            Print("Успешно. redraw ",redraw,". position ",EnumToString(position));
         else
            Print("Ошибка №",GetLastError(),". redraw ",redraw,". position ",EnumToString(position));
        }
      if(redraw)
         ChartRedraw();
     }
//--- получим номер самого первого видимого на графике бара (нумерация как в таймсерии) 
   long first_bar=ChartGetInteger(0,CHART_FIRST_VISIBLE_BAR,0);
//--- добавим символ переноса строки 
   string comm="\r\n";
//--- дополним коментарий 
   comm=comm+"Первый бар на графике имеет номер "+IntegerToString(first_bar)+"\r\n";
//--- выведем комментарий 
   Comment(comm);
  }
//+------------------------------------------------------------------+

P./S.: In addition to your second code: before updating the text entry and publication via the same comment, check if the data has changed. If not, it is better to postpone the text update and publication.

I.e., in this case it is whether the number of the first bar on the graph has changed

 
Vladimir Karputov:

I'll have to check...

Mmm. I'm not quite sure what that's about. OK, then. I've installed it. Checked it in CHART_BEGIN and CHART_END modes. It's working as advertised. After rebooting, it's OK.

Or are you getting at the point where you need to use a crutch - check the number of the first bar on the chart after ChartNavigate and, if it's not the right one, run ChartNavigate again.

Yes, the way out, of course, I thought about it too. But it's tiresome to remember constantly about such fiches of the terminal. After all, it's quite possible that it's a bug.

 
Dina Paches:

P./S.: In addition to your second code: before updating a text entry and publication via the same comment, check if the data has changed. If not, it is better to postpone the text update and publication.

I.e., in this case it's whether the number of the first bar on the chart has changed

Thanks for the info, of course, but we're not talking about performance here. The problem we're discussing is on a slightly different plane, it's just test codes to check if the problem has manifested itself ))

 
Ihor Herasko:

Thanks, of course, for the information, but we're not talking about performance here. The problem we're discussing is on a slightly different plane, it's just test codes to check if the problem appears ))

You're welcome. But see also my other post to which the one you quoted is a postscript.

P./S.: Don't devalue, please. I will not run such codes on mine, knowing what it entails. My equipment is not government-issued

 
Ihor Herasko:

Mmm. I'm not quite sure what that's about. OK, then. Installed it. Checked in CHART_BEGIN and CHART_END modes. Everything works as advertised. After rebooting, it's OK.

Or are you getting at the point where you need to use a crutch - check the number of the first bar on the chart after ChartNavigate and, if it's not the right one, run ChartNavigate again.

Yes, the way out, of course, I thought about it too. But it's tiresome to remember constantly about such fiches of the terminal. After all, it's quite possible that it's a bug.

I used to have a working navigation. Now I have to check it on purpose.


Added: don't pay attention to Comment :)

 
Vladimir Karputov:

My navigation used to work. Now I have to check it on purpose.


Added: Ignore the Comment :)

Why? Did I write/report nonsense?

Reason: