Problems with CHARTEVENT_OBJECT_CLICK

 

Hi coders,

I made a small test indicator and it doesn't always work how it should. Sometimes an alert pops up but more often it doesn't. Is there something I forgot?

Edit: Obviously it only works when I click on the corners or directly in the middle where the little squares are when the rectangle is selected.

#property strict
#property indicator_chart_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   
//---
   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);
  }
//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
//---
   if (id==CHARTEVENT_OBJECT_CLICK) {
      if (ObjectType(sparam)==OBJ_RECTANGLE) {
         Alert("Click on ", sparam);
      }
   }
  }
//+------------------------------------------------------------------+
Reason: