Comment IS NOTHING .

 

int CalculateCurrentOrders(string symbol)
{
int buys=0,sells=0;
//----
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA)
{
if(OrderType()==OP_BUY) buys++;
if(OrderType()==OP_SELL) sells++;
}
Comment("buys",buys,"\n\nSells",sells);
}
//---- return orders volume
if(buys>0) { return(buys);}
else return(-sells);

}

code above,Comment is right,

but below is wrong nothing appear on the left top corner of the chart. plz anyone kindly tell what is wrong,appreciate .

int CalculateCurrentOrders(string symbol)
{
int buys=0,sells=0;
//----
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA)
{
if(OrderType()==OP_BUY) {buys++; Comment("buys",buys,"\n\nSells",sells);}
if(OrderType()==OP_SELL) sells++;
}
//Comment("buys",buys,"\n\nSells",sells);
}

 

int CalculateCurrentOrders( string symbol )
{
   int buys = 0, sells = 0;
   //----
   for( int i = OrdersTotal() - 1; i >= 0; i-- ) 
   {
      if( !OrderSelect( i, SELECT_BY_POS )) continue;
      if( OrderSymbol() == symbol && OrderMagicNumber() == MAGICMA )
      {
         if( OrderType() == OP_BUY ) buys++;
         else if( OrderType() == OP_SELL ) sells++;
      }
   }
   Comment( "buys", buys, "\n\nSells", sells );
   return MathMax( buys, sells );
}

Try this. You were missing a '}'. Not sure if it was just a copy/paste error or if you were compiling it that way. Also, you should process orders in reverse when selecting by position, I have done that here. I replaced break with continue so the loop just starts over at the next order instead of exiting entirely if you get a selection error. Also, your function accepts a parameter called 'symbol' and does not use it. I fixed that, assuming that a call to your function will look like this:

CalculateCurrentOrders( Symbol() );
 
ylxww:

but below is wrong nothing appear on the left top corner of the chart. plz anyone kindly tell what is wrong,appreciate .

if(OrderType()==OP_BUY) {buys++; Comment("buys",buys,"\n\nSells",sells);}
if(OrderType()==OP_SELL) sells++;

If you had an open buy order, then you'ld get a comment with always zero sells.

Once the buy order closes, the comment would be frozen.

 
Anomalous:

Try this. You were missing a '}'. Not sure if it was just a copy/paste error or if you were compiling it that way. Also, you should process orders in reverse when selecting by position, I have done that here. I replaced break with continue so the loop just starts over at the next order instead of exiting entirely if you get a selection error. Also, your function accepts a parameter called 'symbol' and does not use it. I fixed that, assuming that a call to your function will look like this:

I like to simplify even further. You want to select all the EA's orders. Only one indentation is needed.
    for(pos = OrdersTotal()-1; pos >= 0 ; pos--) if (
        OrderSelect(pos, SELECT_BY_POS)                 // Only my orders w/
    &&  OrderMagicNumber()  == magic.number             // my magic number
    &&  OrderSymbol()       == Symbol() ){              // and my pair.
        pips    = OrderProfit()/OrderLots();
Reason: