I Backtested NR7 Strategy using Python

JohnJoy
Quant Factory
Published in
6 min readMar 21, 2023

--

Exploring and backtesting the famous NR7 strategy with backtrader package of python.

NR7 (Narrow Range 7) is a popular trading strategy that traders have used for many years. The strategy involves identifying a seven-day trading range that is narrower than the previous six trading ranges. When the market breaks out of this narrow range, traders can use this signal to enter a trade with a high probability of success. The NR7 strategy is a simple and effective way to capture market profits, and it can be used for both short-term and long-term trading. In this article, we will explore the details of the NR7 strategy, how it works, and how you can use it to improve your trading results.

We are going to be using the back trader library to do the backtesting of the strategy. It comes with a lot of functionalities that make our work easier

Installing Packages

from __future__ import (absolute_import, division, print_function,
unicode_literals)

import backtrader as bt
from datetime import datetime

Getting Data

datapath = "/Users/jessojoy/backtrader/NiftyFutures-1D.csv"
data = bt.feeds.GenericCSVData(
dataname=datapath,
# Do not pass values before this date
fromdate=datetime(2011, 1, 3),
# Do not pass…

--

--