last order filter

 

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);
 
  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
 
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.
 

"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.

Reason: