When we mention the “Narrow Range Inside Bar,” we are specifically referring to stocks that meet two criteria: they appear in the Narrow Range 7 (NR7) scanner and also exhibit the characteristics of an inside bar pattern.
However, as you have already gone through the earlier chapters of backtesting, You can try out the backtesting method on the scanner of Double Narrow Range 7.
In the previous chapters,
The only thing that needs changing in the code is the dataset because everythin g else exactly the same! So double_ib.csv will become nr7.csv which was shared in the earlier chapter. It contains all the FNO stocks that has exhibited Triple Inside Bar Pattern since 2015 to today.
df = pd.read_csv("/root/apps/trident/double_ib.csv")
df
will become –
df = pd.read_csv("/root/apps/trident/nr7.csv")
df
Now, let’s introduce an intriguing twist.
Up until now, we’ve been exploring just two exit methods: same-day exit and exit after 5 days. But what if we experiment with a different approach? How about exiting after just 2 days, meaning the trade closes on the next trading day? (In the event that the next day is a holiday, the trade will be exited on the same day.)
Anyways, to do that, We need to change the check_high_breakout_and_save
function we designed in our earlier chapter.
to_date = from_date + datetime.timedelta(hours=5)
becomes –
to_date=from_date+ datetime.timedelta(days=2)
You are welcome to try out different outcomes and play with both the entry and exit conditions!
As the entire codebase will be same, there is no need to re-invent the wheel. Therefore, let’s proceed to examine the three strategies in parallel to gain a more insightful perspective. Now, it will look nasty in mobile, so it is better You view this in Desktop.
Net of buy_pl_points: 278051.6199999994
Net of sell_pl_points: 1057877.7299999995
Positive buy_pl_points count: 546
Negative buy_pl_points count: 611
Total buy_pl_points count: 2238
Positive sell_pl_points count: 642
Negative sell_pl_points count: 484
Total sell_pl_points count: 2238
Average of buy_pl_points: 124.24111706881118
Average of sell_pl_points: 472.68888739946357
Average of positive buy_pl_points: 5465.013040293043
Average of positive sell_pl_points: 4582.949080996886
Average of negative buy_pl_points: -4428.552373158758
Average of negative sell_pl_points: -3893.337975206613
Net of buy_pl_points: 626660.7300000007
Net of sell_pl_points: 226256.93000000028
Positive buy_pl_points count: 631
Negative buy_pl_points count: 724
Total buy_pl_points count: 2239
Positive sell_pl_points count: 633
Negative sell_pl_points count: 718
Total sell_pl_points count: 2239
Average of buy_pl_points: 279.88420276909363
Average of sell_pl_points: 101.0526708351944
Average of positive buy_pl_points: 7095.479698890652
Average of positive sell_pl_points: 5810.943080568722
Average of negative buy_pl_points: -5318.490276243095
Average of negative sell_pl_points: -4807.896991643455
Net of buy_pl_points: 1087522.4300000002
Net of sell_pl_points: 412298.9700000003
Positive buy_pl_points count: 703
Negative buy_pl_points count: 968
Total buy_pl_points count: 2239
Positive sell_pl_points count: 686
Negative sell_pl_points count: 967
Total sell_pl_points count: 2239
Average of buy_pl_points: 485.71792317999115
Average of sell_pl_points: 184.14424743188937
Average of positive buy_pl_points: 11341.583883357043
Average of positive sell_pl_points: 10449.738644314868
Average of negative buy_pl_points: -7113.234545454547
Average of negative sell_pl_points: -6986.785667011374
After a thorough analysis of the trading strategies, we’ve unearthed some intriguing findings: