Loading…

Delete Pendings By Type

Stops and limits are opposite trades. A buy stop above the market is a breakout entry; a buy limit below it is a mean-reversion entry. Traders who use both hold them at the same time on purpose, and when the market resolves it is normal to want one whole class gone and the other left exactly where it is. A blanket "delete all pendings" cannot express that, so people do it by hand from the Trade tab, sorting by type and right-clicking down the list. That works until the list is long, and then it works until you misclick. This script is the same idea with four switches instead of one - six on MQL5. Tick the types you want cleared. Everything else stays. The types you ticked are echoed into the log and repeated in the confirmation dialog, spelled out in words, before anything is deleted. That readback has stopped more mistakes in practice than the confirmation itself, because it turns "did I tick the right boxes" into something you can actually read. The traps underneath are the same ones that make any pending-order script worth downloading rather than writing. In MQL4, positions and pending orders share a single pool. OrdersTotal returns both, and the type field is all that separates them. The type switchboard in this script is a closed list: buy limit, sell limit, buy stop and sell stop each map to their own input, and OP_BUY and OP_SELL reach no branch at all. There is no setting, no combination of settings, and no order state that lets it delete a live position - not because it is filtered out, but because there is nothing for it to match. The pool re-indexes the moment an order leaves it, so deleting while walking it forwards silently skips about half the book. This script collects tickets first and then deletes by ticket, which is also the only way to check and report each result on its own. And the type is tested twice. Once when the list is built, and once again on the order actually selected at delete time - because a buy stop can trigger and become a live position in the milliseconds between the two, and the ticket alone will not tell you that it has. An order that changed under the script is reported as skipped rather than deleted or failed, since nothing went wrong. Every result is checked. Temporary refusals - server busy, off quotes, no connection, trade context held by an EA on another chart - are retried with a pause. Permanent ones are not, because retrying them only burns time. The summary separates deleted from skipped from refused. Notes and limitations - It deletes pending orders. It does not close positions, and it does not remove stop losses or take profits, which belong to positions rather than to this pool. - All types are ticked by default. That is the safe default for a script whose confirmation dialog reads the selection back to you, but it does mean an unmodified run behaves like a plain delete-all. Check the dialog. - An order frozen by the broker - typically one inside the freeze level with price approaching it - cannot be deleted while that lasts. The condition usually clears within a second or two, so a frozen refusal is retried for as many attempts as you allow and only reported as a failure if it survives them all. - Orders that trigger mid-run are reported as skipped. The script cannot un-trigger them. - There is no undo, and no record of what was deleted beyond the Experts log. Note anything you intend to re-place before you run it. - Type is a property of the order, not of your intention. An order placed as a hedge and an order placed as an entry look identical if they are the same type. Use the magic filter when that distinction matters.

Script · MT5 · v1.0 · Free

About Delete Pendings By Type

Delete Pendings By Type is an expert advisor (trading robot) for MetaTrader 5. It places pending buy/sell stop or limit orders. It has 11 settings, such as Delete buy limit, Delete sell limit and Delete buy stop. MQL source code included.

Files in the download: DeletePendingsByType.ex5, DeletePendingsByType.mq5, DeletePendingsByType.txt.

Trading robots can lose money. Check every setting and test on a demo account before using real funds.

Settings

SettingDefaultWhat it does
Delete buy limittrueDelete buy limit orders
Delete sell limittrueDelete sell limit orders
Delete buy stoptrueDelete buy stop orders
Delete sell stoptrueDelete sell stop orders
Delete buy stop limittrueDelete buy stop limit orders (MQL5 only)
Delete sell stop limittrueDelete sell stop limit orders (MQL5 only)
Current symbol onlyfalseRestrict to this chart's symbol
Magic filter-1Magic number (-1 deletes every magic)
Max retries5Attempts per order before giving up
Retry wait ms500Pause between attempts, milliseconds
Confirm firsttrueAsk for confirmation before deleting

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Experts.
  3. Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
  4. Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the expert advisor from the Navigator onto a chart, check the settings, allow Algo/Auto Trading and press OK.
  6. Test it first on a demo account or in the Strategy Tester.

Download the PDF guide

Tags: Breakout · Pending Orders · MT5 Script · MQL5 Source Code

MQL4 & MQL5 scripts · PolyMaria