Indicator · Pine Script v4 · On the chart

Leo Supertrend

by kodtodya

Leo Supertrend calculates and plots a Supertrend indicator alongside an Exponential Moving Average on the main price chart.

View on GitHub

GitHub stars1on the repository
Pine versionv4older, still runs
Lines of code84
Settings8inputs
LicenceNone statedfile: MPL-2.0
Last update4 years ago22 Jan 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 indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

84 lines of Pine Script v4 from leo-supertrend.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

leo-supertrend.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © kodtodya

//@version=4

study("Leo Supertrend", overlay=true, format=format.price, precision=2, resolution="")

Periods=input(title="ATR Period", type=input.integer, defval=10)

src=input(hl2, title="Source")
Multiplier=input(title="ATR Multiplier", type=input.float, step=0.1,defval=3.0)

changeATR=input(title="Change ATR Calculation Method 7",type=input.bool, defval=true)

showsignals = input(title="Show Buy/Sell Signals ?", type=input.bool, defval=true)

highlighting=input(title="Highlighter On/Off ?", type=input.bool,defval=true)

atr2=sma(tr, Periods)

atr= changeATR ? atr(Periods): atr2

up=src-(Multiplier*atr)

up1 = nz(up[1],up)

up := close[1]> up1 ? max(up, up1): up

dn=src+(Multiplier * atr)

dn1 = nz(dn[1], dn)

dn := close[1]<dn1 ? 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

upPlot = plot(trend == 1 ? up : na, title="Up Trend", style=plot.style_linebr, linewidth=2, color=color.green)

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

plotshape(buySignal ? up: na, title="UpTrend Begins", location=location.absolute, style=shape.circle, size=size.tiny, color=color.green, transp=0)

plotshape(buySignal and showsignals? up:na, title="Buy", text="BUY", location=location.absolute,style=shape.labelup, size = size.normal, color=color.green, textcolor=color.white,transp=0)

dnPlot= plot(trend == 1? na: dn, title="Down Trend", style=plot.style_linebr, linewidth=2, color=color.red)

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

plotshape(sellSignal ? dn: na, title="DownTrend Begins", location=location.absolute, style=shape.circle, size=size.tiny,color=color.red, transp=0)

plotshape(sellSignal and showsignals ? dn:na,title="Sell", text = "SELL", location=location.absolute, style=shape.labeldown, size=size.normal, color=color.red,textcolor=color.white, transp=0)

mPlot=plot(ohlc4, title="", style=plot.style_circles, linewidth=0)

longFillColor = highlighting? (trend ==1? color.red : color.white): color.white


shortFillColor = highlighting? (trend ==+1? color.red: color.white):color.white

fill(mPlot, upPlot, title="Up Trend Highligter", color=longFillColor)

fill(mPlot, dnPlot, title="DownTrend Highligter", color=shortFillColor)

alertcondition(buySignal, title="Super Trend Buy", message="SuperTrend Buy!")

alertcondition(sellSignal, title="SuperTrend Sell", message="SuperTrend Sell")

changeCond = trend != trend[1]

alertcondition(changeCond, title="SuperTrend Direction Change", message="SuperTrend has changed direction!")

//@version 4

len = input(18, minval=1, title="Length")

offset=input(title="Offset", type=input.integer, defval=0, minval=-500, maxval=500)

out=ema(src, len)

plot(out, title="EMA", color=color.blue, offset=offset)

Overview

Leo Supertrend determines trend direction by tracking price relative to an ATR-based volatility band, supporting both standard RMA and simple moving average calculations for the true range. When price breaches the band, the indicator flips direction and marks potential buy and sell entries with labels and circles. Users can adjust the ATR length, multiplier, smoothing mode, signal toggles, and EMA parameters.

Details

Published by

kodtodya on GitHub

Type

Indicator, Pine Script v4

Draws

On the price chart

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
ATR Periodint10Periods
Sourcesourcehl2src
ATR Multiplierfloat3.0Multiplier
Change ATR Calculation Method 7booltruechangeATR
Show Buy/Sell Signals ?booltrueshowsignals
Highlighter On/Off ?booltruehighlighting
Lengthint18len
Offsetint0offset
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

318 stars

This indicator plots four customizable moving averages directly on the main price chart using default lengths of 3, 8, 21, and 50 periods. It fills the space between adjacent averages in green or maroon depending on trend alignment. Additionally, it computes B

Indicator v5 Moving averagesTrend
Updated 2 months ago · MIT GitHub repository of Multiple Moving Averages

NVDA Trend Ribbon

by longsurf-ai
280 stars

This indicator plots three exponential moving averages and ATR volatility envelopes on the price chart. It compares the fast and slow EMAs to shade a trend ribbon and marks confirmed upward and downward crossovers with triangle labels. Settings change the thre

Indicator v6 TrendMoving averages
Updated 3 days ago · MIT GitHub repository of NVDA Trend Ribbon

Bollinger Bands Force

by harryguiacorn
220 stars

This indicator modifies standard Bollinger Bands to measure directional trend force based on line alignment. It calculates a simple moving average basis along with upper and lower volatility bands. When all three lines move upward or downward simultaneously, i

Indicator v5 Volatility & bandsTrend
Updated 1 year ago · None stated GitHub repository of Bollinger Bands Force

Adaptive MA Slope

by capissimo
114 stars

This indicator calculates Kaufman's Adaptive Moving Average (KAMA) on a chosen price source and determines trend direction based on the slope across a configurable lookback window. Signals can be filtered by short-term volatility expansion using ATR comparison

Indicator v4 Moving averagesTrend
Updated 1 year ago · None stated GitHub repository of Adaptive MA Slope

More Trend scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

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

Compare brokers