SuperTrend Trading Strategy with Linear Regression

Kshitiz Khandelwal
Mudrex
Published in
7 min readMay 9, 2020
supertrend trading strategy with linear regression

The SuperTrend indicator is simply one of the easiest trend trading system. It was developed by Olivier Seban and as the name suggests, it is a trend following indicator. It makes use of Average True Range (ATR) as a part of its calculations which takes into account the volatility of the market. Nonetheless it does give fake signals in sideways moving markets which is why we will make use of the concept of market cycles with Linear Regression to confirm a trending market first and then use SuperTrend to generate buy/sell signals for our SuperTrend Trading Strategy on Mudrex.

SuperTrend

The SuperTrend indicator is plotted over the price chart of the stock or the index. The indicator line changes its colour between green and red based on the price moment in the underlying asset. When the stock price turns greater than the indicator value, a buy signal can be generated. At this stage, the indicator colour turns green and you can also see a crossover of the price above the indicator. When the stock price turns lesser than the indicator value, a sell signal is generated . At this stage, the indicator colour turns red and you can also see a crossover of the price below the indicator.

Calculation of the SuperTrend signal line is a bit complicated consisting of multiple if-else conditions with the help of ATR and can be found here. The final signal is constructed with the help of just two parameters- period and multiplier. The default parameters are 10 for the period of Average True Range (ATR) and 3 for its multiplier.

supertrend signal
SuperTrend Indicator

Linear Regression

SuperTrend does not predict the direction. Rather, once the direction is established it will guide you to initiate a position and suggests you to stay in the position till the trend sustains. This is where the Linear Regression of the stock price comes into play.

Linear Regression works by taking various data points in a sample and providing a “best fit” line to match the general trend in the data using the least square fitting method. Traders go long when the Linear Regression Indicator turns up, and they go short when this indicator turns down. The Linear Regression line hints to where the price would be expected making the indicator more responsive than a moving average.

The Magic of Market Cycles

Markets move in four phases; understanding how each phase works and how to benefit is the difference between floundering and flourishing.

  1. Accumulation Phase: The market has bottomed, and early adopters see an opportunity to jump in and enter the trade at the very beginning of the trend.
  2. Mark-up Phase: When the market seems to be trending up, and the bullish sentiment continues before a consolidation at the top.
  3. Distribution Phase: Sentiment turns mixed to slightly bearish, prices are choppy, sellers prevail, and the end of the trend is near.
  4. Mark-down Phase: Active traders try to sell and exit their trades, while early adopters look for signs of a bottom so they can get back in.

A market cycle can last anywhere from a few weeks to a number of years, depending on the market in question and the time-frame at which you look. While there is no way to predict the duration of a particular phase, we can play safe by believing that the phases will occur in a cycle. Using Linear Regression, we can make profits off the trending markets during the mark-up and mark-down phase while close our trades during the consolidated accumulation and distribution phase.

market cycles
The Four Phases of Market Cycles

Setting Up

We will be using Linear Regression as a filter to identify the market direction. The Linear Regression line is a statistical tool that identifies the best straight line fit through the price. The smaller the look-back period of Linear Regression, the more closely it follows the price. However, since we only want to detect the slope of the line, we will use a large enough look back period which gives us fairly smooth results.

We’ll use the comparison of the SuperTrend signal and the Closing Price to generate buy and sell signals once the predominant trend is established.

Bullish Scenario

  1. Predominant uptrend is confirmed when the slope of the Linear Regression line is positive. This can be done by checking that the current value of the Linear Regression line is greater than the value in the near past.
  2. Once the uptrend is established, enter the trade when the Closing Price is greater than the SuperTrend signal i.e. the colour of the SuperTrend signal is green.

Bearish Scenario

  1. Predominant downtrend is confirmed when the slope of the Linear Regression line is negative. This can be done by checking that the current value of the Linear Regression line is less than the value in the near past.
  2. Once the downtrend is established, exit the trade when the closing price is lesser than the SuperTrend signal i.e. the colour of the SuperTrend signal is red.
supertrend trade signals
Look how we entered the trade at the beginning of mark-up while exited during the accumulation

Building on Mudrex

One of the most important factors which determine the success or failure of this strategy is setting up suitable parameters for both SuperTrend and Linear Regression. The parameters will highly vary with the time-frame in which you want to trade and thus running multiple back-tests on Mudrex can help you decide the choice of parameters suitable to your trading style.

In the following example, we’ll be using the lookback period of Linear Regression to be 50 while comparing it with the value 5 candles ago to detect the slope. On the other hand, SuperTrend ATR lookback period is taken as 20 while multiplication factor is 2. As discussed above, let us first write our entry/exit conditions so that we know what to do while building our strategy:

Buy when:

  • Linear Regression (Current) > Linear Regression (5 Candles Ago)
  • Closing Price greater than equal to SuperTrend Value (Green)

Sell when:

  • Linear Regression (Current) < Linear Regression (5 Candles Ago)
  • Closing Price lesser than equal to SuperTrend Value (Red)

We’ll be using a stop-loss of 15% to prevent losing trades due to generation of false signals.

To construct the first buy condition of Linear Regression (Current) > Linear Regression (5 Candles Ago), we’ll use a compare block which looks like this:

linear regression mudrex

Compare block for the second buy condition to generate a buy signal when Closing Price is greater than equal to SuperTrend Value looks like this:

supertrend mudrex

Joining these two blocks with an AND block will make our buy signal look like this:

trading strategy mudrex

Similarly, the sell signal can be constructed by reversing the operators in each of the compare blocks. The overall strategy with a stop loss of 15% looks like this:

trading strategy mudrex
Overall Strategy

And we’re done!

We can now run a quick back-test to see how our strategy performs. Running one from over the past 1.5 years using a tick cycle of 12H gives us quite amazing results:

backtest mudrex
Backtest from 7th Nov 2018 to 7th May 2020 using a 12H tick cycle on Bitmex BTC/USD

Changing the filter from the Linear Regression to Exponential Moving Average can show an improvement in this strategy over the assessment period. However, using the concept of Linear Regression in itself is a unique and interesting method to set the predominant trend and has its own benefits.

Reverse Opening of Trades (Additional)

Another feature which you can try out on Mudrex is preventing “Reverse Opening of Short/Long Trades”. What this means is, since we only have one buy and sell condition respectively, opening of long trades while closing of short trades is done when the buy signal is called. Whereas, closing of long trades and opening of short trades is done when the sell signal is called.

Now technically, closing of long trades should simultaneously open up a short trade, because sell signal is called when a bearish trend is expected and we should logically be betting against the price. This is called “reverse open of long to short”. Whereas, closing of short trade should simultaneously open a long trade since buy signal is called when a bullish trend is expected and we should be betting for the price. This is called “reverse open of short to long”.

However, if we now take the market cycle into consideration, it is very clear that every uptrend need not be followed by a downtrend right away and vice versa. We might not want to enter a short trade right after closing a long trade because of consolidated prices in accumulation and distribution phases between every uptrend and downtrend. This can be done by unchecking the box of “reverse open long to short” or vice versa in the buy/sell signal path details dialogue box as shown:

signal mudrex

A lot of even more complex things can be done on Mudrex! Signup today!

Links

A few quick references below:

· Signup now on Mudex and get $25 FREE: https://mudrex.com/signup
· Support and FAQs: https://support.mudrex.com/hc/en-us
· 24*7 support on our Discord channel: https://discord.gg/huZz3qP

Happy Trading!

Originally published at https://blog.mudrex.com on May 9, 2020.

--

--