find correct price with x y , left mouse button

 

Hi guys  i have  this code

//+------------------------------------------------------------------+
//|                                                        OCOea.mq4 |
//|                                  Copyright 2023, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2023, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict



extern string   b13="=== OPZIONI BOTTONE ===";     //.
extern color    TextColore=clrWhite;               // COLORE TESTO SU I BOTTONI
extern color    BackgColore1=clrGreen;             //COLORE TASTO APRI
extern color    BackgColore2=clrRed;               // COLORE TASTO CHIUDI

bool CtrlClickOneTouch=False;
bool CtrlAfterClick=False;

double price;
int x, y;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
       // create BUTTON 1

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
    ObjectsDeleteAll(0);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   
  }
//+------------------------------------------------------------------+

void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
{


                         if(id==CHARTEVENT_KEYDOWN){
                                              //--- Prepare variables
                       int      x     = (int)lparam;
                       int      y     = (int)dparam;
                       datetime dt    = 0;
                       double   price = 0;
                       int      window = 0;
                       datetime      time;         // Time on the chart 
                       int subwindow;
                     if (ChartXYToTimePrice(0, x, y, window, dt, price))
                     {
                         if (ChartTimePriceToXY(0, window, dt, price, x, y))
                           {
                                 //ChartXYToTimePrice(0,lparam,dparam,subwindow,time,price);
                                // ChartXYToTimePrice(0, x, y, subwindow, time, price);
                                 Print(" Subwindow: ",IntegerToString(subwindow)," Time: ",TimeToString(time,TIME_SECONDS)," Price: ",DoubleToString(price));
                           
                              //  horizLine("LineaSuperiore", price, clrWhite);
                                  ObjectCreate(0, "H Line", OBJ_HLINE, window, dt, price);
                                                 Alert("POP"+ iBarShift(Symbol(), 0, dt));
                           }
                      }     
                       
                      
                 if(lparam==18&&dparam==1.0&&sparam=="16426"){ //alt key
                

                       
                       
                }
              }
                      }
                
                
      



why price  when i click, return me a  price  out  of  chart?  

thanks

 
You should be using:
CHARTEVENT_CLICK
 
thanks