I am trying to close partial orders, see snippet of my code...
PROBLEM AND ISSUE
when i close single part of a trade, i often get an error "ticket is invalid".
how can i fix this? eg if i have an open trade that is size of 0.10, and i want to close 0.01 of the trade, i get the error, not always, but maybe 1 out of 4 times that i attempt to do partial closure.
have you checked that it is using the right ticket number on those occasions?
yep,
as you can see: that ticket was already closed.
if(b >= 2) if(AvgBuyPrice > 0 && Bid >= AvgBuyPrice) { // if(!OrderClose(BuyMaxTic, iMinLots,Bid, iSlippage, clrRed)) // if(!OrderClose(BuyMinTic, BuyMinLot,Bid, iSlippage, clrRed)) done = false; if(BuyMaxTic > thr_int && BuyMinTic > thr_int) done = PartyClose(BuyMaxTic,BuyMaxLot <= iStartLots ? iMinLots : (double)MathCeil(BuyMaxLot / iMinLots) * iMinLots,Bid); if(done) PartyClose(BuyMinTic,BuyMinLot,Bid); }
This is bit of code i use to send the order. as you can see, the OrderSend command is only sent 1 time, so i do not understand why it appears that mt4 has tried to closed the 1 trade a 2nd time.
This is bit of code i use to send the order. as you can see, the OrderSend command is only sent 1 time, so i do not understand why it appears that mt4 has tried to closed the 1 trade a 2nd time.
If the order is already closed, and you are getting this error your code must still be using the old ticket number and submitting it again suggesting that the close logic of your program is still being activated despite the order having been closed.
So make sure that you are clearing out the variable that stores the ticket number as soon as it is closed... and only attempting to close if there is an order to be closed...
and debugging....
https://www.mql5.com/en/articles/654
https://www.metatrader5.com/en/metaeditor/help/development/debug
- www.mql5.com
If the order is already closed, and you are getting this error your code must still be using the old ticket number and submitting it again suggesting that the close logic of your program is still being activated despite the order having been closed.
So make sure that you are clearing out the variable that stores the ticket number as soon as it is closed... and only attempting to close if there is an order to be closed...
ok. thanks for your help. i have not made changes to the code yet, but the reading you posted looked promising: i have not cleared the ticket number after the first successful close, as you suggested might be the cause. I clear it upone the next new tic, but not after the successful closing of the ticket. Thanks again.
- 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 am trying to close partial orders, see snippet of my code...
PROBLEM AND ISSUE
when i close single part of a trade, i often get an error "ticket is invalid".
how can i fix this? eg if i have an open trade that is size of 0.10, and i want to close 0.01 of the trade, i get the error, not always, but maybe 1 out of 4 times that i attempt to do partial closure.