When working through orders always count down not up . . .
for(i = 0; i < OrdersTotal(); i++){ // <--- No for(i = OrdersTotal()-1; i >= 0; i--){ // <--- Yes
. . . this may be part of your problem . . even if it's not it's still good practice.
Does your OrderSelect work ? always check . . .
OrderSelect(i, SELECT_BY_POS); // <--- No if(OrderType() == OP_SELL && OrderMagicNumber() == MAGICBOL) OrderClose(OrderTicket(), OrderLots(), Ask, 3); if( OrderSelect(i, SELECT_BY_POS) && OrderType() == OP_SELL && OrderMagicNumber() == MAGICBOL) // <--- Yes OrderClose(OrderTicket(), OrderLots(), Ask, 3);
RaptorUK:
When working through orders always count down not up . . .
. . . this may be part of your problem . . even if it's not it's still good practice.
I don't know why, but it works with:
for(i = OrdersTotal()-1; i >= 0; i--)
Thanks :)
Arkenis:
If you count up and then Close an order you will skip one . . .
I don't know why, but it works with:
Thanks :)
RaptorUK:
If you count up and then Close an order you will skip one . . .
If you count up and then Close an order you will skip one . . .
Exact ! Thanks
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
Hi,
I'm currently doing an EA which use Bollinger Bands, it sends Buy/Sell Order when I want but I also wanted it to close all Buy/Sell Position when it opened a new Sell/Buy Position, and it doesn't work like it should.. Sometimes, my function sends buy order like it has to, while there is previous sell order, and it doesn't close it, so that I have buy and sell orders at the same time..
I've attached a screen with the backtest:
Here is my close function, it closes orders sometimes, but not always, like if it couldn't close several orders at the same time:
And the orderSend function: