Statistical Session Curfew
Some hours of the trading day are quietly worse for a given account, month after month, and the pattern is easy to miss because the losses are spread thin across many small trades rather than one obvious bad day. This walks the account's closed order history, filtered by an optional magic number, and buckets every trade's realised result (profit plus swap plus commission) by the server hour its position was opened in. An hour is only flagged once it has accumulated a minimum number of trades - a genuine recurring pattern, not one unlucky afternoon - and its average result is a net loss beyond a configurable threshold. The curfew is rebuilt from scratch on a configurable interval (monthly by default), so a bad stretch that has since been addressed drops out of the picture rather than haunting the account indefinitely. MQL4 gives one Expert Advisor no mechanism to intercept or veto another program's OrderSend call, including a different chart running the same strategy. This tool genuinely cannot block a trade by itself, and does not pretend otherwise. What it does is publish the flagged hours as GlobalVariables under a fixed prefix - one flag per hour of the day, plus a single "is the current hour flagged" convenience flag - and any EA that wants to respect the curfew has to explicitly read them before sending an order. That is a convention between cooperating programs, not an enforced gate, and this document says so without dressing it up. Notes and limitations - Advisory only. It cannot force any EA to read the published GlobalVariables, and it cannot intercept or block another program's OrderSend call. - Hour-of-day is server time, as reported by the trade server, not the trader's local time zone or any particular market session's own clock. - A trade's OPEN hour decides its bucket, not its close hour - a trade that lingers into a different hour before closing still counts against the hour it was entered in. - The curfew reflects only the account's own trading history for the filtered magic number; it says nothing about a strategy that has never been run, or one filtered out by the magic number setting.
Expert advisor · MT5 · v1.0 · Free
About Statistical Session Curfew
Statistical Session Curfew is a script for MetaTrader 5. It can alert you with a pop-up, sound, email or push message. It has 6 settings, such as Magic filter, Min trades per hour and Loss threshold money. MQL source code included.
Files in the download: StatisticalSessionCurfew.ex5, StatisticalSessionCurfew.mq5, StatisticalSessionCurfew.txt.
Settings
| Setting | Default | What it does |
|---|---|---|
| Magic filter | 0 | Magic number of trades to analyse; 0 = every magic number |
| Min trades per hour | 8 | Minimum closed trades in an hour bucket before it can be judged |
| Loss threshold money | 0.0 | An hour is cursed when its average P/L is below this (negative = allow small average loss) |
| History lookback days | 180 | Only trades closed within this many days count toward the curfew |
| Rebuild interval days | 30 | Days between full curfew rebuilds |
| Scan interval sec | 3600 | Seconds between rebuild-due checks |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Scripts.
- Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
- Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the script onto a chart to run it once.
Tags: Trading Sessions · Alerts · MT5 Expert Advisor · MQL5 Source Code