Download MetaTrader 5
To add comments, please log in or register
Are you a good trader? Become a signals provider and make even more money!
amando
396
amando 2014.08.07 19:09 

hello,

 

i want to check if the last order is minimum one hour old, so i was thinking the

OrderCloseTime()

and datetime

 

are borth using the date from the 01.01.1970 in seconds

when i use my code i get some unexpected results

 i was thinking, i use the order close time minus the actual time and get as result some seconds.

 

but the resualt is far away from the truth, or it only dosent work at the tester 

   if(OrderSelect(1,SELECT_BY_POS,MODE_HISTORY)==true)
     {
      datetime ctm=OrderCloseTime();
      if(ctm>0) Print("Close time for the order 1 ",ctm);
     }
   else
      Print("OrderSelect failed error code is",GetLastError());
      
      
   //datetime date= D'1970.01.01 00:00';
 
  datetime date=D'';
  string str="mydate="+date;
  
  Print (str);
   
  double now = StringToDouble(str);
   //long  StringToInteger (test);
   
   
   Print("Now: ",now);
   double Last = now - ctm;
   Print(Last);
qjol
3243
qjol 2014.08.08 00:29  
  1. OrdersHistoryTotal - 1 is the last order or use a for loop to find the last order
      if(OrderSelect(OrdersHistoryTotal() - 1,SELECT_BY_POS,MODE_HISTORY)==true)
  2. you have to compare it against TimeCurrent
whroeder1
13640
whroeder1 2014.08.08 00:58  
if(OrderSelect(1,SELECT_BY_POS,MODE_HISTORY)==true)
  1. Don't assume. Not the first closed order (zero) not the last (OrdersHistoryTotal()-1)
  2. OrderSelect loop on history, filter by magic number and symbol, Find the latest OrderCloseTime, then compare.
Hongliang Liu
1196
Hongliang Liu 2014.08.08 07:30  

"i want to check if the last order is minimum one hour old...

if(OrderSelect(1,SELECT_BY_POS,MODE_HISTORY)==true)

order position 1 is usually not the last closed order.

you can use the for loop to get each history order's close time,and find the latest one(the biggest int),use some filter if needed.

then compare with current time.

/
To add comments, please log in or register