Can someone please check why I cannot delete an order on MT5 EA.
1. I have placed a stop
loss order manually
2. Order shows up @ Trade
Tab of the Toolbox Panel.
3. Using Debug Mode,
variable ticket recognizes order number
4. After delete trade; line execution,
order still remains on Trade Tab
Problem fixed using a different approach (don´t know if is the best one but anyway ...)
void Apaga_Pending_Orders() { int ord_total=OrdersTotal(); if(ord_total>0) { for(int i=ord_total-1;i>=0;i--) { ulong ticket=OrderGetTicket(i); ZeroMemory(mrequest); mrequest.action=TRADE_ACTION_REMOVE; // immediate order execution mrequest.magic=0; mrequest.order=ticket; mrequest.symbol=_Symbol; // currency pair mrequest.volume=1; mrequest.type=ORDER_TYPE_SELL_STOP; mrequest.comment="YouTrade"; // comment if(OrderSend(mrequest,mresult)) { if(mresult.retcode==TRADE_RETCODE_PLACED || mresult.retcode==TRADE_RETCODE_DONE) { Print("[TICKET] Order ticket: ",mresult.order," retcode: ",mresult.retcode); } else { Print("Order error: ",GetLastError()," retcode: ",mresult.retcode); ResetLastError(); return; } } else { Print("Order Send error."); ResetLastError(); return; } } } }
Problem fixed using a different approach (don´t know if is the best one but anyway ...)
Can someone please check why I cannot delete an order on MT5 EA.
1. I have placed a stop
loss order manually
2. Order shows up @ Trade
Tab of the Toolbox Panel.
3. Using Debug Mode,
variable ticket recognizes order number
4. After delete trade; line execution,
order still remains on Trade Tab
Hi Marcelo, note that the first code you post will filter all orders just by symbol name, so this is very risky, in my opinion, principally for BM&FBovespa.
The second code is not enough too, since don't test any symbol and if you just need do delete pending orders this is not right.
The big problem here is that several of this details are, in my opinion, very risk to BM&FBovespa, and not so critical to Forex market, but most of MQL5 site examples are regarding Forex.
A really good practice, if there is one, would be you double check all your OrderSend() removing pending orders commands, for instance, reading the deals history (this is very same the visual inspection you are doing).
But for BM&FBovespa, there is latency, and probably this is not so simple to code.
Hi Marcelo, note that the first code you post will filter all orders just by symbol name, so this is very risky, in my opinion, principally for BM&FBovespa.
The second code is not enough too, since don't test any symbol and if you just need do delete pending orders this is not right.
The big problem here is that several of this details are, in my opinion, very risk to BM&FBovespa, and not so critical to Forex market, but most of MQL5 site examples are regarding Forex.
Hi Rogerio,
Can you explain what you mean (I highlighted what is not clear to me) ? Thank you.
Can someone please check why I cannot delete an order on MT5 EA.
1. I have placed a stop loss order manually
Do you mean a stop order ? (BUY_STOP or SELL_STOP). With MT5, a stoploss is not a pending order but is linked to an other order (market or pending).
2. Order shows up @ Trade
Tab of the Toolbox Panel.
3. Using Debug Mode,
variable ticket recognizes order number
4. After delete trade; line execution,
order still remains on Trade Tab
There are several reasons why this code doesn't delete your order, as said by Malacarne and Figurelli, you always have to check the return code, whatever method you are using to send trade request.
OrderGetTicket() already select your order, you don't need to use OrderSelect() too.
Returns ticket of a corresponding order automatically selects the order for further working with it using functions.
for(int i=OrdersTotal()-1;i>=0;i--) { ulong ticket=OrderGetTicket(i); //--- This code remove all pending orders for the chart's symbol //--- where you are running the code if(OrderGetString(ORDER_SYMBOL)==Symbol()) { CTrade *trade=new CTrade(); // You don't really need to use pointer, a "normal" variable will be good bool res=trade.OrderDelete(ticket); //--- add error checking ... delete trade; } }
- www.mql5.com
Problem fixed using a different approach (don´t know if is the best one but anyway ...)
Some fields are not needed to delete a pending order. You don't print the error when OrderSend return false :
mrequest.action=TRADE_ACTION_REMOVE; // immediate order execution mrequest.magic=0; mrequest.order=ticket; mrequest.symbol=_Symbol; // currency pair mrequest.volume=1; mrequest.type=ORDER_TYPE_SELL_STOP; mrequest.comment="YouTrade"; // comment if(OrderSend(mrequest,mresult) && (mresult.retcode==TRADE_RETCODE_PLACED || mresult.retcode==TRADE_RETCODE_DONE)) { Print("[TICKET] Order ticket: ",mresult.order," retcode: ",mresult.retcode); } else { Print("Order error: ",GetLastError()," retcode: ",mresult.retcode); ResetLastError(); return; }P.S: I don't think you can get a return 1008 (TRADE_RETCODE_PLACED) when deleting a pending order. Not sure though, can someone confirm ?
Some fields are not needed to delete a pending order. You don't print the error when OrderSend return false :
P.S: I don't think you can get a return 1008 (TRADE_RETCODE_PLACED) when deleting a pending order. Not sure though, can someone confirm ?Hi Rogerio,
Can you explain what you mean (I highlighted what is not clear to me) ? Thank you.
For sure, this is just risk advices about the use of such codes, principally for the BM&FBovespa pilot project, that I suppose is the main idea of Marcelo, and regarding these codes managing his real accounts.
Unfortunately, for stock exchanges in general, and this is my opinion, MT5 is not so secure and portable yet as for Forex (despite we still have some minor problems at Forex, several of them discussed at this Forum).
In this sense, and if you want and have your time to contribute and discuss about it, I created a topic in the Portuguese area and you are welcome there (https://www.mql5.com/pt/forum/23409) to contribute with your critics and ideas (even in English).
Anyway, if possible, I would like to know your opinion about the use of such codes at BM&FBovespa, as maybe I'm wrong and there are no risks here.
Thank you.
- www.mql5.com
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Can someone please check why I cannot delete an order on MT5 EA.
1. I have placed a stop loss order manually
2. Order shows up @ Trade Tab of the Toolbox Panel.
3. Using Debug Mode, variable ticket recognizes order number
4. After delete trade; line execution, order still remains on Trade Tab