Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Backtesting Breakout Strategies #1295

iimka started this conversation in General
Discussion options

I would like to backtest a breakout strategy, but is it that backtesting.py is unable to implement intra-bar backtesting?

For example, when using day-level data, I expect to execute a buy immediately when the price rises above the previous day's closing price plus 1. However, I've found that the current code can only execute trades at the earliest in the next trading day.

breakout = self.data.Close[-1] + 1

If I want to implement a similar strategy, I can only use lower time frame data—for instance, switching to hour-level data. But there are still similar issues: even if the price breaks through the preset level at 9:45 after the market opens at 9:30, the earliest trade can only be executed at 10:30. To optimize this, I would need to use even lower time frames, but it becomes relatively more difficult to obtain a large amount of relevant data (e.g., half-hourly or minute-level data).

You must be logged in to vote

Replies: 2 comments

Comment options

You can also use Strategy.buy(..., stop=..., limit=...) parameters to enter the trade conditionally if the stop price is hit ...

You must be logged in to vote
0 replies
Comment options

@kernc
Although using 'stop' can implement a breakout strategy, the code cannot execute stop losses within the same bar—it can only do so at the earliest in the next bar. Is there a way to execute a trade at the breakout point and stop loss at the stop loss point if the price within the same bar has ever reached both the breakout level and the stop loss level? This would only make the backtest results lower than actual execution, which is better for users because underestimating results is preferable to overestimating them.

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants

AltStyle によって変換されたページ (->オリジナル) /