Discussing the article: "Automating Trading Strategies in MQL5 (Part 42): Session-Based Opening Range Breakout (ORB) System"

 

Check out the new article: Automating Trading Strategies in MQL5 (Part 42): Session-Based Opening Range Breakout (ORB) System.

In this article, we create a fully customizable session-based Opening Range Breakout (ORB) system in MQL5 that lets us set any desired session start time and range duration, automatically calculates the high and low of that opening period, and trades only confirmed breakouts in the direction of the move.

The Opening Range Breakout (ORB) is a classic intraday momentum strategy that capitalizes on the initial directional bias established at the start of a trading session. We define an "opening range" as the high and low formed during the first few minutes (typically 5–60 minutes) after the market opens, then wait for the price to break decisively above the range high (bullish breakout) or below the range low (bearish breakout) and enter in the direction of the break. The premise is simple but powerful: the opening range often represents the battle between buyers and sellers as the market digests overnight news and order flow, and a clean breakout signals that one side has won control, frequently leading to a sustained directional move. The system is generally easy. Have a look below at the different setups we could have.

ORB STRATEGY SETUPS

Our plan is to create a fully session-flexible ORB system that works on any instrument and any trading session (New York, London, Asian, or even custom openings).  We will allow users to set the exact start time. For example, 09:30 for the NYSE or 08:00 for London. Users will also be able to define the range duration in minutes. The system will automatically calculate the true high and low on the selected timeframe within that window. If needed, users can enable multiple bar-close confirmations to validate a breakout.

The algorithm will execute only one trade per direction per session. We will offer two types of stop-loss and take-profit calculations: dynamic (based on the range size) and static, with customizable risk-reward ratios. Points-based trailing stops will also be available, activating after a minimum profit threshold is reached. In addition, the tool will provide rich chart visualization. This includes filled range rectangles, vertical markers for session start and end, persistent high/low levels, and entry arrows.

Visualization is equally important in our case, as you might have noticed by now, for clarity.

Author: Allan Munene Mutiiria

 
Hi Allan and thanks for your continuing contributions , nicely put together than you , I was wondering if you have any solutions for automating the opening time ? generally I use  broker time change but it is not always accurate for me as I am in NZ my broker is in AU there are factors like austalias offset and times when there is a tokyo offset and a new york offset . I have had trouble getting this to work , any suggestions appreciated  . chat gpt gives me  me a scipt that checks each coutnries daylight saving dates, was wondering if there was a more eloquent solution
 
linfo2 #:
Hi Allan and thanks for your continuing contributions , nicely put together than you , I was wondering if you have any solutions for automating the opening time ? generally I use  broker time change but it is not always accurate for me as I am in NZ my broker is in AU there are factors like austalias offset and times when there is a tokyo offset and a new york offset . I have had trouble getting this to work , any suggestions appreciated  . chat gpt gives me  me a scipt that checks each coutnries daylight saving dates, was wondering if there was a more eloquent solution

Hello. Thanks for the kind feedback. You can define the time in your code by using the local time instead of the broker's time or you can define yours. See example.

Local time:

TimeLocal()

You can also use direct time as per your computer's settings using the trade server:

TimeTradeServer()

GMT Time:

TimeGMT()

You could also define your dedicated date and time as below:

datetime my_time = D'2025.11.27 11:07'
MqlDateTime my_struct_time;

It is all upon you to choose the best approach. Thanks.

 
linfo2 #:
Hi Allan and thanks for your continuing contributions , nicely put together than you , I was wondering if you have any solutions for automating the opening time ? generally I use  broker time change but it is not always accurate for me as I am in NZ my broker is in AU there are factors like austalias offset and times when there is a tokyo offset and a new york offset . I have had trouble getting this to work , any suggestions appreciated  . chat gpt gives me  me a scipt that checks each coutnries daylight saving dates, was wondering if there was a more eloquent solution

Your problem is not clear enough. But you can try the extensive Local Timezones and Local Session Hours library or more simple TimeServerDaylightSavings. Without time adjustments you can't reliably test your strategy on a history which usually affected by DST and timezone switches. Or probably you want Determine Broker's Daylight (DST) schedule to detect timezone changes online.

Unfortunately, built-in MQL5 API does not provide a ready-made and more eloquent solution.

Local Timezones and Local Session Hours
Local Timezones and Local Session Hours
  • 2024.02.28
  • www.mql5.com
Class to access to the local time for the specified location, as well as time zone information and the local trading session hours.