I see the probable reason.
.
It is the construction:
"for(int e=OrdersTotal()-1;e>=0;e--)"
Inside this construction there are:
1. one function "OrderSelect()"
2. many functions "OrderClose()"
After first succesful "OrderClose()" using valid "OrderTicket()" of selected order all others "OrderClose()" will use invalid "OrderTicket()", that is ticket of another order, "error code 4108 = invalid ticket" !
Solution:
1. Instead of "for(int e=OrdersTotal()-1;e>=0;e--)" use
"
int N = OrdersTotal()-1;
for(int e=N;e>=0;e--)
"
2. For single "OrderSelect()" use single "OrderClose()".
.
And advice: use "OrderClosePrice()" instead of any other price in function "OrderClose()", for example, "OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),0,Gold);".
.
Good Luck !
Thank you Sir, :)
ksrohit2712:
The same code works properly if i don't include the calculatelotsize() and the if(){lots/2} condition.
double lotStep = MarketInfo(Symbol(), MODE_LOTSTEP); int digits = 0; if(lotStep <= 0.01) digits = 2; else if(lotStep <= 0.1) digits = 1; lots = NormalizeDouble(lots, digits);
Lots must be a multiple of LotStep. but there is no reason why it must be 0.1 or 0.01. Lots/2 also will not be correct.double minLot = MarketInfo(Symbol(), MODE_MINLOT), LotStep = MarketInfo(Symbol(), MODE_LOTSTEP), size = MathFloor(size/LotStep)*LotStep; if (size < minLot){ ...
- Always count down when modifying orders. Must for delete/close or when other EAs or human can add, change, or delete

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I don't know why this is happening and how to over come it but it's getting me nuts.
The same code works properly if i don't include the calculatelotsize() and the if(){lots/2} condition. But when i include these the EA fails to close the orders...
I tried assigning indivdual tickets to each trade but even then it does the same thing. Please point out my mistakes and the way to avoid them. SLB,TPB,SLS,TPS are stoploss and take profit for buy(B) and sell(S).
U can try to modify the values if required....
Thanks and Regards,
Rohit