Last bar open Time

Back to topics list To post a new topic, please log in or register
avatar
249
Alberto_jazz 2015.04.16 10: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++;
           }   
        }  
     }    
avatar
Moderator
3404
GumRai 2015.04.16 11:31 #
 

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

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

avatar
249
Alberto_jazz 2015.04.16 12: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. 

 

 

 

 

avatar
Moderator
3404
GumRai 2015.04.16 12:55 #
 

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

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

avatar
249
Alberto_jazz 2015.04.16 14:24 #
 
Thank you! Now it works well
Back to topics list  

To add comments, please log in or register