About Array Problem

 
void CheckOrder()
{
 SellOrderNum=0; 
 BuyOrderNum=0;
 ArraySetAsSeries(BuyOrderOpenPrice,true);
 ArraySetAsSeries(SellOrderOpenPrice,true);
 ArrayResize(BuyOrderOpenPrice,PositionsTotal(),0);
 ArrayResize(SellOrderOpenPrice,PositionsTotal(),0);
 for(int i=PositionsTotal();i>=0;i--)
 {
  if(PositionGetTicket(i) > 0)
  {
   int PositionDirection=PositionGetInteger(POSITION_TYPE);
   string PositionComment=PositionGetString(POSITION_COMMENT);
   
   if(Symbol()==PositionGetString(POSITION_SYMBOL))
   {
    if(PositionDirection==POSITION_TYPE_BUY)
    {
     BuyOrderNum++;
     BuyOrderOpenPrice[i]=PositionGetDouble(POSITION_PRICE_OPEN);
     MaxBuyPrice=BuyOrderOpenPrice[ArrayMaximum(BuyOrderOpenPrice,0,WHOLE_ARRAY)];
    }
    if(PositionDirection==POSITION_TYPE_SELL)
    {
     SellOrderNum++;
     SellOrderOpenPrice[i]=PositionGetDouble(POSITION_PRICE_OPEN);
     MaxSellPrice=SellOrderOpenPrice[ArrayMaximum(SellOrderOpenPrice,0,WHOLE_ARRAY)];
    }
   }
  }
 }
}

Hello guys, does anyone know how to get current orders open price and sort in array(BuyOrderOpenPrice[]) only, but not include closed order(history)? I use above code for checking order, but BuyOrderOpenPrice[] still have closed order open price there. Please help me, Many Thanks!

 

What you are currently building has count==1 but price in a random position. It can not be sorted.

random garbage random garbage price random garbage random garbage
BuyOrderNum++;
BuyOrderOpenPrice[i]=PositionGetDouble(POSITION_PRICE_OPEN);

Instead of building, count==1, price in first position.

price don't care don't care don't care don't care
BuyOrderOpenPrice[BuyOrderNum]=PositionGetDouble(POSITION_PRICE_OPEN);
BuyOrderNum++;
 
William Roeder #:

What you are currently building has count==1 but price in a random position. It can not be sorted.

random garbage random garbage price random garbage random garbage

Instead of building, count==1, price in first position.

price don't care don't care don't care don't care

It’s work now, Thank you very much.