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

Introduction to Backtrader – Creating your First Trading Strategy – Python Trading Tutorial

54 sec read

Backtrader is an open-source python framework for backtesting, optimizing, and deploying live algorithmic trading strategies.

Using Backtrader one can create their own indicators, trading strategies with Buy or Sell indications(observers), get trading statistics (analyzers) and even building stock screeners.

Used Python Version – Python 3.8.5

How to Install Backtrader?

open your command line and use the following command. Ensure that pip is already installed.

pip install backtrader
pip install nsepy

Backtrader library is used for backtesting purpose and nsepy python library to get the End of the day data from NSE

Understanding Cerebro

Cerebro is a powerful trading engine and it serves as a central part for connecting the data feeds, running trading strategies, providing trade metrics, execute the backtesting, live trading, and plotting the results.

Creating your First Strategy involves the following steps in Backtrader

1)Download/Prepare the Data
2)Create the Datafeed from the Dataset
3)Create Buy/Sell Signal Observers (Optional)
4)Create Trading Strategy
5)Enable Logging in your Trading Strategy (Optional)
6)Create Cerebro Engine
7)Add Datafeed to Cerebro Engine
8)Set Initial Capital and Trading Commissions
9)Add Trading Strategy to Cerebro Engine
10)Add Observers to Plot Buy/Sell Indications
11)Run Cerebro Engine
12)Plot the Charts with Buy/Sell Signals
13)Get the Portfolio Results and Trade Metrics

Python Code to Implement a Simple Ema Crossover Strategy with Buy/Sell Signals Plot.

[iframe src=”https://www.marketcalls.in/wp-content/uploads/2021/02/Backtrader101.html”]

Backtrader comes with active community support for the traders who are enthusiastic about creating their own trading system and automating their trades.

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

Voice Commands to Trade on OpenAlgo Platform Using Google…

Trading platforms are always getting better by using the newest technologies to make things easier and more efficient for users. A great example of...
Rajandran R
5 min read

[Live Coding Webinar] Build Your First Trading Bridge for…

In this course, you will be learning to build your own trading bridge using Python. This 60-minute session is perfect for traders, Python enthusiasts,...
Rajandran R
1 min read

How to Place Orders Concurrently using ThreadPoolExecutor – Python…

Creating concurrent orders is essential for active traders, especially those handling large funds, as it allows for executing multiple trade orders simultaneously, thereby maximizing...
Rajandran R
2 min read

Leave a Reply

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