I have configured a trading calendar that contains daily sessions and I have the problem that the timestamp of the end of session is not being updated after the end of session has been reached.
I have tracked it down to the code where I think a condition is not met which makes it dismiss the end of session condition.
The scenario is like this:
- live paper trading using tick data getting resampled to
H1bars (10:00 to 18:00, 9 bars)
- The trading hours are
- As said, data is tick-based, but backfilling fills
The code I have pinpointed is in
resamplefilter.py in function
equal = dt == self._nextdteos grter = dt > self._nextdteos if exact: is_eos = equal else: # if the compared data goes over the endofsession # make sure the resampled bar is open and has something before that # end of session. It could be a weekend and nothing was delivered # until Monday if grter: is_eos = self.bar.isopen() and self.bar.datetime <= self._nextdteos else: is_eos = equal
In particular this condition:
is_eos = self.bar.isopen() and self.bar.datetime <= self._nextdteos
In the moment a backfilling H1 bar with timestamp
18:00 is coming in (and eos being
True so the if-clause in question is getting reached. The clause will render
False which in my opinion is the problem which will lead to not considering the session to have ended and therefore not fetching the next following eos timestamp.
The condition returns
False since the bar is not open because the
18:00-bar is the first data in the range from
17:00 - to
18:00 (because H1 bars always deliver a single data in each hour). This situation that a single bar opens a bar and goes beyond the end of the session is the core of the problem I guess cause of the
I am tempted to just remove the condition for me and set
grter is True but I feel I don't really understand what the condition is meant to do. I know there even is a multiline comment above it but I still fail to see under which condition the code. Would you give me a hint please regarding that if-condition? Especially what will go wrong when I remove it?
Also in general:
If I do live tick data resampling to H1 bars. Is it ok for the backtrader to still do backfill with H1 bars? I mean the resampler is expecting tick data but gets H1 bars fed in the beginning. But I think the Oanda data feed does the same so I thought it would be ok.
Many thanks for your help!