ChartTimePriceToXY when used in OnChartEvent returns false but provides values.

 

Strange behavior with ChartTimePriceToXY function. Please check the following code

#property copyright "Copyright 2021, PuguForex."
#property link      "https://www.mql5.com/en/users/puguforex"
#property version   "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers   0 
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   
//---
   return(INIT_SUCCEEDED);
  }

void OnDeinit(const int reason)
  {

  }  
//+------------------------------------------------------------------+
//| 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);
  }
//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
//---
   ResetLastError();
   int x,y;
   bool  getxy =  ChartTimePriceToXY(0,0,lparam,dparam,x,y);
   if(getxy)
     {
      Print("True, error = [",GetLastError(),"]");
     }
    else
      {
       Print("False, error = [",GetLastError(),"]");
      }
   PrintFormat("X = %i, Y = %i",x,y);       
  }
//+------------------------------------------------------------------+ 
 
  1. You never turned on the timer. Your code does nothing. Need more coffee.
  2. You call XY for any event. The params could contain anything.
  3. You are not following the mouse (not enabled.)
 
William Roeder #:
  1. You never turned on the timer. Your code does nothing.
  2. You call XY for any event. The params could contain anything.
  3. You are not following the mouse (not enabled.)

1. I am not using OnTimer event handler so I don't know what you mean here

2. I have tried to call it for a single event ( CHARTEVENT_CLICK ) but still same issue

3. Mouse move enabled but still same issue.

The code works correctly when moved to the OnCalculate event handler and passed with time,price as arguments but doesn't works in OnChartEvent handler.

Reason: