Last bar open Time

 

Hi all, I don't know how to recall the last bar open time.

Could you help with the below code? I need to replace the string "LAST BAR OPEN TIME".

Thank you!!! 

 

total = OrdersTotal();
  Num_Order_Long_6  = 0;
  Num_Order_Short_6 = 0;
  
  for(cnt=0;cnt<=total;cnt++)
     {
     OrderSelect(cnt, SELECT_BY_POS, MODE_HISTORY);
     if (OrderSymbol()==Symbol() && OrderMagicNumber()==1  &&  OrderOpenTime()>= LAST BAR OPEN TIME  )
        {  
        if (OrderType()==OP_BUY)
           { 
           Num_Order_Long_6++;
           }
        if (OrderType()==OP_SELL)
           { 
           Num_Order_Short_6++;
           }   
        }  
     }    
 

The open time for the current bar is Time[0]

The open time for the last completed bar is Time[1] 

 

Ok, now it works with Time[1].

 

The problem is that if I write  

total = OrdersTotal();
  Num_Order_Long_6  = 0;
  Num_Order_Short_6 = 0;
  
  for(cnt=0;cnt<=total;cnt++)
     {
     OrderSelect(cnt, SELECT_BY_POS, MODE_HISTORY);
     
        if (OrderType()==OP_BUY)
           { 
           Num_Order_Long_6++;
           }
        if (OrderType()==OP_SELL)
           { 
           Num_Order_Short_6++;
           }   
         
     }    

 

It returns   Num_Order_Long_6 > 0 and it's ok because I have an order in the history trades.

 

If I write

 

total = OrdersTotal();
  Num_Order_Long_6  = 0;
  Num_Order_Short_6 = 0;
  
  for(cnt=0;cnt<=total;cnt++)
     {
     OrderSelect(cnt, SELECT_BY_POS, MODE_HISTORY);
     if (OrderSymbol()==Symbol() && OrderMagicNumber()==1  &&  OrderOpenTime()>= Time[1]  )
        {  
        if (OrderType()==OP_BUY)
           { 
           Num_Order_Long_6++;
           }
        if (OrderType()==OP_SELL)
           { 
           Num_Order_Short_6++;
           }   
        }  
     }    

 

It gives me 0 and I don't understand why. The magic numer and the symbol are ok. 

 

You are using OrdersTotal() as a counter, but checking history

Use OrdersTotal() for open trades and OrdersHistoryTotal() when checking history 

 
Thank you! Now it works well
Reason: