Loading…

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 · MT4 · v1.0 · Free

About Statistical Session Curfew

Statistical Session Curfew is a script for MetaTrader 4. 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.ex4, StatisticalSessionCurfew.mq4, StatisticalSessionCurfew.txt.

Settings

SettingDefaultWhat it does
Magic filter0Magic number of trades to analyse; 0 = every magic number
Min trades per hour8Minimum closed trades in an hour bucket before it can be judged
Loss threshold money0.0An hour is cursed when its average P/L is below this (negative = allow small average loss)
History lookback days180Only trades closed within this many days count toward the curfew
Rebuild interval days30Days between full curfew rebuilds
Scan interval sec3600Seconds between rebuild-due checks

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: Trading Sessions · Alerts · MT4 Expert Advisor · MQL4 Source Code

Expert advisors (EA) for MT4 & MT5 · PolyMaria