Session Close Reversion
"Price drifts into the close" is a claim that is almost never actually measured per-symbol before being traded. This EA samples the last InpLookbackDays trading days' own return from InpMinutesBeforeClose minutes before a configured session close up to the close itself, using the chart's own bar history matched to each day's target times by iBarShift with a tolerance check - days whose bars do not land close enough to the target times (holidays, thin history, gaps) are skipped rather than silently mismeasured. A trade is only taken when the AVERAGE of those sampled returns clears InpMinDriftPips AND at least InpMinConsistency of the sampled days agreed with the average's own sign. A large average driven by one or two outlier days, with the rest flat or opposite, fails the consistency check and is not traded - this is the difference between a measured seasonal tendency and noise that happened to average out large. Every trade carries its own ATR-based protective stop and is force-closed at the session close regardless of price; the measurement only covers the window up to the close, so the position is never allowed to become an overnight bet the measurement never justified. Notes and limitations - The measurement depends entirely on the chart's own loaded history; a fresh chart with only a few days of bars will report insufficient samples until more history is loaded or accumulates. - Matching each historical day's window to actual bars is approximate (nearest bar within a tolerance) - a broker's occasional schedule shift or a thin session can cause a day to be silently skipped rather than mismeasured. - At most one trade is taken per day, in the window immediately before the close; a bar-close check only re-evaluates once per new bar, so entry timing within the window is not exact to the second. - A historically consistent drift is not guaranteed to persist; this is a mechanical measurement of recent history, not a structural reason for the drift to continue.
Expert advisor · MT5 · v1.0 · Free
About Session Close Reversion
Session Close Reversion is an expert advisor (trading robot) for MetaTrader 5 based on ATR. It can size trades from your balance and risk percent. It has 14 settings, such as Session close hour, Session close minute and Minutes before close. MQL source code included.
Files in the download: SessionCloseReversion.ex5, SessionCloseReversion.mq5, SessionCloseReversion.txt.
Trading robots can lose money. Check every setting and test on a demo account before using real funds.
Settings
| Setting | Default | What it does |
|---|---|---|
| Session close hour | 20 | Server-time hour the session closes |
| Session close minute | 0 | Server-time minute the session closes |
| Minutes before close | 60 | Length of the drift-measurement / holding window before close |
| Lookback days | 20 | Trading days sampled to measure historical drift |
| Min drift pips | 4.0 | Minimum |average drift| over the window, in pips, to trade |
| Min consistency | 0.65 | Minimum fraction of sampled days agreeing on the drift's sign |
| Min samples | 10 | Minimum number of valid sampled days required to trade at all |
| Atr period | 14 | ATR period, used only for the protective stop |
| Stop atr multiple | 1.5 | Protective stop distance, in ATR multiples |
| Risk percent | 0.75 | Risk per trade, percent of equity |
| Magic number | 20260908 | Magic number for orders opened by this EA |
| Slippage pips | 3 | Slippage tolerance, in pips |
| Max retries | 5 | Attempts per trade action before giving up |
| Retry wait ms | 500 | Pause between attempts, milliseconds |
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 → Experts.
- 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 expert advisor from the Navigator onto a chart, check the settings, allow Algo/Auto Trading and press OK.
- Test it first on a demo account or in the Strategy Tester.
Tags: Trading Sessions · Risk & Lot Size · ATR · MT5 Expert Advisor · MQL5 Source Code