ChartNavigate() problem still exist

 

hello, I wanted to use ChartNavigate() in my program, but it does not work as it should.

ChartNavigate(0, CHART_BEGIN, 1300); scrolls normaly to bar 1300 but very often to CHART_BEGIN ! Very strange.

The problem was described 2015 in this thread: https://www.mql5.com/en/forum/69245

Does anybody knows a workaround for this problem ?


Here is my code to show the Bug:

//
// MT5 BUG ChartNavigate()
// =======================
//
// Check it with DOW or NASDAQ M1 Chart on exchange open hour so the MT5 is busy.
//
// ChartNavigate(CHART_BEGIN, pos) scrolls often to CHART_BEGIN and not CHART_BEGIN+pos
//
// ChartNavigate(CHART_END, pos) scrolls often to CHART_END and not CHART_END+pos
//
// This creates in bigger applications bad flickering !
//
// If the MT5 is busy (many Ticks per second) the bug is visible very often, 
// like every 5. calling ChartNavigate() fails.
// It seems to be a multitasking problem with not seralized variables ...
// If you open 2 charts DOW+NASDAQ then it depends where the mouse cursor is !
//
// See Source Lines: 149, 150, 151 !
//
// Tested with MT5 v5.00.2361 on Windows 7 Ultimate SP1 x32
// Tested with MT5 v5.00.2715 on Windows 10 Pro 20H2 19042.630 x64
// 
//************************************************************************
//

#property copyright "Copyright (c) 2020 by XYZ"
#property description "MT5 BUG ChartNavigate()"
#property version   "1.00"

#property indicator_chart_window
#property indicator_plots   1
#property indicator_type1   DRAW_LINE   // plot a Tick Chart with about 5000 Ticks
#property indicator_buffers 1

double   USR[];

bool  DoInit;
uint  TickN;
uint  ChartW;
 

void OnInit()  {

  ChartSetInteger(0, CHART_MODE, CHART_LINE);
  ChartSetInteger(0, CHART_COLOR_CHART_LINE, clrNONE);
  ChartSetInteger(0, CHART_SHOW_BID_LINE, true);
  ChartSetInteger(0, CHART_SHOW_ASK_LINE, false);
  ChartSetInteger(0, CHART_AUTOSCROLL, false);
  ChartSetInteger(0, CHART_SHOW_GRID, false);
  ChartSetInteger(0, CHART_SHOW_VOLUMES, false);
  ChartSetInteger(0, CHART_SHOW_DATE_SCALE, false);
  ChartSetInteger(0, CHART_SCALEFIX, true);
  ChartSetInteger(0, CHART_SCALE, 0);
  PlotIndexSetInteger(0, PLOT_LINE_COLOR, 0, C'0,200,200');
  PlotIndexSetInteger(0, PLOT_LINE_WIDTH, 2);
  PlotIndexSetInteger(0, PLOT_LINE_STYLE, STYLE_SOLID);
  SetIndexBuffer     (0, USR,   INDICATOR_DATA);
  PlotIndexSetDouble (0, PLOT_EMPTY_VALUE, 0);
  ArraySetAsSeries(USR, false);
  ChartW = (uint)ChartGetInteger(0, CHART_WIDTH_IN_BARS);
  ChartSetSymbolPeriod(0, _Symbol, PERIOD_M1);
  EventSetMillisecondTimer(100);
  DoInit = true;
}

void OnTimer()  {

//  k = (uint)ChartGetInteger(0, CHART_WIDTH_IN_BARS);              // UnComment: BUG nearly always ???
//  ChartNavigate(0, CHART_BEGIN, TickN-ChartW+200);                // scrolls often to CHART_BEGIN ???
//  k = (uint)ChartGetInteger(0, CHART_WIDTH_IN_BARS);              // UnComment: BUG nearly never ???
}


int OnCalculate(const int       BarNN,
                const int       CalcN,
                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[])  {

  uint     i;
  uint     j; 
  uint     k;
  MqlTick  Tick;
  MqlTick  ti[];
    
  if (DoInit)  {          // fill with 5'000 ticks HistoData
    DoInit = false;
    ZeroMemory(USR);
    ArrayResize(ti, 10000);
    CopyTicks(_Symbol, ti, COPY_TICKS_ALL, 0, 10000);
    TickN = 0;
    i     = 10000;
    j     = 5000;
    while ((j>0) && (i>0))  {
      i--;
      if ((ti[i].flags & TICK_FLAG_BID)>0)  {
        j--;
        USR[j] = ti[i].bid;
        TickN++;
      }
    }
    ArrayResize(ti, 0);
  }
  SymbolInfoTick(_Symbol, Tick);
  if ((Tick.flags & TICK_FLAG_BID)>0)  {  // new BID tick received
    USR[TickN] = Tick.bid;
    TickN++;
    for (i=0; i<100; i++)  {              // visual Marker for CHART_BEGIN
      if ((i % 10)<4)  {
        USR[i] = Tick.bid + 50;
      }
      else  {
        USR[i] = Tick.bid - 50;
      }
    }
    ChartSetDouble(0, CHART_FIXED_MIN, Tick.bid-0.005*Tick.bid);    // Axis
    ChartSetDouble(0, CHART_FIXED_MAX, Tick.bid+0.005*Tick.bid);
    k = 0;                                                          // here is the buggy MQL5 command
//  k = (uint)ChartGetInteger(0, CHART_WIDTH_IN_BARS);              // UnComment: BUG nearly always ???
    ChartNavigate(0, CHART_BEGIN, TickN-ChartW+200);                // scrolls often to CHART_BEGIN ???
//  k = (uint)ChartGetInteger(0, CHART_WIDTH_IN_BARS);              // UnComment: BUG nearly never ???
  }
  return  1;
}

ChartNavigate problem
ChartNavigate problem
  • 2015.12.15
  • www.mql5.com
Hi, first I apologize if this is in the wrong part of the forum, I saw no technical problems or developer section...
Files:
NaviBUG_1.png  9 kb
NaviBUG_2.png  10 kb
NaviBUG_3.png  11 kb
 

Really no one has ever shifted the chart with ChartNavigate() ? I can't believe it.

Does nobody know a workaround ?

Reason: