Rajandran R Creator of OpenAlgo - OpenSource Algo Trading framework for Indian Traders. Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, 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. Building Algo Platforms, Writing about Markets, Trading System Design, Market Sentiment, Trading Softwares & Trading Nuances since 2007 onwards. Author of Marketcalls.in

Creating and Backtesting Tradingview Pinescript Trading Strategy

1 min read

This basic tutorial helps you to explore creating your own first trading system in Tradingview platform using pinescript programming language. If you are searching for how to create and backtesting your trading ideas then this is the first video tutorial that you have to start with.

Simple Trading Rules

Enter Long: Positive EMA Crossover of 20 and 50
Exit Long: Candle closes below 25 periods EMA

Enter Short: Negative EMA Crossover of 20 and 50
Exit Short: Candle Closes above 25 periods EMA

Video Tutorial on How to Create and Bactesting Tradingview Pinescript Programming

Pinescript Code

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © algomojo

//@version=4
strategy("Simple Trading Strategy",overlay=true)

//compute the indicators

ema1 = ema(close,20)
ema2 = ema(close,50)
ema3 = ema(close,25)



//plot the indicators

plot(ema1,title="EMA20",color=color.red,linewidth=2)
plot(ema2,title="EMA50",color=color.green,linewidth=2)
plot(ema3,title="EMA25",color=color.blue,linewidth=2)


//Trading Logic

EnterLong = crossover(ema1,ema2) //Positive EMA Crossover
ExitLong = crossunder(close,ema3) //candle closes below 25 per EMA value

EnterShort = crossunder(ema1,ema2) //Negative EMA crossover
ExitShort = crossover(close,ema3)



//Execution Logic - Placing Orders

strategy.entry("Long",strategy.long,1,when=EnterLong)
strategy.close("Long",when=ExitLong)

strategy.entry("Short",strategy.short,1,when=EnterShort)
strategy.close("Short",when=ExitShort)


Interested in Designing your Tradingview Indicators/Systems?
If you are interested in creating your own trading indicators, scanners, trading strategies and want to automate your codes?

Then Enroll in 20+ hours of Practical Approach to Pinescript Programming to learn Pinescript Programming in Tradingview Platform right from scratch.

For Complete Agenda Visit

Pratical Approach to Pinescript Programming

Rajandran R Creator of OpenAlgo - OpenSource Algo Trading framework for Indian Traders. Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, 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. Building Algo Platforms, Writing about Markets, Trading System Design, Market Sentiment, Trading Softwares & Trading Nuances since 2007 onwards. Author of Marketcalls.in

Introducing OpenAlgo V1.0: The Ultimate Open-Source Algorithmic Trading Framework…

OpenAlgo V1.0 is an open-source algorithmic trading platform to automate your trading strategies using Amibroker, Tradingview, Metatrader, Python etc. Designed with the modern trader...
Rajandran R
2 min read

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

One Reply to “Creating and Backtesting Tradingview Pinescript Trading Strategy”

Leave a Reply

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