Using Linear Regression Channels to Trade Ranges


Range trades can be a very effective strategy and are used widely by technical traders.

Figure 1: Linear regression channels
Figure 1: Linear regression channels © forexop

But detecting suitable ranges in charts is the main challenge. Firstly ranges tend to be fluid and continually evolving. Secondly most range finding tools are graphical “shape drawing” utilities which don’t produce any outputs that can be traded on.

These limitations make them of little use for real trading.

Given the above challenges how exactly do we trade ranges profitably? More precisely:

  • How do we identify if the market is ranging?
  • Where is the price within a given range?
  • What is the probability of a price breakout?
  • How should we do this without watching the market 24×5?

This article describes a strategy for trading ranges using adaptive linear regression channels. Adaptive linear regression is a statistical method that can solve these problems. It does this by fitting the price to a chain of channels with each being the optimum fit.

As a benchmark I started with a naïve model that just bought and sold at certain positions in the leading range. This strategy produces good profits for a variety of market conditions and is suited to general use (see results).

I refined the basic strategy to use trending properties and to avoid trading against significant resistance or support levels. The extended model reduced the number of trades but in doing so increased trade profitability.

Why do prices range?

Firstly, let’s try to understand why prices range and under what conditions.

It’s well known that when financial markets are volatile prices tend to overshoot or undershoot fair value. A range is simply the upper and lower confines of these price variations.

Range trading also known as channel trading, means simply to trade the price between these given boundaries. The philosophy behind this is that history repeats more often than not. And that the highest probability state is that the price will tend to remain within the same confines. This being until some event causes a shift in market outlook after which a breakout of the channel can occur.

This “wave effect” of ranges is reinforced by both fundamental and technical traders who attempt to buy at the bottom of the range and sell at the top.

The classic picture most have of a range is a horizontal channel. But it’s also very common for ranges to be superimposed on trends. These give rise to either upwards or downwards sloping channels. Moreover ranges don’t have to be rectangular. They can also be trianglular, wedge shaped or even curved.

In this sense, markets can be said to be “ranging” at one scale or another nearly all of the time.

Linear Regression

When I first looked at this I wanted to come up with a strategy that would dynamically adapt to the market and could be easily automated.

Figure 2: Linear regression – the basic concept
Figure 2: Linear regression – the basic concept © forexop

Standard range finding tools such as those in Metatrader will help you to visually identify ranges. But the problem is these are graphical objects that have to be moved around by hand. They also don’t produce any useful outputs that can be traded on.

A workable range trading strategy requires a more sophisticated setup. It needs to be able to find ranges without guidance and adapt dynamically as they change over time.

To overcome this we created an adaptive linear regression indicator and built a range strategy EA around this.

Briefly, standard linear regression is a statistical method for measuring the relationship between two variables. In our case these are price vs. time. See Figure 2. The linear regression model can tell us for example:

  • When the market is following a predictable price channel
  • The statistical properties of the channel: trend, time, volatility, rate of change
  • An estimate of the future price path
  • When the price is breaking out of the existing channel

We make this adaptive so that the model parameters are able to change as the price line evolves. This produces a continuous set of ranges of “best fit”.

Strategy Goals

The aim of this strategy is to exploit range properties and in doing so produce trades with good risk adjusted returns. These goals are as follows:

  1. Identify lines of high resistance or support
  2. Find the “central axis” of the range
  3. Determine the “range stability”.
  4. Locate any “pitch influences” from major ranges that will impact current prices

Let’s look at these individually.

1. Finding Lines of Resistance and Support

The most likely price pivot points occur at or near the range boundaries. But ranges of any size usually have several other key pivot areas. These include the central axis. In bigger ranges they also include the lines of standard deviation which will mark zones of strong price support and resistance.

Figure 3: Range resistance and support areas
Figure 3: Range resistance and support areas © forexop

For example Figure 3 above shows EURGBP on the hourly chart. The two bold lines mark a distance of 1 standard deviation from the central range axis. These are clearly acting as strong support and resistance. But looking closely you can see that the price is also pivoting at the 0.5 standard deviation lines as well.

Figure 4: Low versus high standard deviation ranges
Figure 4: Low versus high standard deviation ranges © forexop

Standard deviation measures the width or price movement of the range. Basically a range with a high standard deviation is wide, and one with a low standard deviation is narrow. See Figure 4.

2. Identify the Central Axis

The central axis is the main pivot line of the range. In linear regression, the central axis is also the line of best fit.

Knowing the range’s central axis is important for two reasons. Firstly it gives you a baseline to check if the price is trading on the lower side or upper side of the range. For a prominent range, mean reversion becomes important. What this means is that the price will tend to migrate back towards the central axis (the mean) of the range.

The second reason for identifying the central axis is that it tells you the general direction in which the price is trending.

Figure 5: Locating the range’s central pivot line
Figure 5: Locating the range’s central pivot line © forexop

To find the position within the range we set the indicator up to display the distance in standard deviations from the central pivot line. This is the orange line shown in the sub window of Figure 5. For example when the line is at zero the price is exactly at the central pivot line. At +1 it’s at the upper standard deviation. At -2 it’s two standard deviations below the central line and so on.

Also in the lower window in Figure 5 the green line flags when a grid crossing (or bounce) occurs and the blue line shows the slope of the range.

3. Identify the Range Stability

Ranges that are well established over time will give stronger support and resistance to price movements than will “short-lived ranges”. For this reason, the extent of the range is a valuable input to the trading system.

Figure 6: Range size is also a trading input
Figure 6: Range size is also a trading input © forexop

For example, Figure 6 shows a range in GBPUSD on the daily chart (D1). The range lasts for 185 days. Compared to the average of 31 days this is obviously an important structure. Flips between ranges are marked by the range transition line (see Figure 6).

4. Identify Confluence Areas

Areas of confluence are where mutliple support & resistance lines meet. If we drill down to the 30 minute timescale (M30) from the above daily chart we can see that this “older range” has an influence long after it appears to break away from the main channel.

Figure 7 shows the M30 chart for July of the same year. The lines drawn on the chart are those extended from the range in Figure 6 above.

These are known as pitch lines and what the diagram shows is that they have an influence on the price right down to the minute scale. This influence extends long after the original trend has apparently broken.

Figure 7: Identifying pitch lines
Figure 7: Identifying pitch lines © forexop

These can create hidden areas of support and resistance and can work against the current price direction. In the example shown in Figures 6 and 7 the market is trying to break upwards and out of this strong downwards channel.

But the pitch lines from the dominant range (in Figure 6) act as strong resistance to upwards progression of the newly forming trend. The strength of pitch lines reduces the further they are from the central axis of the range. Eventually either the new trend will win over or the original will reassert itself.

Range Strategy

Naïve trading model

As a benchmark we started with a naïve strategy that just bought and sold at certain positions in the leading range. Basically this “sells” the top of the range channel and “buys” the bottom.

We used the hourly (H1) chart and the minimum range length was set to 50 bars. The back test covers a period of 10 years and the spread was set to 21 points. The tests traded one standard lot per trade and used fixed leverage at 1:1.

The naïve strategy is as follows:

SD < –dx1 and SD >-dx2 ⇒ Buy
SD > dx1 and SD < dx2  ⇒ Sell

dx2 > dx1

Here SD is the price distance (in standard deviations) from the central axis of the front channel and dx 1 and dx 2 are input parameters.

Figure 8: Naïve range trading model results
Figure 8: Naïve range trading model results © forexop

Extended trading model

In the next test we used the pitch lines. This was to avoid trading “into” resistance and support levels on the daily scale (D1). We also included the gradient (slope) of the range as an input – thus avoiding trading against strong trends.

Figure 9: Extended range trading model results
Figure 9: Extended range trading model results © forexop

To identify pitch lines the strategy uses a second instance of the indicator at the daily scale (D1).

The extended model reduced the number of trades by nearly one half versus the naïve model. But the profit factor increased to 1.46 from 1.29 with the extended model. The overall profit was also significantly higher at $306k.

The range trade indicator is available here:

Download file
Please login


Price Action Trading

Definitive Guide

Price action trading with candlesticks gives a straightforward explanation of the subject by example. It includes data insights showing the performance of each candlestick strategy by market, and timeframe.

  1. Q1: This system can be back-tested easily? How?

    Q2: How can I get the free version of the indicator you offer here? I’m trying to download it but I am not being able to sign-up. Can you send me a link or tell me what to do?

    • Yes, the example uses it’s own custom expert script. The expert takes the output from the indicator and places the trade orders that result from that signal. Once you have a working EA the back testing will be possible.
      Please see the downloads page for the free indicator versions and follow the links there.

  2. Hi Steve,

    I have the Pro version of this indicator and noticed that sometimes it highlights a range previous to the current one. Is it because the algorithm finds that the previous range is a better fit to price action (even though the current range is still valid)? Or another reason?


    • Actually it should be possible to select any range. The indicator will highlight the newest when there are enough bars.

  3. Hi I first time visit your blogs i really impressed in fact i am a software programmer but i have been working in financial market last 9 years , i have a sound knowledge market statistics. Unfortunately my education background is not statics and pure math so some time face and unable to solve mathematical expression to generalize, Here i read grid trading ,linear regression channel and martingale.

    My question how can generalize for identifying trade, range breakout .


    • Hello, my name is Costas & I have been trading 2 years. I would like to know how is the resistance or support found in examples shown in the above?

      • The indicator uses a sampling method to find places where the price is changing direction if you like. These are weighted as the support/resistance lines.

    • Hi Rahul – You mean a general method for identifying any sort of range breakout at all? Breakouts are highly varied and show in many different contexts. Having a system that handles all of them is going to be a challenge. One of the best early indicators of a breakout I think is changing volatility as I have talked about in this article and others. There’s also some specialized techniques such using retests. I suggest you also look at hedging systems like the straddle trade as well which will give you a pay off if the price moves either way from the break.

  4. Hello Steve,
    Thanks for sharing the strategy but where is free version of the indicator?

  5. Thanks for this great article steve!

    I do a lot of range trading as one of my prefered methods. how is the system know if the range has come to an end or if it is still in progress? I mean it is possible for the range to break and then come back into the original track? So in that way you have two ranges which are really just one. How is a check done for this?

    • The range comes to an end when the current price no longer fits within the existing channel. That means having a break out of some sort. This potential to break is controlled by an “elasticity” setting. So basically the higher this is, the more flexible the range fitting will be. The tighter it is the less flexibity the range has to grow. This means a higher number of narrow ranges will result.

Leave a Reply