The original Supertrend indicator

Supertrend is a popular trend-following indicator on TradingView. It uses Average True Range (ATR) to plot a line below the price in an uptrend and above it in a downtrend.

When the direction changes, the original indicator shows a Buy or Sell signal. In the version I used, the default settings were ATR period 10, ATR multiplier 3, and HL2 as the source.

View the original SuperTrend indicator by KivancOzbilgic on TradingView

TradingView original Supertrend inputs with ATR period 10, HL2 source and multiplier 3
Original Supertrend settings — ATR 10, HL2 source, multiplier 3.

What was the expected modification?

The idea was to make TradingView place strategy orders whenever Supertrend produced a new signal, instead of only showing Buy and Sell labels.

  • Buy signal: close an existing short and enter a long.
  • Sell signal: close an existing long and enter a short.
  • Use a 50-period DEMA as the default Supertrend source.
  • Calculate the signals on the 1-hour timeframe by default.

So when the direction changes, the strategy reverses the position. It doesn't hold a long and a short at the same time.

What I changed

I converted Supertrend from an indicator into a TradingView strategy and added a source picker. DEMA(50) is selected by default, but Close, HL2, HLC3 and OHLC4 are also available.

I then connected the trend changes to strategy entries. A Buy switches to a long position, and a Sell switches to a short position. The signal timeframe can also be selected independently, with 1 hour as the default.

SettingOriginalModified version
ScriptIndicatorTrading strategy
ATR period1010
ATR multiplier31
SourceHL2DEMA(50) — Close
TimeframeChart1 hour by default
On a new signalBuy/Sell labelPosition reversal + label
Modified Supertrend settings ATR period 10, DEMA source, ATR multiplier 1
Modified source and ATR settings.
DEMA indicator settings length 50 source Close
DEMA length 50, calculated from Close. The strategy calculates DEMA internally.

The new Supertrend + DEMA strategy

The new version can open simulated long and short trades directly in TradingView's Strategy Tester. It also lets you switch the Supertrend source and adjust the ATR settings without changing the code.

The default configuration uses the 1-hour signal timeframe, ATR period 10, multiplier 1, and DEMA(50). An opposite signal reverses the current position.

Free TradingView script · Pine Script v6

Download the full script for free

Download the complete Supertrend + DEMA Reversal Strategy.

Download free Pine Script ↓
Download count available after launch

Having issues with installation, chart configuration, or anything else related to the script? Feel free to contact me.

CW.
Written by CW

Sharing free TradingView scripts, indicator modifications and Pine Script development notes.