Strategy · Pine Script v5 · On the chart

Super Duper Trend Strategy

by benso87

This strategy plots a Supertrend and a double exponential moving average on the price chart.

View on GitHub

Repaints

GitHub stars24on the repository
Pine versionv5runs as is
Lines of code110
Settings12inputs
LicenceMPL-2.0
Last update4 years ago5 Oct 2022

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

110 lines of Pine Script v5 from Super Duper Trend Strategy.pine, published under MPL-2.0. Keep the author's credit and licence lines when you reuse it.

Super Duper Trend Strategy.pine
//@version=5
//
// Author: benso87
// benso87.com
//
// From Trader's Landing on YouTube: https://www.youtube.com/watch?v=yXskVYp4Rps
//
strategy("Super Duper Trend Strategy", shorttitle='Super Duper', overlay=true, initial_capital=1000, default_qty_value=10, default_qty_type=strategy.percent_of_equity, process_orders_on_close=true)

noColor = color.new(color.white, transp=100)
///////////////////////////////////////////////////////////////////////////////
// Inputs

//Dates
startDate = input.time (timestamp('1 Jan 2022 00:00'), title='Start', group='Dates')
endDate    = input.time (timestamp('1 Jan 2100 00:00'), title='End', group='Dates')

// DEMA
timeframeD = input.timeframe('', title='DEMA Timeframe', group='DEMA')
lenD = input.int(200, title='Length', group='DEMA')
srcD = input.source(close, title='Source', group='DEMA')

// Supertrend
atrPeriod = input.int(12, title='ATR Period', minval=1, group='Supertrend')
srcS = input.source(hl2, title='Source', group='Supertrend')
mult = input.float(3, title='ATR Multiplier', minval=0, step=0.1, group='Supertrend')
changeATR = input.bool(true, title='Change ATR Calculation Method ?', group='Supertrend')
showsignals = input.bool(true, title='Show Buy/Sell Signals ?', group='Supertrend')
highlighting = input.bool(true, title='Highlighter On/Off ?', group='Supertrend')

// Stop Loss
exitChoice = input.string('DEMA', title='Initial Stop Loss', options=['DEMA', 'Supertrend'], group='Stop Loss')

///////////////////////////////////////////////////////////////////////////////
// Calculations

// DEMA
ema = request.security(syminfo.tickerid, timeframe=timeframeD, expression=ta.ema(srcD, lenD), lookahead=barmerge.lookahead_on) 
dema = request.security(syminfo.tickerid, timeframe=timeframeD, expression=2 * ema - ta.ema(ema, lenD), lookahead=barmerge.lookahead_on)

// Supertrend
atr2 = ta.sma(ta.tr, atrPeriod)
atr = changeATR ? ta.atr(atrPeriod) : atr2

up = srcS - mult * atr
up1 = nz(up[1], up)
up := close[1] > up1 ? math.max(up, up1) : up

dn = srcS + mult * atr
dn1 = nz(dn[1], dn)
dn := close[1] < dn1 ? math.min(dn, dn1) : dn

trend = 1
trend := nz(trend[1], trend)
trend := trend == -1 and close > dn1 ? 1 : trend == 1 and close < up1 ? -1 : trend

buySignal = trend == 1 and trend[1] == -1
sellSignal = trend == -1 and trend[1] == 1

longFillColor = highlighting ? trend == 1 ? color.green : color.white : color.white
shortFillColor = highlighting ? trend == -1 ? color.red : color.white : color.white

///////////////////////////////////////////////////////////////////////////////
// Plots

// DEMA
plot(dema, title='DEMA', color=color.yellow, linewidth=2)

// Supertrend
upPlot = plot(trend == 1 ? up : na, title='Up Trend', style=plot.style_linebr, linewidth=2, color=color.new(color.green, 0))
plotshape(buySignal ? up : na, title='UpTrend Begins', location=location.absolute, style=shape.circle, size=size.tiny, color=color.new(color.green, 0))
plotshape(buySignal and showsignals ? up : na, title='Buy', text='Buy', location=location.absolute, style=shape.labelup, size=size.tiny, color=color.new(color.green, 0), textcolor=color.new(color.white, 0))
dnPlot = plot(trend == 1 ? na : dn, title='Down Trend', style=plot.style_linebr, linewidth=2, color=color.new(color.red, 0))

plotshape(sellSignal ? dn : na, title='DownTrend Begins', location=location.absolute, style=shape.circle, size=size.tiny, color=color.new(color.red, 0))
plotshape(sellSignal and showsignals ? dn : na, title='Sell', text='Sell', location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.new(color.red, 0), textcolor=color.new(color.white, 0))
mPlot = plot(ohlc4, title='', style=plot.style_circles, linewidth=0)

fill(mPlot, upPlot, title='UpTrend Highligter', color=color.new(longFillColor, transp=90))
fill(mPlot, dnPlot, title='DownTrend Highligter', color=color.new(shortFillColor, transp=90))

///////////////////////////////////////////////////////////////////////////////
// Strategy

// Entry
longSignal = close >= dema and buySignal
shortSignal = close <= dema and sellSignal

strategy.entry("Long", strategy.long, when=longSignal)
strategy.entry("Short", strategy.short, when=shortSignal)

// Exit
var float slLong = na
var float slShort = na

slLong := longSignal ? dema : slLong[1]
slShort := shortSignal ? dema : slShort[1]

exitLong = exitChoice == 'DEMA' and slLong > up ? slLong : up
exitShort = exitChoice == 'DEMA' and slShort < dn ? slShort : dn

strategy.exit('Long Exit', from_entry='Long', stop=exitLong)
strategy.exit('Short Exit', from_entry='Short', stop=exitShort)


///////////////////////////////////////////////////////////////////////////////
// Testing

// plotchar(slLong, title='long SL', char='.', color=noColor)
// plotchar(slShort, title='short SL', char='.', color=noColor)

Overview

Supertrend direction flips mark buy and sell signals, with optional labels and trend highlighting. The DEMA uses a selectable timeframe and source and is requested with lookahead enabled, so higher-timeframe values can use future bars. An initial stop can be set to the DEMA or the Supertrend line. Date limits, ATR length, multiplier, and ATR method are adjustable. Position size defaults to a percent of equity.

Details

Published by

benso87 on GitHub

Type

Strategy, Pine Script v5

Draws

On the price chart

Category

Trend, Moving averages, Volatility & bands

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

  • Signals can change on the live bar or after it closes (repainting)
  • Reads higher-timeframe data with lookahead on, so the history can show signals that were not there in real time

Settings

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

SettingTypeDefaultVariable
Starttimetimestamp('1 Jan 2022 00:00')startDate
Endtimetimestamp('1 Jan 2100 00:00')endDate
DEMA TimeframetimeframetimeframeD
Lengthint200lenD
SourcesourceclosesrcD
ATR Periodint12atrPeriod
Sourcesourcehl2srcS
ATR Multiplierfloat3mult
Change ATR Calculation Method ?booltruechangeATR
Show Buy/Sell Signals ?booltrueshowsignals
Highlighter On/Off ?booltruehighlighting
Initial Stop LossstringDEMAexitChoice
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

This mean-reversion strategy plots Bollinger Bands and a long-term moving average directly on the price chart. It enters trades when price candles penetrate the outer Bollinger Bands beyond a user-defined body percentage, anticipating a price reversal. Entries

Strategy v5 Mean reversionVolatility & bands
Updated 2 months ago · None stated GitHub repository of Bollinger Bands Winner PRO [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
106 stars

This trading strategy combines three Exponential Moving Averages (8, 14, and 50 periods by default) with Stochastic RSI and Average True Range (ATR). It enters a long position when EMA 1 is above EMA 2, EMA 2 is above EMA 3, and the Stochastic RSI %K line cros

Strategy v4 TrendOscillators & momentum
Updated 2 years ago · GPL-3.0 GitHub repository of 3 x EMA + Stochastic RSI + ATR

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
104 stars

This overlay strategy combines a Chandelier Exit with a zero-lag least squares moving average. Although the header mentions Heikin Ashi candles, the calculations use ordinary closes. An ATR trailing stop sets long and short levels, and direction flips when pri

Strategy v5 TrendMoving averages
Updated 3 years ago · MIT GitHub repository of Chandelier Exit & ZLSMA 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