Coding the Open Range Breakout Strategy

The following article focuses on a famous intraday trading strategy, the open range breakout. The idea behind this approach is simple: We want to stay at the sidelines during the market open phase and only act afterwards, when there is a breakout out of the opening range. This strategy can be the basis for many intraday trading strategies with various modifications for the entry or different exit rules.

Equilla Code for Open Range Breakout System

First, we start with specifying all inputs. When the market opens, the opening range starts, so we don`t need an input for that. TradingStart ends the opening phase and marks the beginning of the trading phase. The input TradingEnd is for controlling the exit at the end of the day, because we don`t want to hold positions overnight.

Next, we need two variables which collect the highs and lows of the ongoing opening phase. We call them HH and LL. Another two variables act as counters for the number of trades placed. Enabling the algorithm to limit the number of trades during the day. Only one trade is allowed both on the long and the short side. Last, but not least, the variable MP is an abbreviation the prebuilt function MarketPosition.

Open Range Breakout_Inputs_Variables

Phase 1: Opening Range Evolves

When a new trading day begins (line 9), the high and low of the first candle are saved as the high and low in our variables. The variables LongTrade and ShortTrade will be used later for counting the number of executed trades.

Open Range Breakout_Date Condition

After completion of the first intraday bar, the following code section is processed.

The target of this nested loop is to review each bar for updating the highest high and the lowest low of the opening phase so far. It is performed until the opening phase ends. In our case, this is at 4pm local time.

Phase 2: Trading Phase Starts

When the trading phase starts, the code checks if a long trade has already been executed or not (lines 25 and 27). If this is not the case (LongTrade=0), a stop buy order is placed at the high of the opening range. The opposite end of the opening range (the low) serves as loss stop for the long position. This is the core of the open range breakout strategy.

Open Range Breakout_Orders

Accordingly, the same process is performed for the short side. If there is an entry on either the long or short side, the variables LongTrade and ShortTrade are set to 1. This means that if a long trade has already been performed on that trading day, no further long trades are allowed anymore. The same applies to short trades.

Phase 3: Exit At The End Of The Day

Day-trading strategies like the open range breakout exit positions before the market closes. To tell the computer when to exit the position intraday, we use the following condition at the end. By using the input TradingEnd, we can modify (and optimise) the exit time easily. Visualising the open range in the chart is simple, too. We just add a simple drawsymbol command for the variables HH and LL which represent the high and low of the range.

Open Range Breakout_Exit

Open Range Breakout Strategy – Practical Example

After compiling the code, we can apply it to any intraday chart. Here`s an example using the S&P 500 ETF with 5 minute bars. As you can see, a short trade has been triggered after breaking the lower border of the opening range. The position was held until 9.30pm CET.

Open Range Breakout Strategy

Extending the Open Range Breakout Basic Strategy with a Trend Filter

Trading the breakout can be dangerous when the overall trend of the market points into one direction, while the intraday breakout points into the other. Implementing a trend filter based on a higher time frame could improve our strategy. For example, when the market is above the 20 day SMA, we could decide to only take long breakouts intraday and only take short breakouts intraday when prices are below the 20 day SMA.

As described in our previous article, we have to make sure to avoid a common trap in multiple time frame programming. In short: If we want to make use of data from a higher time frame, we have to use the data from the last finished bar, not the current real-time bar. Here`s how to do it:

  • First, we add a new variable, let`s call it TrendFilterDaily (line 15).
  • Then we declare it using the correct reference of daily data by using the [1] statement (line 21).
  • In line 45 and 47, we add a simple condition to control whether trades are allowed on the long or short side, depending on the prevailing trend.

Open Range Breakout_Extended Version Part 2

As you can see on the following figure, now breakouts are only allowed in accordance to the daily trend (bold black line shows the daily simple moving average, overlayed to a 5 minute chart). This enables us to backtest, whether a filter eliminates many unprofitable trades and thus improves overall performance. In some cases, it might be useful to do it the other way round and only trade long breakouts, when the short term trend from the daily time frame is down. Why? Because bear markets tend to have volatile short squeeze rallies.

Open Range Breakout with Trend Filter

Adding a Price Buffer to the Open Range Breakout

If you take a look at breakout strategies like this, many times you`ll see that a trade has been triggered by only a small margin and runs against you afterwards. Here is an example for the S&P 500 ETF in November 2018: After the breakout to the downside, the market went up in the evening session and generated a loss for this short trade.

Open Range Breakout_with Buffer

Of course, we can try to eliminate such trades by adding a small buffer. For example 2 ticks, which prevents such false signals to be triggered. In order to have a general solution independent of the underlying instrument, we decide to use a multiple of the average true range (ATR). This buffer will be added/subtracted from the upper/lower border of the opening range. If you take a look at the code above, you can see how to implement it:

  • In line 22 the ATRBuffer variable is declared.
  • Lines 45 and 47 make use of this buffer which is calculated as a multiple of the input from line 7 and the ATR value from line 22.

The result is that the trade would not have been triggered when we had used 1 ATR as buffer. The breakout simply wasn’t significant enough.

Open Range Breakout with Activated Buffer

Whether adding such a buffer helps performance or not, can be figured out by using the optimiser and calculating the strategy with and without the buffer.

Implementing a Target based on the Size of the Range

The third option for extending our open range breakout strategy is a profit target. In the basic strategy, we just stay in the trade until the end of the session. But why shouldn’t  we exit a trade when it has reached a specific target? For example, when the book profit equals the double size of the opening range size? Being able to turn it on and off, we want to use a switch in the inputs for the target. Here`s how to code it:

  • First, we add an input called ProfTarget(yes,no) to the input section (line 6).
  • In line 23, we calculate the size of the opening range (it is simply the difference of HH and LL).
  • Lines 61 to 65 contain the rules for the profit target.

The following example shows a short trade reaching the profit target. Its size equals the size of the opening range. Of course you can try different targets using the input we created in line 6, to adapt to different markets.

Open Range Breakout with Target


I hope this article is a helpful guide to code your own daytrading breakout strategy. All components described here can be combined in different ways and also extended by other conditions in order to create a robust and profitable strategy. If you would like to dig deeper into the open range breakout, I recommend reading works by Toby Crabel.

Tradesignal® is a registered trademark of Tradesignal GmbH. Unauthorized use or misuse is strictly prohibited. Data by Refinitiv Eikon.
Copyright Terms of use:

3 thoughts on “Coding the Open Range Breakout Strategy

    1. Yes, in the first chart you can see the strategy visualises the highest high and lowest low between 3.30pm CET (market open in the US) and 4.30pm CET.

Leave a Reply

Your email address will not be published. Required fields are marked *

Subscribe to this Blog