CHARTEVENT_CHART_CHANGE - Missing events (Bug?) - page 2

 
Doerk Hilger #:

it takes up to 4 (FOUR!) seconds until ChartGetDouble() returns.

Try this.
ChartGetDouble(-1, CHART_PRICE_MAX)
 
fxsaber #:
Try this.

Why? 

 
Doerk Hilger #:

Why? 

The program will access its chart directly, rather than through the general queue.

 
fxsaber #:
Try this.
fxsaber #:

The program will access its chart directly, rather than through the general queue.

Where is this coming from ? Do you have a link please ?

If it doesn't wait for the queue to be executed that means you could get wrong values.

 
Alain Verleyen #:

Where is this coming from ? Do you have a link please ?

https://www.mql5.com/ru/forum/342090/page50#comment_18647629

https://www.mql5.com/ru/forum/383101/page5#comment_26356569


I seem to have forgotten a bit. It was about creating your own events for the chart.

MT5 и скорость в боевом исполнении - Попробуйте сделать обходное решение. Введите TimeCurrentMsc в MQL5.
MT5 и скорость в боевом исполнении - Попробуйте сделать обходное решение. Введите TimeCurrentMsc в MQL5.
  • 2020.10.08
  • fxsaber
  • www.mql5.com
Иначе можно много терять на соединении с Print-снепшотом. На быстрой машине такое решение значительно быстрее обычного подхода. автоматическим торговым системам и тестированию торговых стратегий. что через -1 асинхронность того же Алерта не реализовать
 
Doerk Hilger #:

This issue is still not fixed.

Especially number 2 - I need to check if the max price of the chart changed, which happens, when the scale is not fixed and the new candles would exceed the the current chart display, in such a case, the chart is changed - but no event occurs. 

This measurement, which is clearly needed to catch all chart changes, slows down the EA drastically. I do this checking within the timer. I simply buffer the last Max-Price and compare it to the new one, by using ChartGetDouble(). My profiling shows horrible results and this explains stuttering execution.

As shown, it takes up to 4 (FOUR!) seconds until ChartGetDouble() returns. The profiling shows only values which exceed 1ms. 



What is the point of code optimization when bottlenecks like such remain since years ... I don´t get it. 

This is a Windows issue on slow computer (or VPS Windows Servers who are not optimized for the GUI). MT5 is relying on Windows events queue for such function call and it can be very slow (in seconds).

ChartEvent has been improved for the Max/Min changes. Available from build >=5880.

struct SChartProperties
  {
  //--- Chart Properties from Dialog
  int              scale;
  bool             isFixedScale;
  bool             isFixed11;
  bool             isScalePtBar;
  double           chartMax;
  double           chartMin;
  } ChartProperties;

bool Init=false;
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick(void)
  {
  if(Init) return;
  ChartProperties.isFixed11               = (bool)ChartGetInteger(0,CHART_SCALEFIX_11);
  ChartProperties.isFixedScale            = (bool)ChartGetInteger(0,CHART_SCALEFIX);
  ChartProperties.isScalePtBar            = (bool)ChartGetInteger(0,CHART_SCALE_PT_PER_BAR);
  ChartProperties.chartMax              = (double)ChartGetDouble(0,CHART_PRICE_MAX);
  ChartProperties.chartMin              = (double)ChartGetDouble(0,CHART_PRICE_MIN);
  ChartProperties.scale                   = (int)ChartGetInteger(0,CHART_SCALE);

  Init  = true;
  }
//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
  if(!Init) return;
//--- Change of the chart size or modification of chart properties through the Properties dialog
  if(id==CHARTEVENT_CHART_CHANGE)
    {
    printf("CHARTEVENT_CHART_CHANGE");
    }
//--- Detect a change in chart size or properties
  int scale = (int)ChartGetInteger(0,CHART_SCALE);
  if(scale!=ChartProperties.scale)
    {
    Print("CHANGE DETECTED on CHART_SCALE ",scale);
    ChartProperties.scale = scale;
    }
//---
  bool isFixed11 = (bool)ChartGetInteger(0,CHART_SCALEFIX_11);
  if(isFixed11!=ChartProperties.isFixed11)
    {
    Print("CHANGE DETECTED on CHART_SCALEFIX_11 ",isFixed11);
    ChartProperties.isFixed11 = isFixed11;
    }
//---
  bool isFixedScale = (bool)ChartGetInteger(0,CHART_SCALEFIX);
  if(isFixedScale!=ChartProperties.isFixedScale)
    {
    Print("CHANGE DETECTED on CHART_SCALEFIX ",isFixedScale);
    ChartProperties.isFixedScale = isFixedScale;
    }
//---
  bool isScalePtBar = (bool)ChartGetInteger(0,CHART_SCALE_PT_PER_BAR);
  if(isScalePtBar!=ChartProperties.isScalePtBar)
    {
    Print("CHANGE DETECTED on CHART_SCALE_PT_PER_BAR ",isScalePtBar);
    ChartProperties.isScalePtBar = isScalePtBar;
    }
//---
  double isChartMax = (double)ChartGetDouble(0,CHART_PRICE_MAX);
  if(isChartMax!=ChartProperties.chartMax)
    {
    Print("CHANGE DETECTED on CHART_PRICE_MAX ",isChartMax);
    ChartProperties.chartMax = isChartMax;
    }
//---
  double isChartMin = (double)ChartGetDouble(0,CHART_PRICE_MIN);
  if(isChartMin!=ChartProperties.chartMin)
    {
    Print("CHANGE DETECTED on CHART_PRICE_MIN ",isChartMin);
    ChartProperties.chartMin = isChartMin;
    }
  }
  
//+------------------------------------------------------------------+

2026.06.01 11:48:21.351    EA (EURUSD,H1)    CHANGE DETECTED on CHART_PRICE_MAX 1.1859
2026.06.01 11:48:21.351    EA (EURUSD,H1)    CHANGE DETECTED on CHART_PRICE_MIN 1.1396