Loading…

Session Strategy Scheduler

An EA that behaves differently by session usually ends up with a stack of TimeHour()-based if/else statements, one per session, that grows harder to audit every time a session boundary or a new strategy variant gets added. This header replaces that stack with an array of SSessionWindow entries - name, strategy ID, a day-of-week bitmask, and a start/end minute of day - so adding a session or changing its hours is one array line, and ResolveActiveStrategy answers "which strategy, if any, is active right now" by scanning the array in order and returning the first match. Ordering the array is itself the tool for resolving an intentional overlap (a "London/New York overlap" strategy layered on top of both base sessions), rather than an undefined last-write-wins outcome. Two details a lot of session-switching code gets wrong are handled explicitly. First, a session that crosses midnight (Asia's typical 23:00-07:00 window) needs its late-night half matched against "today" and its early-morning half matched against "yesterday's occurrence" of the same window - IsInsideWindow checks both halves separately using the day mask, so a plain start<end comparison never silently drops the wrap-around portion. Second, a fixed holiday calendar (a date-only list, time of day ignored) checked before any window - not merged into the window logic - so "no strategy on Christmas" is one array entry rather than a special case threaded through every session's own hours. DST is the one part of this problem MQL4 genuinely cannot solve on its own - there is no timezone database and no reliable server-side signal that a broker just rolled its clock forward or back. Rather than pretend otherwise, this header takes InpDstOffsetMinutes as a plain input the trader updates twice a year (added to server time before the day/minute split), documents it as a manual value, and applies it consistently everywhere a time comparison happens. Notes and limitations - DST is not computed automatically - there is no timezone database available to MQL4. InpDstOffsetMinutes is a manual value the trader keeps current; getting it wrong shifts every window by the same fixed amount rather than causing a crash or an obviously wrong result, so it is worth checking after any known clock change. - Holiday matching is date-only. A half-day holiday, or a holiday that only affects one of several configured strategies, needs a second holiday list or a per-window exception - this header only supports "no strategy at all runs on this date". - When more than one window covers the same moment, the first match in array order wins. Order the array deliberately when windows are meant to overlap. - This header never reads account or market state and never trades - it only answers "which strategy ID is active right now", leaving what each ID means entirely to the caller.

Script · MT5 · v1.0 · Free

About Session Strategy Scheduler

Session Strategy Scheduler is a script for MetaTrader 5. It has 1 setting, such as Dst offset minutes. MQL source code included.

Files in the download: SessionStrategyScheduler.mq5.mqh, SessionStrategyScheduler.txt, SessionStrategySchedulerDemo.ex5, SessionStrategySchedulerDemo.mq5.

Settings

SettingDefaultWhat it does
Dst offset minutes0Added to server time to get local session time; update twice a year

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 → Scripts.
  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 script onto a chart to run it once.

Download the PDF guide

Tags: Trading Sessions · MT5 Script · MQL5 Source Code

MQL4 & MQL5 scripts · PolyMaria