Loading…

Close Tickets Listed In File

Closing a specific handful of tickets out of a large book by clicking through the terminal is slow and error-prone once the list gets past four or five. This script takes the list as a plain text file instead: one ticket number per line, and it closes exactly those tickets and nothing else. A market position is fully closed at the current market price; a pending order is deleted rather than closed, since a pending order has no position to exit. The script tells the two apart automatically per ticket, so one file can mix both kinds without extra input. Blank lines and lines starting with # are ignored, so the file can carry comments explaining why each ticket was listed. Every line in the file is accounted for in the result: closed, deleted, already closed, not currently open, or failed with the broker's reason. That report is written both to the Experts tab and to a CSV file placed next to the input file, so a batch run against, say, every ticket flagged by a risk review leaves a paper trail of exactly what happened to each one - not just a single summary count that could be hiding a handful of quiet failures. Notes and limitations - Only tickets that literally appear in the file are touched. There is no filter by symbol or magic - the file itself is the entire selection criterion, by design. - A ticket that is not currently open (never existed, or already closed) is reported as such and left alone, never treated as an error that stops the run. - The report file is overwritten on every run under the fixed name <InpFileName>.result.csv - rename or move it first if a previous run's report needs to be kept. - File access is sandboxed to MQL4\Files\ (or MQL5\Files\ on the native MQL5 build) by the platform; the input file must be placed there, not anywhere else on disk. - The order the file lists tickets in is the order they are processed, but each ticket is closed independently - there is no attempt to close them as one atomic batch.

Script · MT5 · v1.0 · Free

About Close Tickets Listed In File

Close Tickets Listed In File is an expert advisor (trading robot) for MetaTrader 5. It has 4 settings, such as File name, Slippage points and Max retries. MQL source code included.

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

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

Settings

SettingDefaultWhat it does
File nameclose_tickets.txtFile in MQL5\Files\, one ticket number per line
Slippage points30Maximum acceptable slippage on market closes, points
Max retries5Attempts per ticket before giving up
Retry wait ms500Pause between attempts, milliseconds

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: Pending Orders · MT5 Script · MQL5 Source Code

MQL4 & MQL5 scripts · PolyMaria