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)

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/
// © algostudio
// 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)

Dive Into the TradingView Paper Trading Competition: A Chance…

Welcome to an exhilarating opportunity presented by TradingView – a paper trading competition that not only tests your trading acumen but also offers a...
Rajandran R
1 min read

Introducing PineGPT – To Build Better Tradingview Pinescript Codes

PineGPT is a customGPT for ChatGPT4 users designed to provide expert guidance on creating and understanding TradingView Pine Script indicators and trading strategies. PineGPT...
Rajandran R
1 min read

5Paisa – Tradingview Webhook Automation Module

In this tutorial, we will be learning how to use the 5Paisa – Tradingview Webhook feature for automating your Tradingview pinescript strategy. This Module...
Rajandran R
10 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