Power failure

 

Hi!

Yesterday, an EA was running and it had already sent a couple orders, when there was a power failure. When I turned the computer back on,

the orders were still there (Stop loss and take profit had not been reached) but, even though I re-ran the EA, it was not doing what it was supposed to,

and I had to manually close the orders. It's as though the EA lost any kind of reference to the orders that were already in.

I usually select orders with OrderSelect and SELECT_BY_POS... maybe I need to select orders by ticket, in order to keep this reference?

Or what could be causing this?

 
Can you explain in plain English (without using code) what you think should have happened.
 

When you have a power failure you will lose any flags you set, statics, and arrays your EA might have been using to keep track of open orders you should write a recovery function to get the open orders from the order pool, identify them by the EA magic number, and re-enter them into any arrays you are using for order tracking and then to reset any flags your EA uses to identify which orders should be closed.

put the function call to the recovery function in init()

 
changowero:

Hi!

Yesterday, an EA was running and it had already sent a couple orders, when there was a power failure. When I turned the computer back on,

the orders were still there (Stop loss and take profit had not been reached) but, even though I re-ran the EA, it was not doing what it was supposed to,

and I had to manually close the orders. It's as though the EA lost any kind of reference to the orders that were already in.

I usually select orders with OrderSelect and SELECT_BY_POS... maybe I need to select orders by ticket, in order to keep this reference?

Or what could be causing this?

Oh dear. I really wonder how long you wait to close those orders? Use the PHONE to close, for goodness sake.

 
changowero:
but, even though I re-ran the EA, it was not doing what it was supposed to,
I usually select orders with OrderSelect and SELECT_BY_POS... maybe I need to select orders by ticket, in order to keep this reference?
  1. EA's must be coded to recover - yours doesn't properly - you'll have to post the code.
  2. Two choices, select by position (on tick or on startup) or remember the ticket in permanent storage (file write/file read/file update, file name per pair/tf/mn)
 
diostar:

Oh dear. I really wonder how long you wait to close those orders? Use the PHONE to close, for goodness sake.


Actually, the power came back on, and there was no problem with the orders. The only issue is that it wasn't done automatically, I had to do it myself... which

beats the whole purpose of having an EA xD

 
WHRoeder:
  1. EA's must be coded to recover - yours doesn't properly - you'll have to post the code.
  2. Two choices, select by position (on tick or on startup) or remember the ticket in permanent storage (file write/file read/file update, file name per pair/tf/mn)


The weird thing is I already select orders by position, so I don't know why it is not working.

I guess I will probably go with the file write/read option. Let's see how that works.

Thanks!

 
changowero:


The weird thing is I already select orders by position, so I don't know why it is not working.

I guess I will probably go with the file write/read option. Let's see how that works.

You are already correctly selecting the orders - changing that will NOT fix the problem - post the code.
 
SDC:

When you have a power failure you will lose any flags you set, statics, and arrays your EA might have been using to keep track of open orders you should write a recovery function to get the open orders from the order pool, identify them by the EA magic number, and re-enter them into any arrays you are using for order tracking and then to reset any flags your EA uses to identify which orders should be closed.

put the function call to the recovery function in init()

Agree with SDC.

I experience the same problem before because I did not do the init() to recover;

You can test it on a demo account, turn off the EA and turn it back on to see if something is funny

 

What SDC posted is very specific, for example it wouldn't apply to my code.

I suspect that changowero needs to find the error in his code before adding, what may be, unnecessary complexity to it.

 
I recalled some previous thoughts on this issue last night. And you know what?


This SHOULDN'T be the case because ever since MQL4 alpha version, when they introduced the Magic Number, this was to circumvent the problem of EAs not able to recognise their orders when stoppages DO happen at the client. Like what happen to yours.

Recall this was one of the most debated issue of the MQL predecessors, where we had no other choice but to keep re-initing (that famous orderInit() thingy all the time). And still, this wont do the job.

EA MUST recognise their orders, no matter what has happened, or about to happen. MetaQuotes folks realised this, so that's the Magic Number came in, right into the orderSend. So, no one needs to cry anymore over this.

Now, you ARE giving me the creeps, dejavu??

Reason: