time at which pending order placed

 

hi,

i am trying to retrieve the time at which a (pending) order was placed. take, for example, a buy stop order placed at some time XXX. now, when the market reaches the entry price the trade is activated. the time at which this happens is accessible through OrderOpenTime(). is there any way of reliably retrieving the original time (XXX) at which the pending order was placed though?

the reason that i want to retrieve this time is i need to find the parameters which were used to calculate the target and stoploss, which are based on the candle preceding the one on which the pending order was placed.

any ideas?

cheers,

andrew.

 

hi,


i dont see such function in trading functions, so maybe you should use variable for that, and write to it CurrentTime in the moment when you send pending order.


regards

Romek

 
oromek:

i dont see such function in trading functions, so maybe you should use variable for that, and write to it CurrentTime in the moment when you send pending order.

yes, that is right. thanks! and, actually, i have tried this approach already, but it breaks when, for whatever reason, the platform is restarted. then you lose all this information. when you restart there is no way of getting back all the times at which the orders were placed. i was trying to find a way of figuring out this time "from first principles". any ideas for that?

 

You could save the variable as a Global variable which the terminal retains on start. Or you could write it to a text file which is probably ovely complicated way of doing it.

Alternatively, you could save the time as part of the OrderComment, and then simply extract it from the comment later when needed.

 

Save the variable as a global variable to prevent loss on restart

https://docs.mql4.com/globals/GlobalVariableSet


I don't work much with pending orders so I'm not positive (I'm sure others will correct me) but I think the pending order would move to the order history pool once it is triggered you slould be able to loop through order history, identify added pending orders and get the time from that.I suspect if you tied that info to the close time, you could match it to the open time of the trade that triggered it. As I say, I might be off the mark with this, but it is the method I would explore.

hth

V

 
collierab:

yes, that is right. thanks! and, actually, i have tried this approach already, but it breaks when, for whatever reason, the platform is restarted. then you lose all this information. when you restart there is no way of getting back all the times at which the orders were placed. i was trying to find a way of figuring out this time "from first principles". any ideas for that?

i used once other solution - i was writing the most important variable values to configuration file. After restart, EA is reading such file and sets all variables appropriately. I know, using global variables may require less work to implement, but it had one important benefit for me - i was able to manually edit all variable values before starting mt4, and EA was exactly in such state that i wanted.


oromek

Reason: