Rajandran R Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, USDINR and High Liquid Stock Derivatives. Trading the Markets Since 2006 onwards. Using Market Profile and Orderflow for more than a decade. Designed and published 100+ open source trading systems on various trading tools. Strongly believe that market understanding and robust trading frameworks are the key to the trading success. Writing about Markets, Trading System Design, Market Sentiment, Trading Softwares & Trading Nuances since 2007 onwards. Author of Marketcalls.in and Co-Creator of Algomojo (Algorithmic Trading Platform for DIY Traders)

Supertrend v4.0 with EMA Filter – Tradingview Pinescript Code

1 min read

Supertrend with a simple EMA Filter can improve the performance of the signals during a strong trending market and reduces the number of trades as well which in turn reduces the trading cost + unwanted losing trades. i.e overall drawdown reduces and improves the sharp ratio compared to the regular supertrend long/short signals.

Strategy Rules

Buy – if candle closes above supertrend and price above 200 EMA on closing basis
Exit Buy – if price of the candle closes below supertrend.

Strategy Parameters

EMA Filter used: 200 EMA

Strategy Type: Long Only

Recommended Timeframe: 15min

Symbol Backtested: Nifty Futures

Backtesting Period : Jan 2017 – 29th Nov 2022 – Till to date

Supertrend Default Parameters: Multiplier- 3 and ATR Length – 10

Optimization : No

Position Size : 1 lot (50 shares)

Supertrend V4.0 – Nifty Futures 15min Charts

During the sideways markets, it behaves like supertrend, creating noisy signals. However, the overall performance of the super trend improves with reduced drawdown

Equity Curve per lot

Absolute Drawdown per lot

Backtesting Metrics

Tradingview Pinescript Code – Supertrend V4.0

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © tradestudio
// Coded by Rajandran R (Founder - Marketcalls and Co-Founder - Algomojo)

//@version=5
strategy("Supertrend with EMA as Filter", overlay=true)


//input controls
factor = input.float(2,"Factor",1.0,10.0,0.5)
length = input.int(10,"ATR Length",1,100,1)

[supertrend,direction] = ta.supertrend(factor,length)

ema200 = ta.ema(close,200)

plot(ema200,"EMA 200",color.yellow,linewidth = 2)

//direction variables contains series of +1 and -1
//supertrend variable contains the supertrend line

longEntry = direction == -1 and close > ema200
longExit =  direction == 1 and direction[1] == -1

shortEntry = direction == 1 and close < ema200
shortExit = direction == -1 and direction[1] == 1

supcolor = direction == -1 ? color.green : color.red 

plot(supertrend,"Supertrend",supcolor,linewidth = 2)

if(longEntry)
    strategy.entry("BUY",strategy.long,comment="BUY")
if(longExit)
    strategy.close("BUY",comment="BUY EXIT")
// if(shortEntry)
//     strategy.entry("SHORT",strategy.short,comment="SHORT")
// if(shortExit)
//     strategy.close("SHORT",comment="SHORT EXIT")
Rajandran R Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, USDINR and High Liquid Stock Derivatives. Trading the Markets Since 2006 onwards. Using Market Profile and Orderflow for more than a decade. Designed and published 100+ open source trading systems on various trading tools. Strongly believe that market understanding and robust trading frameworks are the key to the trading success. Writing about Markets, Trading System Design, Market Sentiment, Trading Softwares & Trading Nuances since 2007 onwards. Author of Marketcalls.in and Co-Creator of Algomojo (Algorithmic Trading Platform for DIY Traders)

How to Squareoff All OpenPositions using Tradingview – Automation…

One of the most demanded requests from Tradingview-based automated traders is how to square-off all open positions when a particular time is reached. There...
Rajandran R
1 min read

Sending Futures/Spot – Signals to Two-Legged Options Execution Module…

Thought of making an open-source Tradingview Pinescript code demanded by most of the option traders to control the cost, control the risk, and configure...
Rajandran R
16 min read

Tradingview Smart Order Strategy Automation – Without Writing any…

Algomojo strives to bring intelligent trade execution practices in the form of Arrow API controls. This tutorial helps you to convert any Tradingview strategy...
Rajandran R
3 min read

2 Replies to “Supertrend v4.0 with EMA Filter – Tradingview Pinescript Code”

  1. I have downloaded the nakshatra system for nifty and modified it. It is giving vey good calmar ratio for 6 months but the problem is i don’t have reliable data source for historical data. It would be great if you would share your data with us as you have shared many code. If it is not possible to share your data, please share the nakshatra system for tradingview where we can buy the data and test the code also. Thanks.

Leave a Reply

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