counting the open-buy-lots and the open-sell-lots

 

Hello

I'm working at a grid system and for the lots-sices i would like to count the lots.

openselllots = the lots of all open SELL posistions

openbuylots = the lots of all open BUY posistions

double openselllots, openbuylots;

if(OrdersTotal()>0)
for(i=0;i<OrdersTotal();i++){
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic && OrderCloseTime()==0)


{
if(OrderType()==OP_BUY){
openbuylots=OrderLots();

}
if(OrderType()==OP_SELL){
openselllots=OrderLots();
}
}
}

i hope someone can help me!!

thanks

chris

 

 

Before posting please read some of the other threads . . . then you would have seen numerous requests like this one:

Please use this to post code . . . it makes it easier to read.

 

Try this . . .

if(OrderType()==OP_BUY) openbuylots += OrderLots();   //  keep a running total of lots bought


if(OrderType()==OP_SELL) openselllots += OrderLots();   //  keep a running total of lots sold
 

Thank you, ill try it today!!!

 

here is the code, but it does not work, it makes now really big lot-sizes.....

   if(OrdersTotal()>0)
      for(i=0;i<OrdersTotal();i++){
         OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic && OrderCloseTime()==0)
         
         
         {
            if(OrderType()==OP_BUY){ 
            openbuylots += OrderLots();
            }   
            
            if(OrderType()==OP_SELL){
            openselllots += OrderLots();
            }
         }
      }
  
 

Are you initialising the running totals variables before you run the loop ?

if(OrdersTotal()>0)
   {
   openbuylots = 0; openselllots = 0;    //  set the variables to zero
   for(i=0;i<OrdersTotal();i++)
      {
      OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
      if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic && OrderCloseTime()==0)
         {
         if(OrderType()==OP_BUY) openbuylots += OrderLots();
           
         if(OrderType()==OP_SELL) openselllots += OrderLots();
         }
      }
   }
 
  1. initialize the sums to zero before the loop.
  2. You are scanning the open order list, so OrderCloseTime() will ALWAYS be zero.
  3. Always check your return codes
       openbuylots = 0; openselllots = 0;    //  set the variables to zero
       for(iPos=OrdersTotal()-1; iPos>=0; iPos--)
       if (OrderSelect(iPos,SELECT_BY_POS,MODE_TRADES)
       &&  OrderMagicNumber()==magic
       &&  OrderSymbol()     ==Symbol() 
       ){
          if(OrderType()==OP_BUY)  openbuylots  += OrderLots();
          else                     openselllots += OrderLots();
       }
  4. Get in the habit of counting down.
 

hi RaptorUK

thank you for your help.

I'm not a coder so sorry for my stupid question :(.

Your code is working, but there is a little problem after the basket-closes. >> pics. do you know how i could fix that??

 
christion:

hi RaptorUK

thank you for your help.

I'm not a coder so sorry for my stupid question :(.

Your code is working, but there is a little problem after the basket-closes. >> pics. do you know how i could fix that??

How on earth am I supposed to know what you mean by " after the basket-closes. " ? you don't even show the code for it . . . I really have no idea of what you are trying to do.
 

I'm sorry for that, here is the whole code.

It is not my code, I'm just wanna change the grid and the money-managment.

Reason: