question about EventChartCustom function

 
ButtonCreate(long chart_id,CChartObjectButton &btn,int i,const string name,
                                 const int x,const int y)
  {
   if(!btn.Create(chart_id,"Sym_"+(string)i+"_"+name,0,x,y,77,25))
      return(false); //"Button_"+name
   if(!btn.Description(name))
      return(false); //"NEXT"
   if(!btn.FontSize(10))
      return(false);
   if(!btn.Color(textColor))//clrBlack
      return(false);
   if(!btn.BackColor(clrWhite))//
      return(false);
   if(!btn.BorderColor(clrDodgerBlue))//clrBlack
      return(false);
//--- successful execution
   return(true);
  }

Hi 

I have created 3 button in three diferent chart, with one expert !

and now I want to do something when the buttons get pressed by mouse click

it is simple for the button that is in chart that the expert is athached , using this code :

OnChartEvent(const int id,
                                 const long &lparam,
                                 const double &dparam,
                                 const string &sparam)
  {
   
//--- check the event of clicking the chart object
   if(id==CHARTEVENT_OBJECT_CLICK)
     {
      //--- divide the object name by separator
      string obj_name[];
      StringSplit(sparam,'_',obj_name);
      //--- check if the object is a button

//...
    }
//...
}

but for two buttons in other charts I canot do something !

I guess it is possible with  EventChartCustom function because it has : long    chart_id, parameter , but I can not understand how by reading the help !!

can anyone guide me please ?

regards

 
Get the Chart ID for the 2 other charts with the buttons.  Send the custom event.
 
Thank-god Avwerosuoghene Odukudu #:
Get the Chart ID for the 2 other charts with the buttons.  Send the custom event.

 

my question is how can I understand the buttons on the other pages have pressed ? 

you know, I want to do this throu event , not by checking State of the buttons ( pressed or not ) on the other page

I have saved 3 pages 's ID .

I only have run one expert on first page
 
Mehrdad Sarrafi #:

 

my question is how can I understand the buttons on the other pages have pressed ? 

you know, I want to do this throu event , not by checking State of the buttons ( pressed or not ) on the other page

I have saved 3 pages 's ID .

I only have run one expert on first page

Example in the documentation for the EventChartCustom does just what you want - it detects button click on the chart and then based on the button state it broadcasts an event.

The key point is to define different events for different button states.

Study that code.

 
Drazen Penic #:

Example in the documentation for the EventChartCustom does just what you want - it detects button click on the chart and then based on the button state it broadcasts an event.

The key point is to define different events for different button states.

Study that code.

there is a difference 

the button in the example is located in the chart that the expert is attached .

but mine is in another page !!


<<>>>>how can I detect mouse click on another chart's button or other objects ?<<<>>>>

 
Mehrdad Sarrafi #:

there is a difference 

the button in the example is located in the chart that the expert is attached .

but mine is in another page !!


<<>>>>how can I detect mouse click on another chart's button or other objects ?<<<>>>>

Read the sample code, especially the last function - "BroadcastEvent" - it broadcasts event to all active charts.

After that, study OnChartEvent function in the sample code and carefully examine part where it catches CHARTEVENT_CUSTOM.

Is there anything that prevents you from creating two EA's or indicators where one of them broadcasts event and another waits for it?

Simplest test - compile that sample code and run it on two charts and then click on one chart and check what happens on another.

 
Drazen Penic #:


Is there anything that prevents you from creating two EA's or indicators where one of them broadcasts event and another waits for it?

Simplest test - compile that sample code and run it on two charts and then click on one chart and check what happens on another.

OK thank you very much

I want to simplify  running the expert .

then as you say the optimum way is to write an indicator and load on the other charts to send the event to master chart (expert)  or do the task by itself. 

am I right?

 
Mehrdad Sarrafi #:

OK thank you very much

I want to simplify  running the expert .

then as you say the optimum way is to write an indicator and load on the other charts to send the event to master chart (expert)  or do the task by itself. 

am I right?

I really don't know what you want to achieve. I just pointed out that the sample code from the documentation does what you asked in your original question - put a button on a chart, then broadcast the click to all active charts, and then listen to the broadcasted event on all charts where the sample EA runs.

The part of the code from the sample that detects a button click and then broadcasts events should be on all charts where you want a button

The part of the event handler from the sample code that waits for the CHARTEVENT_CUSTOM should be on all charts where you want to listen for the event.

Both parts of that code can work both in EA and indicator, so the architecture depends on what you want to accomplish.


Sample code has both parts because it was simpler to have both broadcast and event listen code in a single file. 


Anyway - did you try what I suggested  before - compile the sample code, run it on two or more charts, and then click the button? Do you understand how it works? Run one copy from the debugger and go through the code.

 

The answers are above. Just as a sample 

   #define Click_But1 14            // Button 1
   #define Click_But2 15            // Button 2
   #define Click_But3 16            // Button 3
   if(id==CHARTEVENT_OBJECT_CLICK)
     {
      //--- divide the object name by separator
      string obj_name[];
      StringSplit(sparam, '_', obj_name);
      //--- check if the object is a button

      //...

      //--- Broadcasting events to the required chart
      long IDs[2];
      EventChartCustom(IDs[0], Click_But2, lparam, dpar  am, sparam);
      EventChartCustom(IDs[1], Click_But3, lparam, dparam, sparam);

     }

   if(id==CHARTEVENT_CUSTOM+Click_But2)
     {
      // Carry out Button 2 action
     }
Reason: