ChartNavigate during initialisation - page 5

 
Ihor Herasko:

No, I'm not. Because that's exactly the point. Let me tell you a little bit more about what this is all about. The trader uses the chart as if it were a tester. The indicator hides a part of the real chart to the right of the supposedly current time (in fact, this time is somewhere in the history). Pressing F12 displays the next candle in the online chart, etc. So, it is when restarting the terminal with the indicator attached that it does not return the chart position to the place where the trader finished his studies. As a result he/she receives an empty chart because the terminal resets the chart to the last real candle. And this despite the fact that the terminal was unloaded in a completely different place.

An interesting observation. I checked it myself - alas, nothing has changed. I still get the freshest prices on reloading.

I suggest that we "synchronise our watches". I'm testing all this on build 1861. What is your build?

Maybe you should add such lines at the front

   ChartSetInteger(0, CHART_AUTOSCROLL, false);
   ChartSetInteger(0, CHART_SHIFT, false);
   ChartNavigate(0, CHART_END, 0);

and then shift it?

Or just don't shift it anywhere. It works without problems too.

ChartNavigate(0, CHART_CURRENT_POS, 0)

At which bar I closed the terminal, and at which it opened.

However, this variant keeps the chart on the inactive window as well. Alas. The chart stays in place even without this code.

 
Alexey Viktorov:

Maybe add lines like this at the front

and then shift it afterwards?

Yes, the full version has it all. If you work without rebooting the terminal, everything is fine. But rebooting leads to such problems. And even crutch solution doesn't always help. I'll investigate it further.

 
Ihor Herasko:

Yes, the full version has it all. If you work without rebooting the terminal, everything is fine. But rebooting leads to problems like this. And even crutch solution doesn't always help. I'll investigate it further.

But I've done experiments with rebooting the terminal too. What may be the problem? I got the update downloaded, but I cancelled the update for now. Maybe you should update as well?
 
Alexey Viktorov:
But I have also experimented with restarting the terminal. What could be the problem? I got the update downloaded, but so far I've cancelled the update. Maybe you should update as well?

Upgraded to 1865 build. The problem remains.

Moreover, it turned out that even after full loading of data on the chart and using ChartNavigate() the chart is displayed where required for a while, but with a new tick it still goes back to the very last bar. The autoscroll button is disabled and no other indicators are used.

If you move the chart manually, nothing like this happens. I am at a loss for now. I will investigate it tomorrow when I have fresh eyes to see if I have screwed up somewhere.

 
MetaTrader 5 x64 build 1870 started (MetaQuotes Software Corp.)
Windows 10 (build 17134) x64, IE 11, UAC, Intel Core i3-3120 M  @ 2.50 GHz, Memory: 4720 / 8077 Mb, Disk: 301 / 464 Gb, GMT+2
C:\Users\barab\AppData\Roaming\MetaQuotes\Terminal\D0E8209F77C8CF37AD8BF550E51FF075

Script. Only withCHART_CURRENT_POS it is stable. With CHART_BEGIN and positive "Shift", as well as with CHART_END and negative "Shift", the chart either does not move or jumps (scrolls itself) to the latest prices: feeling that the autoscroll button is enabled.

//+------------------------------------------------------------------+
//|                                                       Test_1.mq5 |
//|                              Copyright © 2018, Vladimir Karputov |
//|                                           http://wmua.ru/slesar/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2018, Vladimir Karputov"
#property link      "http://wmua.ru/slesar/"
#property version   "1.000"
#property script_show_inputs
//--- input parameters
input ENUM_CHART_POSITION  InpPosition = CHART_CURRENT_POS;    // Chart Position  
input int                  InpShift    = -1;                   // Shift
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   ResetLastError();
//--- получим номер самого первого видимого на графике бара (нумерация как в таймсерии) 
   int chart_first_visible_bar=ChartFirstVisibleBar();
   if(chart_first_visible_bar==-1)
      return;
//--- 
   string comm="До: Первый бар на графике имеет номер "+IntegerToString(chart_first_visible_bar);
//--- выведем комментарий 
   Print(comm);
   if(ChartNavigate(ChartID(),InpPosition,InpShift))
      Print("ChartNavigate ",EnumToString(InpPosition),",",InpShift," успешно");
   else
      Print("Ошибка №",GetLastError(),", ",EnumToString(InpPosition));
//--- получим номер самого первого видимого на графике бара (нумерация как в таймсерии) 
   chart_first_visible_bar=ChartFirstVisibleBar();
   if(chart_first_visible_bar==-1)
      return;
//--- 
   comm="После: Первый бар на графике имеет номер "+IntegerToString(chart_first_visible_bar);
//--- выведем комментарий 
   Print(comm);
  }
//+------------------------------------------------------------------------------+ 
//| Gets the index of the first visible bar on chart.                            | 
//| Indexing is performed like in timeseries: latest bars have smallest indices. | 
//+------------------------------------------------------------------------------+ 
int ChartFirstVisibleBar(const long chart_ID=0)
  {
//--- prepare the variable to get the property value 
   long result=-1;
//--- reset the error value 
   ResetLastError();
//--- receive the property value 
   if(!ChartGetInteger(chart_ID,CHART_FIRST_VISIBLE_BAR,0,result))
     {
      //--- display the error message in Experts journal 
      Print(__FUNCTION__+", Error Code = ",GetLastError());
     }
//--- return the value of the chart property 
   return((int)result);
  }
//+------------------------------------------------------------------+

1

 
Ihor Herasko:

Upgraded to 1865 build. The problem remains.

Moreover, it turned out that even after full loading of data on the chart and using ChartNavigate() the chart is displayed where required for a while, but with a new tick it still goes back to the very last bar. The autoscroll button is disabled and no other indicators are used.

If you move the chart manually, nothing like this happens. I am at a loss for now. Tomorrow I will investigate it again with a clear head, maybe I have screwed up somewhere.

I suggested to update not in the hope that everything will fall into place, but in order to have the same builds.

Igor, are you making experiments with the full version of the indicator or with the experimental one?

I have just reloaded the terminal with build 1865 and everything was fine. I'm writing this message, periodically look at the chart, switch the chart windows... But the shifted chart remains unmoved despite incoming ticks and switching.

Here is the whole code

#property indicator_chart_window
#property indicator_plots 0
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   ChartSetInteger(0, CHART_AUTOSCROLL, false);
   ChartSetInteger(0, CHART_SHIFT, false);
   ChartNavigate(0, CHART_END, 0);
   if(ChartNavigate(0, CHART_END, -100))
      Comment("Успешно");
   else
      Comment("Ошибка №", GetLastError());   
  //ChartRedraw(ChartID());
//---
   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);
  }
//+------------------------------------------------------------------+

void OnDeinit(const int reason)
{
 Comment("");
}/********************************************************************/
For some reason, I don't believe that one terminal works this way and another works that way.
 
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 with the full version of the indicator or with an experimental one?

I have just reloaded the terminal with build 1865 and everything was fine. I am writing this message, periodically look at the chart, switch the chart windows... But the shifted chart remains unmoved despite incoming ticks and switching.

Here is the whole code

Somehow I don't believe that one terminal works this way and the other does not.

Try looking at a symbol that has no history at all

 
Artyom Trishkin:

Try to look for a symbol that has no history at all

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 there already...

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

 
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...

Second was opening the EURMXN symbol. Without looking in the terminal can you tell what it is? )))

No, I can't...

What I meant was that probably loading historical data makes the chart shift towards its end.

Try this: put the indicator on a minute timeframe, close the terminal and open it after an hour - the terminal starts loading the missing minutes - what will happen to the chart? Will it shift?

 

What a newsflash!!!

I had H1, H4 period charts open and I used them to check. Now started experimenting on M1, M5, M30... it's not working!!!

Switching to H1 or H4 there is no problem even if there is a new hour. This was tested either yesterday or early today or both yesterday and today... not the point, but I got caught up in the hour change.

Reason: