Chart Event not working when the indicator using Chart Event is called from EA using iCustom function

 

Hello People

In my recent project, I tried to call an indicator, which uses chart event and button objects, from EA using iCustom function.

After EA is loaded, the indicators are also loaded as the indicators are compiled as the part of resource of EA.  

However,  when I tried to click on the button from the indicator, nothing is happened.

I tried to print something to check if OnChartEvent function is working fine, but nothing is printed. I have no idea how to deal with this problem. Except OnChartEvent function problem, the other things are working fine from the indicators. Even buttons are correctly created.   

OnChartEvent function is the MQL5 built in function, and I have no idea how to go about this problem. Please share your idea if you have any.

Kind regards.

 

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

      if(id==CHARTEVENT_OBJECT_CLICK)
     {

         printf("button is clicked");     

     } 

} 
 

Hi, maybe you have to add this :

void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
//--- Check the event by pressing a mouse button
   if(id==CHARTEVENT_OBJECT_CLICK)
     {
      string clickedChartObject=sparam;
      //--- If you click on the object with the name buttonID
      if(clickedChartObject==buttonID)
        {
          Print("button is clicked"); 
        }
      }
   }   

I already try it and its work. This example is taken from documentation.

 
biantoro:

Hi, maybe you have to add this :

I already try it and its work. This example is taken from documentation.

Hi Thanks. Let me try and see it works.

The complication comes from the fact that I am calling the indicator using Object and Chart Event function with iCustom function after I embedded the indicator into resource in my EA.

Therefore, things would normally worked very well if the indicator is attached directly to charts. But when the indicator is called with iCustom, button object is drawn correctly but the button object with chart event is not function correctly.

Anyway, I will give a go with your idea.

Regards.

 
biantoro:

Hi, maybe you have to add this :

I already try it and its work. This example is taken from documentation.

Just tried your ideas. However nothing is printed.

As I mentioned before, The complication comes from the fact that I am calling the indicator from iCustom function after I embedded the indicator into resource in my EA.  

Anyways, thanks for your idea.

Regards 

 
Young Ho Seo:

Just tried your ideas. However nothing is printed.

As I mentioned before, The complication comes from the fact that I am calling the indicator from iCustom function after I embedded the indicator into resource in my EA.  

Anyways, thanks for your idea.

Regards 

If realised with my indicators that an error such as 'array out range' in the indicator stopped my events from working.
   Also the naming of the buttons gave me good exercise so now I check and delete all objects  before adding them. I also avoid short labels for object names. Does mq4 reserve some object names? I havent checked but it seems to work for me
 
Young Ho Seo:

Just tried your ideas. However nothing is printed.

As I mentioned before, The complication comes from the fact that I am calling the indicator from iCustom function after I embedded the indicator into resource in my EA.  

Anyways, thanks for your idea.

Regards 

That's expected behaviour, an indicator launched with iCustom is not running on a chart and don't react to chart events. Use ChartIndicatorAdd() to have it on the chart.