One EA across multiple pairs

 

Hey guys,

I'm new to trading and I'm still in the process of figuring out how MT4 & MQL4 work. I've wrote a little EA that, if tested on one pair, executes as intended but if I use the same EA across 2 or more pairs, the S/L and T/P get messed up big time. For example, if two sell orders happen back to back on two different pairs, the S/L is the same for both even though the prices are different. I'm using the same input variable values for both pairs so my question is, can the same EA be used across multiple pairs or is that a thing I shouldn't be doing?

I've attached a screenshot of the erroneous S/Ls.

Files:
 

It can be done - I've been doing that all the time, just that you cannot hard-code your input variables. Consider using global variables, named with the pair as prefix or suffix. Another option is to draw horizontal lines on the chart itself to indicate where you want the S/L and T/P to be.

 
I haven't actually been hard-coding the S/L, I used the built-in Ask and Bid functions along with a global StopLoss variable. Even if I use the same code and put it in different EAs and throw those on the charts (meaning I have a EA for the EURUSD, one for the GBPUSD, etc) it still errors out..
 
Ask and Bid will give you pair-specific values, no issue there. However, your global StopLoss variable will be shared by the EA running on EURUSD and the EA running on GBPUSD. To differentiate the StopLoss value, you should consider having two global variables - each prefixed or suffixed with the pair's name.
 
Works like a charm. I assume it's the same concept for the OrderModify function and it should be a quick fix.
Reason: