Loading…

Backup Rotation Manager

Any tool that exports its own state to MQL4\Files (a settings dump, a trade log, a hand-tuned CSV) eventually gets accidentally overwritten or corrupted, and by then the previous good version is long gone because nothing was keeping a history of it. Manually copying a file with a timestamp in the name works until it is forgotten a few times in a row, and an unmanaged pile of backups just moves the mess one folder over. This script copies a chosen source file into a backup folder with a YYYYMMDD_HHMMSS timestamp appended to its name, then looks at every existing rotated backup for that same source file, sorts them by timestamp, and deletes the oldest ones beyond the configured keep count. Every run leaves exactly InpKeepCount (or fewer, on early runs) backups on disk, oldest automatically pruned. The keep-N bookkeeping is driven by parsing the timestamp back out of each backup's own filename rather than reading filesystem modify times, since MQL4 file functions expose no reliable modify-time read across brokers and builds - the filename itself is the more portable source of truth here. Notes and limitations Only backs up one named file per run - to rotate several files, either run the script once per file with a different InpSourceFile each time, or duplicate the script under different names. It does not recurse into folders. Backups are stored inside the MQL4\Files sandbox alongside the source, not copied anywhere outside the terminal's data folder - this is not a disaster-recovery tool protecting against a lost or corrupted terminal installation, only a rolling undo history for accidental in-sandbox overwrites. The keep-N pruning only recognises backups matching its own <source>.<15-character timestamp>.bak naming pattern; a backup file renamed or created by another tool will not be counted or pruned. There is no restore step built into this script - restoring means copying the wanted .bak file back over the original by hand (or with a file manager), since the safer action is a deliberate manual choice rather than an automatic overwrite of the current file.

Script · MT4 · v1.0 · Free

About Backup Rotation Manager

Backup Rotation Manager is a script for MetaTrader 4. It can alert you with a pop-up, sound, email or push message. It has 3 settings, such as Source file, Backup folder and Keep count. MQL source code included.

Files in the download: BackupRotationManager.mq4, BackupRotationManager.txt.

Settings

SettingDefaultWhat it does
Source fileMyTool_State.csvFile under MQL4\Files to back up
Backup folderBackupsSub-folder of MQL4\Files to store backups in
Keep count10How many rotating backups to keep (oldest deleted beyond this)

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Scripts.
  3. Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
  4. Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the script onto a chart to run it once.

Download the PDF guide

Tags: Alerts · MT4 Script · MQL4 Source Code

MQL4 & MQL5 scripts · PolyMaria