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
//@version=4
study("Supertrend - Buy or Sell Signal", overlay = true)
//inputs
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
up=Source-(Multiplier*atr)
up1 = nz(up[1],up)
up := close[1] > up1 ? max(up,up1) : up
//Creating Down Channel
dn=Source+(Multiplier*atr)
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)
//Alerts
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
barcolor(color)
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
Regards,
Veer
We are still in Beta. You can expect the feature once we are going live with our own feeds
Dear Rajendaran
I am unable to apply supertrend indicator in Amibroker.. When I try to edit the formula it shows error??
Please help me
Regards
Dhananjay
Its designed for Tradingview charts for Amibroker use the Supertrend AFL code link here
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.
you can get it at http://www.marketcallls.in/eodchart
Can you please provide “tradescript” code for Supertrend indicator ?
What is the timeframes to use with this indicator?
Thank you
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.
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?
Thanks
Jo
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.
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
Initally TrendUp sets with null values automatically. So TrendUp[0] is initialized to null and rest other calculation does in recursive mode.
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?
supertrend v4 is not codeable as of now in Trading View due to pinescript feature. May be in the later days.
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?
how to code close> supertrend?