how do i calculate my pending order to expire the next day?

 

Hi everyone,


Happy new year to all! Can anyone help me express mathematically the the date time for the end of the day's trading session? I am using pending orders in my robot and I would like to create a formula that will set the expiration date to the end of the current day's trading.. So if I opened a sell limit at 9PM GTM, I want the order to expire at at 12:00:00 am the next day.. =)


Anyone know how to do this, please let me know. Thanks!

 

if

timeseconds==0

&&

timeminutes==0

&&

timehour==0 //(or 12)

thats not the direct code, but you can find the correct functions in the docs

a problem maybe, that your EA dont receives a tick at midnight, so you have to expand the triggertime a little bit like

minute between 0 and 59 and hour == 0 or something like that

 

Hi Meikel,


Thanks for your reply..


I've tried that before, but it keeps getting a 'stack overflow' error.. and so I have to try and use the expiration date instead. And for that to work, I need to be able to calculate the "X" where PendingExpiration = CurrentTime() + X..


I just need to know how do I calculate the difference in seconds between the CurrentTime and 00:00:00 of the next day?


Rgds!
Arnold

 
heyarn:

I just need to know how do I calculate the difference in seconds between the CurrentTime and 00:00:00 of the next day?

at first you have to find out the current day of the year. (or the month)

then you add 1 to this and create a datetime value of this and the other values (year,month,minutes==0,seconds==0) for a timestamp (unix seconds since 1970 etc)

this value in seconds you can subtract with the current time in second since 1970 and you have the difference.

not very clear described from me, but i hope you find the point.

 

datetime t = TimeCurrent();
t = t - TimeHour(t)*60*60 - TimeMinute(t)*60 - TimeSeconds(t); // time at start of today
t = t + PERIOD_D1*60 + PERIOD_H1*12*60; // expiry time at noon next day



 
sxTed:

datetime t = TimeCurrent();
t = t - TimeHour(t)*60*60 - TimeMinute(t)*60 - TimeSeconds(t); // time at start of today
t = t + PERIOD_D1*60 + PERIOD_H1*12*60; // expiry time at noon next day

Or, alternatively:

   datetime t = MathFloor(TimeCurrent() / 86400) * 86400;

That gives you the start of today. The start (midnight) of tomorrow is then t + 86400, and noon tomorrow is t + 129600.

 
i have same question

how i can to close order how has have 1 day?

thx




example

int sellticket=OrderSend(Symbol(),OP_SELLSTOP,0.1,Bid-15*Point,5,Bid-5*Point,Bid-30*Point,NULL,0,TimeCurrent()+3600,Red);


but his don't work

Reason: