Stop Move Behaviour Audit
Many traders move their stop repeatedly on an open trade - trailing it, tightening it on doubt, loosening it on hope - and rarely find out afterwards whether that habit made money or cost it. MQL4 keeps no modification log for an order: OrdersHistoryTotal() returns only the FINAL stop a closed trade had, never a count of how many times it changed. There is no API to recover that history after the fact. This script builds the missing history itself, one run at a time. Every run it compares each currently open order's stop against the value it saw last run, using a small state file in the sandbox to remember between runs, and counts a difference as one move. When a tracked ticket disappears from the open orders list, it has closed since the last run - the script looks it up in terminal history, records its final outcome against the move count observed while it was open, and finalises it permanently in a results file. Run it again, and the summary rebuilds from every trade finalised so far, bucketed by how many times its stop was moved, showing win rate and average net result per bucket. The one real requirement this places on the trader: it can only see a stop move that happened between two runs. Attach it to a chart and run it every few minutes while trades are open (or run it manually whenever you check your terminal) for the move count to be meaningful - running it once a week will merge many moves into what looks like one. Notes and limitations - This is a sampling tool, not a continuous monitor: a stop that was moved twice between two runs and ended up back at its original value is recorded as one move, not two, since only the value at each sampling moment is compared. - Two state files are used in MQL4\Files: StopMoveBehaviourAudit_state.csv (in-progress tracking of currently open tickets, safe to delete to reset tracking) and StopMoveBehaviourAudit_results.csv (permanent record of every finalised trade, deliberately never overwritten - delete it yourself to start the correlation over). - Only market trades (OP_BUY/OP_SELL) are tracked; pending orders are ignored since "stop move behaviour" while resting is a different question. - A ticket that vanishes from open orders without yet appearing in history (a rare timing race between the two calls) is dropped from tracking rather than guessed at, and is not counted in the results file. - Correlation, not causation: this shows what happened alongside stop moves, not proof that the moves caused the outcome.
Script · MT4 · v1.0 · Free
About Stop Move Behaviour Audit
Stop Move Behaviour Audit is a script for MetaTrader 4. It can alert you with a pop-up, sound, email or push message. It has 2 settings, such as Move bucket width and Print closed detail. MQL source code included.
Files in the download: StopMoveBehaviourAudit.mq4, StopMoveBehaviourAudit.txt.
Settings
| Setting | Default | What it does |
|---|---|---|
| Move bucket width | 2 | Trades per "stop moves" bucket in the summary (0,1-2,3-4,...) |
| Print closed detail | false | Print every finalised trade's line, not just the summary |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Scripts.
- Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
- Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the script onto a chart to run it once.
Tags: Trailing Stop & Break-even · Alerts · MT4 Script · MQL4 Source Code