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

To add comments, please log in or register
Daniel Castro
116
Daniel Castro  

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?

Marco vd Heijden
Moderator
8158
Marco vd Heijden  
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
Drazen Penic
2765
Drazen Penic  
Do you use a magic number to differentiate between the EA instances?
Alain Verleyen
36041
Alain Verleyen  
Daniel Castro:
...

Is there any code practice to avoid that?

Yes, fix the bug(s).
whroeder1
17943
whroeder1  
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
Daniel Castro
116
Daniel Castro  
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.
Marco vd Heijden
Moderator
8158
Marco vd Heijden  

Of course there are many.

You could write a book about this subject alone.

To add comments, please log in or register