Rajandran R Founder of Marketcalls and Co-Founder Algomojo. Full-Time Derivative Trader. Expert in Designing Trading Systems (Amibroker, Ninjatrader, Metatrader, Python, Pinescript). Trading the markets since 2006. Mentoring Traders on Trading System Designing, Market Profile, Orderflow and Trade Automation.

Supertrend Indicator – PineScript – Tradingview Charts

1 min read

Supertrend – Pine Script Indicator with Nifty Future charts

This is my first indicator from a series of Pinescript Indicators. And of course, supertrend is one of my favorite indicators. So love to take this opportunity to code it in Pinescript supported by Tradingview charts with a huge community following.

Already Supertrend is enough spoken here. Those who are very new to Supertrend can follow this article here 10 things to know about Supertrend v2.0 AFL code

Tradingview users can use the Supertrend Indicator from the Public Library

Scale Settings to Apply Supertrend V1.0 in Tradingview

Do the scale settings as shown in the image below.


// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © marketcalls_in
// Rajandran - Founder - Marketcalls  / Co-Founder - Algomojo
study("Supertrend - Buy or Sell Signal", overlay = true)

Periods = input(title="ATR Period", type=input.integer, defval=10)
Source = input(hl2, title="Source")
Multiplier = input(title="ATR Multiplier", type=input.float, step=0.1, defval=3.0)

//Compute ATR Levels
atr=  atr(Periods) 

//Creating Upper Channel

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

//Creating Down Channel
dn1 = nz(dn[1], dn)
dn := close[1] < dn1 ? min(dn, dn1) : dn

//Compute the Trend Stream +1/-1
trend = 1
trend := nz(trend[1], trend)
trend := trend == -1 and close > dn1 ? 1 : trend == 1 and close < up1 ? -1 : trend

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

//Buy Signal
Buy = trend == 1 and trend[1] == -1

plotshape(Buy ? up : na, title="Go Long", location=location.absolute, style=shape.circle, size=size.tiny, color=color.green, transp=0)
plotshape(Buy ? up : na, title="Buy", text="Buy Mode", location=location.absolute, style=shape.labelup, size=size.tiny, 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)

//Sell Signal
Sell = trend == -1 and trend[1] == 1

plotshape(Sell ? dn : na, title="Go Short", location=location.absolute, style=shape.circle, size=size.tiny, color=color.red, transp=0)
plotshape(Sell ? dn : na, title="Sell", text="Sell Mode", location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.red, textcolor=color.white, transp=0)

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

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

fill(iPlot, upPlot, title="UpTrend Highligter", color=longFillColor)
fill(iPlot, dnPlot, title="DownTrend Highligter", color=shortFillColor)

alertcondition(Buy, title="SuperTrend Buy", message="SuperTrend Buy!")
alertcondition(Sell, title="SuperTrend Sell", message="SuperTrend Sell!")

buycontiue = barssince(Sell) > barssince(Buy)
sellcontinue = barssince(Buy) > barssince(Sell)

color = buycontiue[1] ? color.green : sellcontinue ? color.red : na
Rajandran R Founder of Marketcalls and Co-Founder Algomojo. Full-Time Derivative Trader. Expert in Designing Trading Systems (Amibroker, Ninjatrader, Metatrader, Python, Pinescript). Trading the markets since 2006. Mentoring Traders on Trading System Designing, Market Profile, Orderflow and Trade Automation.

Simplified Algomojo Execution Controls for Tradingview Platform

This tutorial explains how to configure trading pinescript trading strategies with Algomojo execution controls to send MKT orders to Algomojo supported Brokers in a...
Rajandran R
15 min read

How to Send Cover Orders from Tradingview to Algomojo…

This tutorial helps you to understand how to send cover orders from the Tradingview platform using the webhook method to Algomojo Trading Platform.
Rajandran R
4 min read

Creating and Backtesting Tradingview Pinescript Trading Strategy

This basic tutorial helps you to explore creating your own first trading system in Tradingview platform using pinescript programming language. If you are searching...
Rajandran R
1 min read

16 Replies to “Supertrend Indicator – PineScript – Tradingview Charts”

  1. Dear Rajandran

    Can you pls make the symbol search easier in your EOD charts of Tradingview. Like Google when you type the first two or three letters we can choose the symbol. This will be helpful



  2. Dear Rajendaran

    I am unable to apply supertrend indicator in Amibroker.. When I try to edit the formula it shows error??

    Please help me



  3. Last week i was seeing EOD charts with RSI and stochastic RSI signals but now i have lost site where i can see these charts now? kindly inform on my mail if possible.

  4. Dear sir
    i m using trading view for trading in nasdaq. i have also subscribe for trading view live data for cme. i m using ur super trend indicator. pls help me to convert super trend indicator code base to strategy code so i can back test and foreword test in pine script.

  5. Hello Rajandran

    I have just come across your SuperTrend V1.0 script and it’s awesome. What’s the current version and can I have it?



  6. Dear Rajandran

    Can you tell me if the Supertrend V1.0 – Buy or Sell Signal indicator is available for MT4?

    If so I would like to carry it over to my broker platform for ease of execution.

    With regards.

  7. Hello Rajandran,

    I found your script about Supertrend indicator very interesting.

    However, the is something in it I do not understand. Perhaps you could leave me some lines.

    The calculation of variable TrendUp uses TrendUp[1]. But this previous TrendUp seems to me that is never calculated. For example, there is no “once” statement.

    How is TrendUp getting its first value in the script? Once I understand where this first value comes from, I will fully understand.

    Thank you in advance

    1. Initally TrendUp sets with null values automatically. So TrendUp[0] is initialized to null and rest other calculation does in recursive mode.

  8. Dear Rajendran,

    Wonderful work, can you please share latest script v4 for TradingView? I can see only v1 in your page also in Trading view?

  9. Hello Rajendran,
    I am using your Supertend script v1.0 in the free version of Tradingview. I wanted also the default MACD indicator alolng with your Supertrend. I treid to modify your script, but getting some error.
    Can you please help me?

Leave a Reply

Get Notifications, Alerts on Market Updates, Trading Tools, Automation & More