ChartNavigate during initialisation - page 6

 
Alexey Viktorov:

I have in this post:https://www.mql5.com/ru/forum/260815/page4#comment_7890492 detailed the conditions under which the problem can be reproduced. This was able to reproduce based on your assertions. What I wrote about here

I.e., a slight modification of the conditions led to a steady reproduction of the problem.

You somehow failed to notice this

 
Alexey Viktorov:

P./S.: Print instead of Comment in your code would not only be a gentler procedure. Print results in OnInit() are easier to compare, copy and attach here

 
Alexey Viktorov:

I suggested updating not in the hope that everything would fall into place, but so that the builds would be the same.

Igor, are you doing experiments on the full version of the indicator or on the experimental one?

Both there and there. But I still cannot say for sure what the issue is: whether it is a bug or not. I need to find sufficiently reproducible conditions.

 
Alexey Viktorov:

How to do this?

According to the description in the first post of the thread, it is an indicator, it hangs on an open chart - it means that the history is already loaded. Right? Hang the indicator, close the terminal, start the terminal, --- where can the history go? If it was already there...

Secondly, I opened EURMXN symbol. Without looking in the terminal, can you tell what it is? )))

It's easy:

  1. A template with the indicator is saved as default.tpl.
  2. The chart symbol is opened, which has never been opened before.
As a result, the indicator starts first, and then the data are loaded. I have got the whole bunch of events in one package.

 
Ihor Herasko:

Both there and there. But I still can't say with any certainty whether it's a bug or not. We need to find sufficiently reproducible conditions.

Your wording is a bit unfortunate. What I cited is of reproducible conditions.

Another thing is that yes, probably what I described in blocks I and II is not a bug, but peculiarities of data loading when the terminal is restarted .

And in 1870th build there were differences of replaying from what I got in 1861th.

Combinations of messages (success and error 4111) have changed a little. For example, if earlier there was such a stable reproduction:

test 2018 06 26 (GBPUSD,M5)     Alert: Успешно
test 2018 06 26 (GBPUSD,H1)     Alert: Ошибка №4111

Now, with the same code, the error messages seem to be more pronounced:

test 2018 06 26 (EURNZD,M5)     Alert: Ошибка №4111
test 2018 06 26 (EURNZD,H1)     Alert: Ошибка №4111

test 2018 06 26 (EURNZD,M5)     Alert: Ошибка №4111
test 2018 06 26 (EURNZD,H1)     Alert: Ошибка №4111

test 2018 06 26 (EURNZD,M5)     Alert: Ошибка №4111
test 2018 06 26 (EURNZD,H1)     Alert: Ошибка №4111

test 2018 06 26 (EURNZD,M5)     Alert: Успешно
test 2018 06 26 (EURNZD,H1)     Alert: Ошибка №4111


And block IIIfrom that post of mine is no longer reproducible in the 1870th.

Nor could it reproduce in the 1870s what is described here:https://www.mql5.com/ru/forum/260815/page5#comment_7901728 Last - maybe it depends somehow on the operating system (as a guess). I.e., this code by Vladimir works fine for me, with no problems

 
Ihor Herasko:

I have come across a problem with the ChartNavigate function. Doing something wrong or is there really a problem with the function. Write back if you have used it often enough.

So, the crux of the problem: ChartNavigate does not shift the chart When starting the terminal If you call this function in OnInit(). Especially several times I read the documentation. Nowhere does it say that the function can't be called at initialization.

Code indicator for playback:

Steps to play:

  1. Turn off chart autoplay.
  2. Attach indicator to the chart. ChartNavigate will trigger by moving the chart to the desired position.
  3. Unload the terminal.
  4. Load the terminal. ChartNavigate will not work by displaying the chart without an offset.
OK, if the function would give an error. But it doesn't. All calls are successful, but it is when the terminal is reloaded that the chart is not shifted.

Try the three variants of the indicator and see the result of each

1. ChartNavigate at the end of the other graphics commands

//+------------------------------------------------------------------+
//|                              TryToSetChartSettings_Indicator.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"
#property indicator_chart_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {


//--- отключим автопрокрутку
   ChartSetInteger(0,CHART_AUTOSCROLL,false);
//--- установим отступ правого края графика
   ChartSetInteger(0,CHART_SHIFT,true);
//--- отобразим в виде свечей
   ChartSetInteger(0,CHART_MODE,CHART_CANDLES);
//--- установить режим отображения тиковых объемов
   ChartSetInteger(0,CHART_SHOW_VOLUMES,CHART_VOLUME_TICK); 
//--- Прокрутим от правого края графика на 1000 баров влево
   ChartNavigate(0,CHART_END,-1000);
//---
   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. ChartNavigate one - no other commands to the chart

//+------------------------------------------------------------------+
//|                              TryToSetChartSettings_Indicator.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"
#property indicator_chart_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
/*
//--- отключим автопрокрутку
   ChartSetInteger(0,CHART_AUTOSCROLL,false);
//--- установим отступ правого края графика
   ChartSetInteger(0,CHART_SHIFT,true);
//--- отобразим в виде свечей
   ChartSetInteger(0,CHART_MODE,CHART_CANDLES);
//--- установить режим отображения тиковых объемов
   ChartSetInteger(0,CHART_SHOW_VOLUMES,CHART_VOLUME_TICK); 
*/
//--- Прокрутим от правого края графика на 1000 баров влево
   ChartNavigate(0,CHART_END,-1000);
//---
   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);
  }
//+------------------------------------------------------------------+


3. ChartNavigate before other chart commands

//+------------------------------------------------------------------+
//|                              TryToSetChartSettings_Indicator.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"
#property indicator_chart_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {

//--- Прокрутим от правого края графика на 1000 баров влево
   ChartNavigate(0,CHART_END,-1000);
//--- отключим автопрокрутку
   ChartSetInteger(0,CHART_AUTOSCROLL,false);
//--- установим отступ правого края графика
   ChartSetInteger(0,CHART_SHIFT,true);
//--- отобразим в виде свечей
   ChartSetInteger(0,CHART_MODE,CHART_CANDLES);
//--- установить режим отображения тиковых объемов
   ChartSetInteger(0,CHART_SHOW_VOLUMES,CHART_VOLUME_TICK); 

//---
   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);
  }
//+------------------------------------------------------------------+
 
Rashid Umarov:

And try three variants of the indicator, see the result of each

1. ChartNavigate at the end of the other chart commands

  1. Attached to the M1 chart with autoscrolling enabled. Autoscroll is off, chart has moved 1000 bars to the left.
  2. Reloaded the terminal without disconnecting the indicator from the chart. The chart shows the current candle, no shift of 1000 bars to the left. Autoscrolling remains unavailable.
  3. I repeated the step 2 7 times in a row. 3 times out of them the transition to the left of 1000 candles is complete, 4 times - the transition is not complete.
When I have not perfected the command "Waiting for refresh" appears. So, one can conclude that the terminal forcibly scrolls the chart to the latest quotes when loading the history. And since it happens after OnInit(), we get an unexpected result.

2. ChartNavigate alone - no other commands to the chart

  1. Since auto-scrolling is not automatically disabled in this version, I disabled it manually and connected the indicator. The chart has moved 1000 bars to the left.
  2. Rebooted the terminal without disconnecting the indicator from the chart.
  3. In 2 out of 7 cases scrolling has been performed. And in one of them it happened in three stages: displaying expected history, displaying the current candle and displaying the expected history. It looks as if OnInit() has been executed twice: once before the history has been loaded and the second time - after.

3. ChartNavigate before other chart commands.

  1. I have enabled auto-scrolling and attached the indicator. The chart jerked and returned to the current candle. To be expected, autoscrolling is disabled after 1000 bars move command.
  2. Rebooted the terminal without disconnecting the indicator from the chart (the chart displays the current candle).
  3. In all 7 cases the chart has displayed the current candle, scrolling has not even flashed.
If we restart the terminal without any indicators on the chart with auto-scrolling turned off and displaying somewhere in the depths of history, then at each restart we get the display of the place where the terminal was turned off. It turns out that somewhere during the execution of navigation commands there is a move to the current candle.
 
Ihor Herasko:

  1. Attached to the M1 chart with autoscroll on. Auto-scrolling was switched off, the chart moved 1000 bars to the left.
  2. Reloaded the terminal without disconnecting the indicator from the chart. The chart shows the current candle, no shift of 1000 bars to the left. Autoscrolling remains unavailable.
  3. I repeated the step 2 7 times in a row. 3 times out of them the transition to the left of 1000 candles is complete, 4 times - the transition is not complete.
In those cases I have noticed "Waiting for refresh" message. So, one can conclude that the terminal forcibly scrolls the chart to the latest quotes when loading the history. And since it happens after OnInit(), we get an unexpected result.

I always forget that your message/suggestion is read backwards. It's like in an old joke:

1917, October. A lady, granddaughter of
Decembrist, is sitting in her own house on Nevsky. Hearing a noise in the street, she asks her janitor to find out what
is going on.
- Young lady, the revolution is there! - The janitor comes back.
-Oh, how wonderful! - My grandfather dreamed of a revolution!
Go and find out what the revolutionaries want, my dear fellow!
- They want no rich men, ma'am," says the janitor on his return.
- Strange," says the lady thoughtfully, "but my grandfather wanted there to be no poor people!

I thought you were going to change the properties of the timetable before you rebooted the terminal.
 
Rashid Umarov:

I always forget that your message/suggestion will be read backwards.

What do you mean? You wrote that you need to test the operation of the three indicators. Since the topic is about reloading the terminal and then using ChartNavigate, these are the tests that were made.

I thought you were going to change the chart properties before restarting the terminal.

Why, if the problem is that ChartNavigate does not always work when the terminal starts? That's exactly the point.

 
Ihor Herasko:

the problem is exactly that ChartNavigate does not always trigger when the terminal starts? This is the point.

And also when I change my profile. In addition, if the ChartNavigate( chart_id, CHART_BEGIN, shift ) get for example CHART_FIRST_VISIBLE_BAR, then the result will be as if ChartNavigate has worked. If the Expert Advisor is removed, then the next time you start the Expert Advisor (this one or another), the result of obtaining CHART_FIRST_VISIBLE_BAR in this chart will look like CHARTNavigate failed.

The result: extremely inconsistent ChartNavigate operation already in combination with CHART_FIRST_VISIBLE_BAR