error 129

 

Hello traders,


I have following code which give me error 129 even all looks OK. Any idea ?

Krzysztof


			RefreshRates();
                        double closePrice = NormalizeDouble(MarketInfo(Symbol(), MODE_BID), Digits);
                        Print("Closing short position at ", closePrice, " Bid ", Bid);
                        bool isSuccess = OrderClose(OrderTicket(), OrderLots(), closePrice, 1000, clrNONE);

                        if(!isSuccess)
                          {
                           Print("OrderClose failed with error ", GetLastError());
                           svSetValue(Link,"OP",operation);
                           Sleep(60000);
                           return;
                          }
                        else
                          {
                           svSetValue(Link,"OP",0);
                          }
                       }


2024.01.09 11:27:23.390 tr_traderV2 EURUSD,H1: OrderClose failed with error 129
2024.01.09 11:27:23.390 tr_traderV2 EURUSD,H1: Closing short position at 1.09401 Bid 1.09401
 

I think that error can happen for different reasons, but I can see from the small snippet you posted that "double closeprice" maybe an issue. Try OrderClosePrice() instead.
Also, i can not remember why, but I was taught to use an int where you have isSuccess and have "if(isSuccess<=0). I am sure that this was one of the things that could cause different erroneous errors too when the bool returned a false, when the OrderClose Function actually returned a negative number for whatever reason.

Please post an update after you have tried different things and report what fixed your issue. Most posters do not report that their issue is fixed; leaving their responders "in the lurch", not knowing if they helped or not.

 
Revo Trades #:
OrderClosePrice()

OrderClosePrice() is used to get closing price of already closed order so I think is't not relevant here. I can only close those orders manually


Krzysztof

 
krzysiaczek99 #:

OrderClosePrice() is used to get closing price of already closed order so I think is't not relevant here. I can only close those orders manually


Krzysztof

This is regarding mt4 code, correct? OrderClosePrice() is used to get the bid or ask price of the selected trade. It may not fix your error, however, I know that when i used it, instead of Ask/Bid, especially when using loops, I would get less orrurence of closing related errors. Please try it and see.

 

image of help file in mt4 editor

 
Revo Trades #:

This is regarding mt4 code, correct? OrderClosePrice() is used to get the bid or ask price of the selected trade. It may not fix your error, however, I know that when i used it, instead of Ask/Bid, especially when using loops, I would get less orrurence of closing related errors. Please try it and see.

yes, MT4. OK will try, must wait for next signal and its on daily charts...

 
krzysiaczek99 #:

yes, MT4. OK will try, must wait for next signal and its on daily charts...

ok. sure.

EDIT: i confirmed that many of my most recent mt4 codes use OrderClosePrice() in the OrderClose function -- not that i code in mt4 anymore hahahaha
 

I can confirm it works now after using OrderClosePrice().

2024.01.12 08:41:32.100 tr_traderV2 GBPUSD,H1: Closing long position at 1.27717 Ask 1.27732

so using double closePrice = NormalizeDouble(MarketInfo(Symbol(), MODE_ASK or MODE_BID), Digits);

is not working

Reason: