Strategy · Pine Script v4 · On the chart

Triple Supertrend Strategy

by shyrwinsia

This strategy calculates three Supertrend directions from short, medium, and long ATR periods and multipliers on a chosen source.

View on GitHub

GitHub stars5on the repository
Pine versionv4older, still runs
Lines of code65
Settings8inputs
LicenceMIT
Last update5 years ago20 Apr 2021

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

65 lines of Pine Script v4 from Triple Supertrend with Baseline Strategy.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

Triple Supertrend with Baseline Strategy.pine
//@version=4
strategy("Triple Supertrend Strategy", overlay = true)

src = input(hl2, title="Source")
sPeriod = input(title="Short ATR Period", type=input.integer, defval=10)
sMultiplier = input(title="Short ATR Multiplier", type=input.float, step=0.1, defval=1.0)
mPeriod = input(title="Medium ATR Period", type=input.integer, defval=11)
mMultiplier = input(title="Medium ATR Multiplier", type=input.float, step=0.1, defval=2.0)
lPeriod = input(title="Long ATR Period", type=input.integer, defval=12)
lMultiplier = input(title="Long ATR Multiplier", type=input.float, step=0.1, defval=3.0)

yearstart = input(2018, title="Year Start")

satr = atr(sPeriod)
sup = src - (sMultiplier * satr)
sup1 = nz(sup[1], sup)
sup := close[1] > sup1 ? max(sup, sup1) : sup
sdn = src + (sMultiplier * satr)
sdn1 = nz(sdn[1], sdn)
sdn := close[1] < sdn1 ? min(sdn, sdn1) : sdn
strend = 1
strend := nz(strend[1], strend)
strend := strend == -1 and close > sdn1 ? 1 : strend == 1 and close < sup1 ? -1 : strend

matr = atr(mPeriod)
mup = src - (mMultiplier * matr)
mup1 = nz(mup[1], mup)
mup := close[1] > mup1 ? max(mup, mup1) : mup
mdn = src + (mMultiplier * matr)
mdn1 = nz(mdn[1], mdn)
mdn := close[1] < mdn1 ? min(mdn, mdn1) : mdn
mtrend = 1
mtrend := nz(mtrend[1], mtrend)
mtrend := mtrend == -1 and close > mdn1 ? 1 : mtrend == 1 and close < mup1 ? -1 : mtrend

latr = atr(lPeriod)
lup = src - (lMultiplier * latr)
lup1 = nz(lup[1], lup)
lup := close[1] > lup1 ? max(lup, lup1) : lup
ldn = src + (lMultiplier * latr)
ldn1 = nz(ldn[1], ldn)
ldn := close[1] < ldn1 ? min(ldn, ldn1) : ldn
ltrend = 1
ltrend := nz(ltrend[1], ltrend)
ltrend := ltrend == -1 and close > ldn1 ? 1 : ltrend == 1 and close < lup1 ? -1 : ltrend

baseline = ema(close, 200)


buysignal = strend == 1 and mtrend == 1 and ltrend == 1 and strategy.position_size == 0
sellsignal = strend != 1 and mtrend != 1 and ltrend != 1 and strategy.position_size == 0

tplong = open + (open - mup)
sllong = open - mup

tpshort = open - mdn
slshort = open - (open - mdn)

if time >= timestamp(yearstart,0,0,0,0,0)
    strategy.entry("buy", strategy.long, 10000, when = buysignal)
    strategy.close("buy", when = (strend != 1))
    strategy.exit("close", "buy", 10000, stop = sllong, limit = tplong, when=strategy.position_size > 0)

    strategy.entry("sell", strategy.short, 10000, when = sellsignal)
    strategy.close("sell", when = (strend == 1))

Overview

Triple Supertrend Strategy enters long when all three trends are bullish and the position is flat, and enters short when none is bullish and the position is flat. Longs close if the short Supertrend turns down and also use a stop and limit based on the medium upper band. Shorts close when the short Supertrend turns up, with no separate short stop in the code. A start year limits when orders are placed. It runs on the price chart for any market or timeframe.

Details

Published by

shyrwinsia on GitHub

Type

Strategy, Pine Script v4

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.

Settings

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

SettingTypeDefaultVariable
Sourcesourcehl2src
Short ATR Periodint10sPeriod
Short ATR Multiplierfloat1.0sMultiplier
Medium ATR Periodint11mPeriod
Medium ATR Multiplierfloat2.0mMultiplier
Long ATR Periodint12lPeriod
Long ATR Multiplierfloat3.0lMultiplier
Year Startint2018yearstart
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

330 stars

This strategy calculates Bollinger Bands and Aroon oscillator values to identify mean-reversion opportunities. It enters a long position using full equity when the closing price crosses below the lower Bollinger Band while Aroon Up remains above a user-specifi

Strategy v5 Mean reversionVolatility & bands
Updated 2 months ago · None stated GitHub repository of Bollinger bands + Aroon [Alorse]
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]

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