void CancelOrder() { // check all orders for(int i = OrdersTotal() - 1; i >= 0; i--) // count all currency pair orders { // get the ticket number ulong OrderTicket = OrderGetTicket(i); // delete the pending order trade.OrderDelete(OrderTicket); } // end of for loop }
Just call this custom function in OnTick().
Also, I use:
#include <Trade\Trade.mqh>
CTrade trade;
hamedham65 TürkOğlu:
In MQL5 you must first select each order (using OrderSelect) and then check its type to ensure it’s a pending order (Buy/Sell Limit or Stop). Also, it’s best to loop backward when deleting orders.I want script that close all pending orders When OnTick accures.
I tested this but not happens:
#include <Trade\Trade.mqh> CTrade trade; void OnTick() { int total = OrdersTotal(); // Loop backward since we are removing orders for(int i = total - 1; i >= 0; i--) { if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { int type = (int)OrderGetInteger(ORDER_TYPE); // Check if it's a pending order if(type == ORDER_TYPE_BUY_LIMIT || type == ORDER_TYPE_SELL_LIMIT || type == ORDER_TYPE_BUY_STOP || type == ORDER_TYPE_SELL_STOP) { ulong ticket = OrderGetInteger(ORDER_TICKET); if(ticket > 0) { if(!trade.OrderDelete(ticket)) { Print("Failed to delete pending order ticket ", ticket, " Error: ", GetLastError()); } else { Print("Deleted pending order ticket ", ticket); } } } } } }

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
I want script that close all pending orders When OnTick accures.
I tested this but not happens: