because with i=0, you close first order with index [0].
second order changes from index[1] to index[0]
Then with next loop .. oops, no more orders.
Change
for(i=0;i<OrdersTotal();i++)
to
for(i=OrdersTotal()-1;i>=0;i--)
Count down and always test return codes.
for(int pos=OrdersTotal()-1; pos >= 0; i--) if( OrderSelect(i,SELECT_BY_POS) && OrderMagicNumber() == MagicNumber // Only my orders, && OrderSymbol() == Symbol() // on my chart, && OrderType() > OP_SELL){ // pending only. static OP.text[]={ "OP_BUY", "OP_SELL", "OP_BUYLIMIT", "OP_SELLLIMIT", "OP_BUYSTOP", "OP_SELLSTOP" }; if (OrderDelete(OrderTicket())) Print(OP.text[OrderType()]," Deleted"); else Print( "Error Deleting ",OP.text[OrderType()]," ",GetLastError()); }
brewmanz:
because with i=0, you close first order with index [0].
second order changes from index[1] to index[0]
Then with next loop .. oops, no more orders.
Change
to
Duh... Thanks so much. This is why I ask the experts. Thanks again.
WHRoeder:
Count down and always test return codes.
Count down and always test return codes.
Thanks for your help. Can you please explain OrderType() > OP_SELL ? Also the use of static OP.text[] . Your code is very efficient.
tparimore:
Thanks for your help. Can you please explain OrderType() > OP_SELL ? Also the use of static OP.text[] . Your code is very efficient.
Thanks for your help. Can you please explain OrderType() > OP_SELL ? Also the use of static OP.text[] . Your code is very efficient.
Many programmers writes like >OP_SELL to show they high "skill" of codding. :))))
It is for use less PC resources. But code becomes bad readed.
OP_BUY | 0 | Buy operation |
OP_SELL | 1 | Sell operation |
OP_BUYLIMIT | 2 | Buy limit pending order |
OP_SELLLIMIT | 3 | Sell limit pending order |
OP_BUYSTOP | 4 | Buy stop pending order |
OP_SELLSTOP | 5 | Sell stop pending order |
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Could someone tell me why the code below only closes one open trade per bar? e.g. I have two open orders. On each new bar ClosePending() is called. However, only one will close this bar and the second closes the next bar? Thanks in advance.