datetime is integer representing the amount of seconds elapsed from midnight, 1 January, 1970
If I understand correctly, chart time is independent of datetime value - no connection.
Sleep(1000) is sleep for one second regardless of time frame running under.
Please be sure read docs, yes?
also https://book.mql4.com/ Programming in Algorithmic Language MQL4 is great resource...
hth
The expiration integer is in seconds.
Suppose you want are using H1 chart and want to keep the orders for the next 6 bars,
The expiration should be = 6 (bars) * 60 (minutes) * 60 (seconds)
which is equal to 21600 seconds.
I'm using the following function to close the bars after certain of time (ClosePendingInSeconds)
for short positions. You may change the function for your long ones.
...
...
...
extern int ClosePendingInSeconds = 43200;
...
...
...
void SellStopOrderFollowUp(){
int ticket;
for (int i=0; i<OrdersTotal(); i++) {
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
if (OrderMagicNumber()==MAGIC ) {
if (OrderType()==OP_SELLSTOP) {
if (TimeCurrent()-OrderOpenTime()>=ClosePendingInSeconds){
OrderDelete(OrderTicket(),Yellow);
}
}
}
}
}
}
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
What is the time scale unit? If I am in 4H time frame e write 1000 what does it mean? And what if in 15m I write the same datetime? How long are them?
Thanks.
SA