Linear Regression Line

Contributor Image
Written By
Contributor Image
Written By
Dan Buckley
Dan Buckley is an US-based trader, consultant, and part-time writer with a background in macroeconomics and mathematical finance. He trades and writes about a variety of asset classes, including equities, fixed income, commodities, currencies, and interest rates. As a writer, his goal is to explain trading and finance concepts in levels of detail that could appeal to a range of audiences, from novice traders to those with more experienced backgrounds.
Updated

Linear regression, when used in the context of technical analysis, is a method by which to determine the prevailing trend of the past X number of periods.

The Best Brokers For Linear Regression Line Trading

Click a broker for details
  1. 1
    FOREX.com
    Active Trader Program With A 15% Reduction In Costs

    Ratings
    4.9 / 5
    4 / 5
    4.3 / 5
    4.6 / 5
    4.6 / 5
    4.3 / 5
    4.8 / 5
    4.5 / 5
    3.6 / 5
    3.8 / 5

    $100
    0.01 Lots
    1:50
    NFA, CFTC
    Forex, Stocks, Futures, Futures Options
    MT4, MT5, TradingView, eSignal, AutoChartist, TradingCentral
    Wire Transfer, Credit Card, Debit Card, Visa, Mastercard, Skrill, Neteller, ACH Transfer
    USD, EUR, GBP, CAD, AUD, JPY, CHF, PLN
  2. 2
    NinjaTrader

    Ratings
    4.3 / 5
    2.8 / 5
    2.9 / 5
    4.3 / 5
    4.5 / 5
    4 / 5
    4 / 5
    4 / 5
    3 / 5
    3.2 / 5

    $0
    0.01 Lots
    1:50
    NFA, CFTC
    Forex, Stocks, Options, Commodities, Futures, Crypto
    NinjaTrader Desktop, Web & Mobile, eSignal
    ACH Transfer, Debit Card, Wire Transfer, Cheque
    USD
  3. 3
    eToro USA
    Invest $100 and get $10
    Securities trading offered by eToro USA Securities, Inc. (“the BD”), member of FINRA and SIPC. Cryptocurrency offered by eToro USA LLC (“the MSB”) (NMLS: 1769299) and is not FDIC or SIPC insured. Investing involves risk. https://www.daytrading.com/ is not an affiliate and may be compensated if you access certain products or services offered by the MSB and/or the BD.

    Ratings
    4.3 / 5
    3 / 5
    3.9 / 5
    3.4 / 5
    4 / 5
    3 / 5
    4.3 / 5
    4.5 / 5
    4.3 / 5
    4 / 5

    $100
    $10
    SEC, FINRA
    Stocks, Options, ETFs, Crypto
    eToro Trading Platform & CopyTrader
    ACH Transfer, Debit Card, PayPal, Wire Transfer
    USD
  4. 4
    Interactive Brokers

    Ratings
    4.5 / 5
    3.5 / 5
    4.6 / 5
    4.3 / 5
    3.3 / 5
    3 / 5
    4.4 / 5
    4.3 / 5
    4.3 / 5
    4.5 / 5

    $0
    $100
    1:50
    FCA, SEC, FINRA, CFTC, CBI, CIRO, SFC, MAS, MNB, FINMA, AFM
    Stocks, Options, Futures, Forex, Funds, Bonds, ETFs, Mutual Funds, CFDs, Cryptocurrencies
    Trader Workstation (TWS), IBKR Desktop, GlobalTrader, Mobile, Client Portal, AlgoTrader, OmniTrader, eSignal, TradingCentral
    Cheque, ACH Transfer, Wire Transfer, Automated Customer Account Transfer Service, TransferWise, Debit Card
    USD, EUR, GBP, CAD, AUD, INR, JPY, SEK, NOK, DKK, CHF, AED, HUF

Unlike a moving average, which is curved and continually molded to conform to a particular transformation of price over the data range specified, a linear regression line is, as the name suggests, linear. It takes a certain number of user-defined periods and plots a linear line that best fits the general trend.

To clarify, it is not simply taking the current price and the price from X number of periods ago and drawing a line between the two. The activity in between the two points is every bit as critical.

For example, in the particular 50-day period in the S&P 500 below, the net gain of the market is positive. Yet the linear regression line is negatively sloped. This has to do with a strong down-move over the course of this period. Most forms of linear regression are based on the mean or average, which makes it sensitive to outliers. Since the mean price over this period was below where it currently stands, the linear regression line is negatively sloped.

linear regression line

The shape of the linear regression line is simply designed to represent yet another way to track the market’s trend.

Conceptually, linear regression implies that it can predict how an output will change based on an input. In this case, it’s simply using previous price data to predict the general trend of future price data. This is, of course, a naïve assumption, but trends have a way of persisting over time until the information embedded in a market materially changes.

If we set the linear regression line to a 100-day period, we see the line markedly take a different shape:

linear regression line technical analysis

For trend traders, this might present confusing signals to have the 50-day and 100-day regression lines be so profoundly different. Which one is more “correct”?

First, it is never recommended to use any given indicator in isolation. Being in buy/long trades when a X-period regression line is pointing up and sell/short trades when a X-period regression line is pointing down will not be a profitable trading strategy.

It should ideally be made to fit your trading timeframe. Those who trade with the intention of holding positions over the course of years might apply a 200-day linear regression line to a daily chart. Someone who holds positions minutes or hours might apply a 20-period linear regression line to a 5-minute chart.

If paired with a moving average, it would make sense to have them both be the same period for equal comparison’s sake. For example, here’s the linear regression line paired with a 50-period simple moving average (SMA).

linear regression line moving average

If you’re a trend follower and trust the signals that the linear regression line and SMA give you on these particular periods, you’d probably pass on anything trend-related.

Examples of the Linear Regression Line Within a Broader System

The linear regression line can be relevant when identifying the trend within a larger trading system.

Many trading systems are based on the premise that once all indicators match up, a trade signal is thereby given in a particular direction.

For example, we could invent a trading system that involves trade entries based on trading with the trend according to a 100-period linear regression line and 100-period moving average.

With respect to price reversals, we can use Keltner channels. For Keltner channels, we’ll use 20-period bands and a 3x multiple of the average true range.

Our rules are:

  1. Trade only with the trend, meaning both the 100-period linear regression line and 100-period moving average are in agreement.
  2. When the above rule is true, take long trades when price hits the bottom band of the Keltner channel. Likewise, when both the linear regression line and moving average are in agreement in a downtrending market, a touch of the upper band of the Keltner channel would be a signal to go short.
  3. To exit a trade, we can use either a shift in the trend – i.e., the slope of either the linear regression line or moving average changes (opposite the direction of the trade) – or a touch of the linear regression line.

Also note that backtesting this strategy is particular difficult given that the linear regression line changes shape continually. How and where it’s displayed on the chart currently is purely dependent on the market at the current moment, not where it was at some point in the past. The best you can do is infer on the basis of knowing how linear regression lines are made to fit a particular data set.

Example #1

Let’s see how this would have worked out on a daily chart of WTI crude oil:

linear regression line tradeHere we have one or two trade signals (shown through the two green arrows), depending on whether you’re willing to take the same setup more than once. We see both trend confirmation tools pointing up.

We ignore price’s touch of the top band on the way up as those trades would have gone opposite the trend. But we do get a touch of the bottom band twice. This presented a solid setup to take a long trade in the direction of the up-trend of the market.

Some trader’s might take just the initial touch and ignore the subsequent touch since it’s fundamentally the same trade idea. Moreover, it might constitute “doubling down” on a position and could make one’s book (i.e., current set of live/open trades) more concentrated and dependent on a certain outcome to profit.

The trade was exited upon a touch of the linear regression line (white line).

Example #2

Let’s apply it to a daily chart of the USD/SEK (US dollar versus the Swedish krona).

With this currency pair in a downtrend, we see confluence with a down-sloping 100-period linear regression line, down-sloping SMA, and touch of the upper band on the Keltner channel.

linear regression keltner channel

Based on the chart and our rules stipulated above, this trade would still be open if our close signal is a touch of the linear regression line. However, it would be closed if we were more flexible and extended it to a touch of the SMA or if we added a center line in the Keltner channel.

Conclusion

A linear regression line is an easy-to-read way of obtaining the general direction of price over a past specified period. Unlike a moving average, which bends to conform to its weighting input, a linear regression line works to best fit data into a straight line.

Linear regression lines will be more dependent on the period of the timeframe considered relative to moving averages. It’s rare that there will be wide dispersions in the general gradation of a moving average between, for example, 50 and 100 periods. There can, however, be a big difference between a 50-period linear regression line and a 100-period regression line.

Note the difference below.

50-period linear regression line + 50-period SMA

linear regression line moving average

100-period linear regression line + 100-period SMA

linear regression line moving average

A linear regression line should not be used a system itself. Rather it should be used in the context of a larger trading system – mechanical or otherwise – that uses other technical indicators, price, candlestick patterns, support and resistance levels, and/or fundamental analysis to improve the accuracy of trading decisions.