last sell entry price returning zero but last buy entry price returning correct price, help pls

 
hi guys I have this function to return the value of last entry price on Buy and Sell they are almost the same but its weird the function for buy is returning me the correct value but on the function for sell is returning me zero. This are the code

for buy :
double LastEntryBuy()
{
double LastEntryBuy=0;

for(int i=0; i<CurrentOpenBuyTrade() ;i++)
{
   if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)==true)
       {
         if(OrderSymbol()==Symbol() && OrderType() == OP_BUY)
         {
           LastEntryBuy = OrderOpenPrice();                                    
         }       
       }
   }
   return (LastEntryBuy);
}

For Sell that returns zero:

double LastEntrySell()
{
double LastEntrySell=0;

for(int i=0; i<CurrentOpenSellTrade() ;i++)
{
   if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)==true)
       {
         if(OrderSymbol()==Symbol() && OrderType() == OP_SELL)
         {
           LastEntrySell = OrderOpenPrice();                                 
         }
         
       }
   }
   return (LastEntrySell);
}

thank you in advance :)

 
for(int i=0; i<CurrentOpenBuyTrade() ;i++)

I don't know what your function returns, but you should be using OrdersTotal().

 
Keith Watford:

I don't know what your function returns, but you should be using OrdersTotal().

Hi sir, its returning the number of current open Buy "CurrentOpenBuyTrade()" and current open Sell "CurrentOpenSellTrade()"

 
mark692:

Hi sir, its returning the number of current open Buy "CurrentOpenBuyTrade()" and current open Sell "CurrentOpenSellTrade()"

Do you have any current sell orders open?
 

yes I do have. While observing it now, it turns out that it only happens when both code on buy and sell is turned on. If i only use Sell it work properly.

 
mark692:

yes I do have. While observing it now, it turns out that it only happens when both code on buy and sell is turned on. If i only use Sell it work properly.

So probably one function is interfering with another due to nesting or a variable conflict?
 
clemmo:
So probably one function is interfering with another due to nesting or a variable conflict?

yes maybe sir hmmmm this is giving me a headache lol, the problem occurs because this function "LastEntrySell()" retrun zero everytime i  the buy is on,

 
mark692:
hi guys I have this function to return the value of last entry price on Buy and Sell they are almost the same but its weird the function for buy is returning me the correct value but on the function for sell is returning me zero. This are the code

for buy :

For Sell that returns zero:

thank you in advance :)

The problem is with  this CurrentOpenSellTrade(), check it!!

 
Tiecheng Fu:

The problem is with  this CurrentOpenSellTrade(), check it!!

that was im thinking sir here is my codes

on buy:

int CurrentOpenBuyTrade()
{
int ordercountbuy=0;

for(int i=OrdersTotal()-1;i>= 0 ;i--)
{
   if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)==true)
       {
         if(OrderSymbol()==Symbol() && OrderType() == OP_BUY)
         {
           ordercountbuy++;
         }
       }
   
}
return (ordercountbuy);
}

on Sell

int CurrentOpenSellTrade()
{
int ordercountsell=0;

for(int i=OrdersTotal()-1;i>= 0 ;i--)
{
   if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)==true)
       {
         if(OrderSymbol()==Symbol() && OrderType() == OP_SELL)
         {
           ordercountsell++;
         }
       }
   
}
return (ordercountsell);
}
 
mark692:
hi guys I have this function to return the value of last entry price on Buy and Sell they are almost the same but its weird the function for buy is returning me the correct value but on the function for sell is returning me zero. This are the code

for buy :

For Sell that returns zero:

thank you in advance :)

place this one instead...its working...OrdersTotal is better choice

for(int i=0; i<OrdersTotal();i++) {
      OrderSelect(i, SELECT_BY_POS);
      if(OrderType() == OP_SELL )
         LastEntrySell = OrderOpenPrice();}
 

Keith Watford:

for(int i=0; i<CurrentOpenBuyTrade() ;i++)

I don't know what your function returns, but you should be using OrdersTotal().

mark692:

Hi sir, its returning the number of current open Buy "CurrentOpenBuyTrade()" and current open Sell "CurrentOpenSellTrade()"

Why would you want to use that?

I repeat 

you should be using OrdersTotal().