Looking for advice about multiple order management in EA

 

I'm writing an EA based on a strategy that uses several predetermined levels to open orders, so the EA needs to manage several orders at once and make sure only one order is opened per price bar, per level so if there are 4 levels a maximum of 4 orders can be opened per price bar, more orders can be opened on subsequent price bars before all the orders are closed when the price reaches another predetermined level.

I was wondering what is the best way to deal with the problem of recovering the strategy after an accidental computer shutdown or reboot or power outage.

I could create special magic numbers for the orders, from which could be extrapolated later the original status of the order, which level it was opened at and which level it should be closed at, for instance,

level 1 = 101 level 2=102 level 3=103 level 4=104

so an order opened at level 1 which should be closed at level 3 would have magic number 101103 and then the price bar at which it was opened can be established using iBarShift on the open time from the trade pool.

The other option would be to use Global variables to hold simalar info about each order so the strategy can be resumed after a system failure.

I was wondering is there any reason why either of those methods should be the preferred way of doing it or is there another better alternative to those two ?

 

If the PC's hard drive fails your Global variables are toast.

If the levels are predetermined can't you relate the orders back to those levels from the price that the order was opened at ?

 
Global variables will not be written to disk unless the terminal is properly closed. Think power failure/OS crash - no update.
 
SDC:
[...]

I was wondering is there any reason why either of those methods should be the preferred way of doing it or is there another better alternative to those two ?

u can write to a file using FileWrite() function, (i don't know if it's a better way)
 

Thanks for your input guys, it looks as if Globals are out, FileWrite() would work unless a hardrive failed so magicnumber or the order comment appear to be best ways to maintain persistant info about each order's opening criteria, I'll use one of those.

Reason: