Expert Advisors • Indicators • Scripts • Libraries

MQL.RobotFX.org is the biggest collection of MetaTrader expert advisors (MT5 & MT4), indicators, scripts and libraries that can be used to improve trading results, minimize risks or simply automate trading tasks

Metatrader 5 Indicator | Session Range Breakout | Source Code Included

RobotFX curates the best open-source MetaTrader code to inspire your trading automation.

Image for Session Range Breakout

A MetaTrader 5 chart-window indicator that calculates a completed session's high and low from M1 bars, optionally draws its range and alerts on the first break in each direction. Times use the broker's server time.

Input Default Meaning
InpSessionStart 09:00 Session start, HH:MM , inclusive.
InpSessionEnd 10:00 Session end, exclusive. An earlier clock time means the next day; equality with start is invalid.
InpLineEnd 17:00 First occurrence of this clock time strictly after session end. Equality means the next day.
InpHistoryDays 10 Completed session start dates to inspect, 1–365; dates without bars count. A session in progress does not displace the previous completed session.
InpShowRectangle true Draw the session rectangle.
InpShowLines true Draw high and low lines from session end until line end.
InpRectangleColor clrLightSteelBlue Rectangle color.
InpHighColor clrLimeGreen High line color.
InpLowColor clrTomato Low line color. Colors must be valid RGB values.
InpLineStyle STYLE_SOLID Line style. MT5 may display non-solid styles as solid when width exceeds 1.
InpLineWidth 1 Line width, 1–5.
InpEnableBuffers true Populate the two iCustom buffers.
InpBreakMode BREAK_TOUCH Live chart price strictly outside the range, or BREAK_CLOSE for a chart bar closing strictly outside.
InpPopup true Show popup alerts.
InpPush false Send push notifications; configure them in MT5.
InpEmail false Send email; configure it in MT5.
InpInstanceId 1 Instance identifier: 1–8 ASCII letters or digits. Assign distinct identifiers to instances in the same chart window.

Place SessionRangeBreakout.mq5 in MQL5/Indicators , compile in MetaEditor, and attach it to a chart. The symbol and timeframe are those of the chart. The always-declared, non-plotted iCustom buffers are index 0 (high) and 1 (low). When enabled, values appear on chart bars whose opening times fall from session end through line end, inclusive; all other values are EMPTY_VALUE . The most recent session takes precedence if windows overlap.

Unique stair-step trend trading with the Stairsteps Expert Advisor. Innovative approach for consistent results. Learn more.

Only the most recent completed session with an active extension is eligible for alerts, once per direction. Touch uses Bid on Bid charts or Last on Last charts and requires a new symbol tick. Close mode requires a newly observed closed bar opening at or after session end, with the next bar opening no later than line end; an arriving tick can follow the boundary. Attach, restart, and history recalculation prime earlier observed breaks without alerting. When the indicator has observed the session before its end, its first new tick in the end minute can trigger a live break. If the first tick arrives later, earlier breaks are conservatively primed and an initial live break may be missed. The indicator cannot recover live notifications while the terminal is offline or ticks are unavailable; only the previously observed bar is eligible after a gap.

The range uses available M1 bars in [session start, session end) , allowing market-closure gaps. It checks for synchronized history with first-date coverage at or before the requested start before copying rates, and skips a session with no M1 bars. An unavailable or short M1 history produces at most one log message per initialization; the indicator waits or skips unavailable sessions and retries. Synchronization does not guarantee the broker supplied every expected bar. Historical touch priming uses M1 highs and lows, not tick order; close priming uses chart-timeframe history. Fixed 24-hour server-date increments, daylight-saving changes, missing history and market closures can affect results.

Full buffer initialization occurs when MT5 requests a full calculation. Subsequent rebuilds clear the configured history window, including the expired part of the previous window once when it moves, before filling it again. Objects use a stable SRB_<ChartID>_<subwindow>_<instance ID>_ prefix and are cleaned on initialization and removal. Assign a different InpInstanceId to each instance in the same chart window; instances with the same ID share a namespace and can remove or overwrite each other's objects. Invalid IDs are rejected during initialization. This indicator places no trades and uses no DLL or WebRequest.

Complement community code with advanced automation from RobotFX.

79016

Best MetaTrader Indicators + Profitable Expert Advisors