I am trying to backtest inside candle pattern on 15 mins timeframe. But, the entry price is not correct as I tried to see the _stats.trades. The exit price seems correct but the entry price is way above than what I have set by placing 'Stop' orders. I tried to cross-check it in trading view charts as well as the data I am passing. The price does not even hover in the range what the entry price I am getting with this backtest. This issue is recurring with almost every code. Not sure if something is wrong with the trade. I am attaching the entire code below.
from backtesting import Strategy, Backtest
from backtesting.lib import resample_apply
import pandas as pd
import numpy as np
class System(Strategy):
rr = 2
def init(self):
pass
def next(self):
if (self.data.Close[-2] > self.data.Open[-2] and
self.data.High[-1] < self.data.High[-2] and
self.data.Low[-1] > self.data.Low[-2]):
self.buy(stop=self.data.High[-1], sl=self.data.Low[-1],
tp=self.data.High[-1]+(self.rr*(self.data.High[-1] - self.data.Low[-1])))
df = pd.read_csv("Data.csv", index_col="Date_Time", parse_dates=True)
bt = Backtest(data = df, strategy = System, commission = 0.01,
cash = 100000, exclusive_orders=False, hedging=True)
bt.run()
I am so grateful to you for this library and prompt response. Kudos 👍
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4