Loading…

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

SettingDefaultWhat it does
Session close hour20Server-time hour the session closes
Session close minute0Server-time minute the session closes
Minutes before close60Length of the drift-measurement / holding window before close
Lookback days20Trading days sampled to measure historical drift
Min drift pips4.0Minimum |average drift| over the window, in pips, to trade
Min consistency0.65Minimum fraction of sampled days agreeing on the drift's sign
Min samples10Minimum number of valid sampled days required to trade at all
Atr period14ATR period, used only for the protective stop
Stop atr multiple1.5Protective stop distance, in ATR multiples
Risk percent0.75Risk per trade, percent of equity
Magic number20260908Magic number for orders opened by this EA
Slippage pips3Slippage tolerance, in pips
Max retries5Attempts per trade action before giving up
Retry wait ms500Pause between attempts, milliseconds

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Experts.
  3. Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
  4. Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the expert advisor from the Navigator onto a chart, check the settings, allow Algo/Auto Trading and press OK.
  6. Test it first on a demo account or in the Strategy Tester.

Download the PDF guide

Tags: Trading Sessions · Risk & Lot Size · ATR · MT5 Expert Advisor · MQL5 Source Code

Expert advisors (EA) for MT4 & MT5 · PolyMaria