kernc / kernc/backtesting.py

How to close on session end

Open
#1,290 1 comment 1 reaction 0 assignees View on GitHub
question
Dominant language
Python
Stars
9k
Forks
1.5k
PR merge metrics
No merged PRs in 30d

Description

Hello!

Let's say I'm backtesting futures, and the session ends every day at 16:00 and it starts again at 17:00. What if I want to close a trade at session close?

I can't do like `if self.data.df.index.time == "16:00": self.position.close()` otherwise the closing order will be executed at next bar, that would be the first bar of the new session.

I know I could close at one bar prior to the close, but I specifically need to close the trade at closing price of `16:00` bar for reproducibility reasons with another platform.

Also I'm aware of `trade_on_close`, but I still need trades to be opened at next bar open.

Any idea? Thanks

Contributor guide

Open the contributing guide

Research direction

The issue names no source file, test, or entry point. Start by locating the order-execution and session-boundary logic, then review existing tests for trade_on_close and session handling. Done should be a documented, tested way to close at the 16:00 bar while retaining next-bar-open entries.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.