Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

    Problem: End Of Session not being updated

    General Code/Help
    1
    1
    177
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • vbs
      vbs last edited by

      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 H1 bars (10:00 to 18:00, 9 bars)
      • The trading hours are 9:00 to 17:35
      • As said, data is tick-based, but backfilling fills H1 bars (!)

      The code I have pinpointed is in resamplefilter.py in function _eoscheck:

              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 17:35) then equal is False but grter is True so the if-clause in question is getting reached. The clause will render is_eos to 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 bar.isopen condition.

      I am tempted to just remove the condition for me and set is_eos to True when 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!

      1 Reply Last reply Reply Quote 0
      • 1 / 1
      • First post
        Last post
      Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors