Download MetaTrader 5
To add comments, please log in or register
Track Market top sellers!
Alberto Tortella
480
Alberto Tortella 2015.04.16 08:57 

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
7887
Keith Watford 2015.04.16 09:31  

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

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

Alberto Tortella
480
Alberto Tortella 2015.04.16 10:14  

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
7887
Keith Watford 2015.04.16 10:55  

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

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

Alberto Tortella
480
Alberto Tortella 2015.04.16 12:24  
Thank you! Now it works well
/
To add comments, please log in or register