Download MetaTrader 5

multiple orders on start

To add comments, please log in or register
18081961 2016.04.05 13:27 

Hi all,

 I have an ea on four pairs. At first, the ea is working well, but if I close the platform  and open it again in one of the pairs multiple orders start to open.

Could you show me what is wrong?

Thank you in advance


Fernando Carreiro
Fernando Carreiro 2016.04.05 15:36  

You must change/adapt your code, so that when it starts, it first looks over all currently open orders that have the same Symbol and Magic Number and re-calibrate all the variables accordingly so that it continues to work where it left off. Hopefully, the magic number is not used by any other EA.

Use the "OrderHistory()" to find out how many open or pending orders there are and then go over all of them from last to first (important) using the "OrderSelect()" function. For each order verify the, Magic Number, the Symbol and Order Type to make sure they belong to your specific EA and then adjust the states of the EA's internal variables to reflect this information.

Once the EA has "collected" all the orders details and adjusted accordingly, it can then continue to function as before!

whroeder1 2016.04.05 16:34  
EA's must be coded to recover. If the power fails, OS crashes, terminal or chart is accidentally closed, on the next tick, any static/global ticket variables will have been lost. You will have an open order but don't know it, so the EA will never try to close it, trail SL, etc. How are you going to recover? Use a OrderSelect loop to recover, or persistent storage (GV/file) of ticket numbers required.
To add comments, please log in or register