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(); } } }
- initialize the sums to zero before the loop.
- You are scanning the open order list, so OrderCloseTime() will ALWAYS be zero.
- 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(); }
- 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??
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??
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.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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