//-------------------------------------------- OrderClose loop ---! for(int i=0;i<OrdersTotal();i++){ ulong iTicket=PositionGetTicket(i); if(PositionSelectByTicket(iTicket)&& PositionGetString(POSITION_SYMBOL)==_Symbol){ if(PositionsTotal()>1){ // There is a second order (opposite), so I'm trying to close the first one. if(!trade.PositionClose(iTicket,ULONG_MAX)){ Print("PositionClose error ",trade.ResultRetcode()); return; } } } }
You are using the wrong total.
I suggest to count down from total-1 to 0, specially when closing orders/positions.
You are also using PositionsTotal()>1, totally untrustable in case of EA running on several charts/pairs or several EA running at the same time or account mixed manual/automatic trading.
You are using the wrong total.
I suggest to count down from total-1 to 0, specially when closing orders/positions.
You are also using PositionsTotal()>1, totally untrustable in case of EA running on several charts/pairs or several EA running at the same time or account mixed manual/automatic trading.
Thank you I wasn't noticed that, first loop was correct but second one was wrong. Now it's working perfectly.
Count is forward cause I need to close first order when positionstotal>1. The problem about you're speaking is solved by MagicNumber but I still don't know how to place Magic.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi there, I'm testing my recent translated advisor but I suspect that orders count function is not working properly cause it isn't closing orders.
Here I count Buy and Sell orders, c ode:
Then I try to close first open order when there is an opposite signal, code:
What expert does in backtest is open 1 buy and 1 sell closing no one, it works in MQ4. Need some help, thanks.