Download MetaTrader 5

Last bar open Time

To add comments, please log in or register
Alberto Tortella
526
Alberto Tortella  

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++;
           }   
        }  
     }    
Keith Watford
Moderator
10614
Keith Watford  

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

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

Alberto Tortella
526
Alberto Tortella  

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. 

Keith Watford
Moderator
10614
Keith Watford  

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

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

Alberto Tortella
526
Alberto Tortella  
Thank you! Now it works well
To add comments, please log in or register