Strategy · Pine Script v5 · On the chart

Double Supertrend [Alorse]

by Alorse

Double Supertrend [Alorse] is a trend-following strategy that calculates two Supertrend indicators with distinct ATR periods and multiplier factors directly on the price chart.

View on GitHub

GitHub stars330on the repository
Pine versionv5runs as is
Lines of code83
Settings10inputs
LicenceNone statedfile: MPL-2.0
Last update2 months ago25 Aug 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart. The trades and results appear in the Strategy Tester tab; adjust the settings with the gear icon.

Source Code

83 lines of Pine Script v5 from strategies/trend/Double Supertrend.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

Double Supertrend.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © alorse

//@version=5
strategy(title='Double Supertrend [Alorse]', overlay=true, pyramiding=0, currency=currency.USD, default_qty_type=strategy.percent_of_equity, initial_capital=10000, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=0.06)

// Backtesting
btGroup = "Backtesting"
startTime = input.time(title="Start time", defval=timestamp("Dec 01 2021 23:59:59"), group=btGroup)
endTime = input.time(title="End time", defval=timestamp("Feb 01 2022 23:59:59"), group=btGroup)

inDateRange = time >= startTime and time <= endTime

st_1 = "Supertrend"
atrPeriod = input(10, "ST1   ATR", group=st_1, inline=st_1)
factor = input.float(3.0, "Factor", step = 0.1, group=st_1, inline=st_1)

[supertrend, direction] = ta.supertrend(factor, atrPeriod)

inLong = direction < 0
inShort = direction > 0

upTrend = plot(inLong? supertrend : na, "Up Trend", color=color.new(color.green, 35), style=plot.style_linebr)
downTrend = plot(inShort ? supertrend : na, "Down Trend", color=color.new(color.red, 35), style=plot.style_linebr)

bodyMiddle = plot((open + close) / 2, display=display.none)
fill(bodyMiddle, upTrend, color.new(color.green, 92), fillgaps=false)
fill(bodyMiddle, downTrend, color.new(color.red, 92), fillgaps=false)

st_2 = "Supertrend 2"
atrPeriod2 = input(10, "ST2   ATR", group=st_1, inline=st_2)
factor2 = input.float(5.0, "Factor", step = 0.1, group=st_1, inline=st_2)

[supertrend2, direction2] = ta.supertrend(factor2, atrPeriod2)

inLong2 = direction2 < 0
inShort2 = direction2 > 0

upTrend2 = plot(inLong2? supertrend2 : na, "Up Trend", color=color.new(color.green, 50), style=plot.style_linebr)
downTrend2 = plot(inShort2 ? supertrend2 : na, "Down Trend", color=color.new(color.red, 50), style=plot.style_linebr)

bodyMiddle2 = plot((open + close) / 2, display=display.none)
fill(bodyMiddle2, upTrend2, color.new(color.green, 95), fillgaps=false)
fill(bodyMiddle2, downTrend2, color.new(color.red, 95), fillgaps=false)

// Strategy Conditions
stratGroup = 'Strategy'
ifShortLong = input.string(title='Direction', defval='Long', options=['Long', 'Short'], group=stratGroup)
entryLong = inLong
exitLong = ta.change(direction2) > 0
entryShort = inShort
exitShort = ta.change(direction2) < 0

tpGroup = 'Take Profit'
useTP = input.string(title='Type', defval='Supertrend', options=['Supertrend', '%'], group=tpGroup, inline=tpGroup, tooltip='Supertrend: Will close the trade when ST 5 changes direction.\nPercent (%): Will close the trade when it reaches this profit percentage.')
TPPercent = input.float(1.5, step=0.1, title='%', group=tpGroup, inline=tpGroup)

longTP = 99999999999.9
shortTP = 0.0

if useTP == '%'
    longTP := strategy.position_avg_price * (1 + (TPPercent * 0.01))
    shortTP := strategy.position_avg_price * (1 - (TPPercent * 0.01))
else
    longTP := na
    shortTP := na

// Stop Loss
slGroup = 'Stop Loss'
SLPercent = input.float(10, title='Percent', group=slGroup) * 0.01

longStop = strategy.position_avg_price * (1 - SLPercent)
shortStop = strategy.position_avg_price * (1 + SLPercent)

if ifShortLong == 'Long' and inDateRange
    strategy.entry("Long", strategy.long, when=entryLong)
    strategy.close("Long", when=exitLong)
    strategy.exit("Exit", "Long", limit=longTP, stop=longStop)

if ifShortLong == 'Short' and inDateRange
    strategy.entry("Short", strategy.short, when=entryShort)
    strategy.close("Short", when=exitShort or inLong)
    strategy.exit("Exit", "Short", limit=shortTP, stop=shortStop)

Overview

Double Supertrend [Alorse] enters long or short positions when the fast Supertrend signals a trend. Exits occur when the second, slower Supertrend changes direction or when a customizable percentage take-profit level is reached. The strategy includes a fixed percentage stop loss and an adjustable backtesting date window.

Details

Published by

Alorse on GitHub

Type

Strategy, Pine Script v5

Draws

On the price chart

Category

Trend, Volatility & bands

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Topics

pinescriptpinescript-indicatorspinescript-strategiestrading-strategiestradingviewtradingview-alerttradingview-strategy

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Start timetimetimestamp("Dec 01 2021 23:59:59")startTime
End timetimetimestamp("Feb 01 2022 23:59:59")endTime
ST1   ATRint10atrPeriod
Factorfloat3.0factor
ST2   ATRint10atrPeriod2
Factorfloat5.0factor2
DirectionstringLongifShortLong
TypestringSupertrenduseTP
%float1.5TPPercent
Percentfloat10SLPercent
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

257 stars

This overlay strategy targets one-minute ES futures and plots volume-weighted moving-average bands from the open, scaled by a standard-deviation multiple, plus a slower band from ten-minute opens. A higher-timeframe exponential moving average can filter trades

Strategy v6 Moving averagesVolatility & bands
Updated 6 weeks ago · None stated GitHub repository of ES - Futures 1M No Repaint

STRG-BBForce

by harryguiacorn
219 stars

STRG-BBForce is a Bollinger Bands trend-following strategy. It calculates standard Bollinger Bands and tracks directional alignment across the upper, lower, and basis lines. When all three lines slope upward, it opens a long position and closes short positions

Strategy v5 TrendVolatility & bands
Updated 1 year ago · None stated GitHub repository of STRG-BBForce

Nasdaq Prop Firm Strategy

by TradersPost
218 stars

This strategy uses multiple VWAP anchors and a custom Lull indicator to generate buy and sell signals on the Nasdaq price chart. It plots the VWAP trend line and three VWAP anchors with customizable colors and mitigation methods. The Lull indicator produces si

Strategy v6 TrendSupport & resistance Repaints
Updated 3 months ago · None stated GitHub repository of Nasdaq Prop Firm Strategy

This strategy implements a single-layer perceptron machine learning model built from scratch to generate trading signals directly on the price chart. It calculates predictions based on sample size, threshold settings, and optional volatility or volume filters.

Strategy v5 AI / machine learningTrend
Updated 1 year ago · None stated GitHub repository of Machine Learning: Perceptron-Based Strategy [5] (v.3)
106 stars

This overlay strategy plots a two-timeframe Ichimoku setup on the price chart, with Tenkan, Kijun, Chikou, and Kumo from a base higher timeframe and an optional highest-timeframe cloud. It allows two entries in the same direction and uses ATR-based trailing st

Strategy v4 TrendVolatility & bands
Updated 2 years ago · GPL-3.0 GitHub repository of 2Tier Ichimoku Pyramiding [Takazudo]

Bollinger Bands Strategy

by cklose2000
105 stars

This strategy generates buy and sell signals based on Bollinger Band crossovers combined with a simple moving average trend filter. It enters a long position when price crosses above the lower band while trading above the SMA filter line, and enters a short po

Strategy v5 Volatility & bandsMoving averages
Updated 1 year ago · None stated GitHub repository of Bollinger Bands Strategy

More strategys

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers