Code practices to isolate values from instances of my EA - Suggestions?

 

Hi guys,


I am trying to write a EA that can be attached to multiple Charts.  

My first try on Demo Account showed me that when I attach the EA on two pairs I get the values of my inputs variables shared among the 2 running EA.

For example:

I have a EA that defines the maximum number of open orders for this EA attached to the pair USDCHF

input int max_orders = 3;

When I attach the same EA to the USDJPY chart I also define the max_order for this instance to be 3.

What I would like to see happening is a total of 6 opened orders because it works as a grid EA.  But what I observed is that I get 2 orders for USDCHF and one for USDJPY.

Is there any code practice to avoid that?

 
Documentation on MQL5: Global Variables of the Terminal
Documentation on MQL5: Global Variables of the Terminal
  • www.mql5.com
Global Variables of the Terminal - Reference on algorithmic/automated trading language for MetaTrader 5
 
Do you use a magic number to differentiate between the EA instances?
 
Daniel Castro:
...

Is there any code practice to avoid that?

Yes, fix the bug(s).
 
Drazen Penic: Do you use a magic number to differentiate between the EA instances?
Exactly. Using OrdersTotal directly and/or no Magic number filtering on your OrderSelect loop means your code is incompatible with every EA (including itself on other charts and manual trading.) Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 forum
 
Drazen Penic:
Do you use a magic number to differentiate between the EA instances?

This was my first guess, but I was considering that could be a different approach to promote this kind of isolation between the running EAs.
 

Of course there are many.

You could write a book about this subject alone.

Reason: