Action on all charts when a button is pressed in one chart

 

Hello there,

Can someone guide me on how to make an EA on each chart do something once when a button is pressed in any one of the charts in the same terminal? My guess is that I need to use Global Variables here. I am using MQL4 and not MQL5.

Thanks in advance.

 

Loop through all you chart with ChartFirst() and ChartNext() and the other function beginning with Chart..

Type e.g. ChartFirst() in the editor and press F1 - there you find everything you need.‌

 
jaya7838:

Hello there,

Can someone guide me on how to make an EA on each chart do something once when a button is pressed in any one of the charts in the same terminal? My guess is that I need to use Global Variables here. I am using MQL4 and not MQL5.

Thanks in advance.


You can use GVs, but you could also use EventChartCustom() and broadcast the event to all charts.

E‌ach EA is listening for the custom chart event, and takes action accordingly.

T‌ake a look at the documentation, and this post may help too.

EventChartCustom - Working with Events - MQL4 Reference
EventChartCustom - Working with Events - MQL4 Reference
  • docs.mql4.com
EventChartCustom - Working with Events - MQL4 Reference
 
Thank you both very much. I think I will write a separate script using ChartFirst() and ChartNext() to loop through the charts and do what I want, leaving the existing EA as it is. Once again, Thanks a lot
 
jaya7838:

Hello there,

Can someone guide me on how to make an EA on each chart do something once when a button is pressed in any one of the charts in the same terminal? My guess is that I need to use Global Variables here. I am using MQL4 and not MQL5.

Thanks in advance.

The code for both mt4 and mt5 will be exactly the same though