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 : Delayed Market Order Execution with Hour Data Feed

    General Code/Help
    1
    4
    28
    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.
    • AnsonCHOWcm
      AnsonCHOWcm last edited by

      Hello everyone,

      I am new to backtrader and I encounter the following problem and I cannot search for an solution on the community. May I have your help?

      My Data Feed is on Hour basis

      Screenshot 2022-05-27 at 12.47.30 AM.png

      I execute the trade and close the position by the following code :

      Screenshot 2022-05-27 at 12.49.49 AM.png

      Screenshot 2022-05-27 at 12.50.17 AM.png

      My Order suppose to be market order which is expected to trade at the open of next bar (next hour opening price)
      However, it turns out that the order execute on the next day but not next hour

      May I ask for your advise for executing the order at the coming hour instead of coming day

      Thank you very much

      AnsonCHOWcm 1 Reply Last reply Reply Quote 0
      • AnsonCHOWcm
        AnsonCHOWcm @AnsonCHOWcm last edited by

        For Further information, it seems the datetime of each bar has error

        I found that the datetime of each bar is in the following way:

        For example, suppose I feed hour data of 2021 - 12 -24
        Then those bars' datetime are supposed to be like
        2021-12-24 00:00:00
        2021-12-24 01:00:00
        2021-12-24 02:00:00
        ...

        However, each data bar of 2021 - 12 -24 have the datetime like the following:
        2021-12-24 23:59:59
        2021-12-24 23:59:59
        2021-12-24 23:59:59
        ...

        I am wondering whether the error lead to my order execution delay. For the datetime error problem, I found some posts talking about it. However, the problem still exist after following their solution

        1 Reply Last reply Reply Quote 0
        • AnsonCHOWcm
          AnsonCHOWcm last edited by

          I solved the problem. Thank you everyone.

          For Future Readers,

          The problem I mentioned actually is caused by the datetime error of the bar I mentioned in my second comment.

          To solve the datetime error of the bar,
          you have to align the timeframe and compression to your source during the data feed
          And you have to use PandasDataFeed to Feed the data in this case (In my case, YahooDataCSV cannot feed it properly)

          1 Reply Last reply Reply Quote 0
          • AnsonCHOWcm
            AnsonCHOWcm last edited by

            Please check the following post:

            https://community.backtrader.com/topic/5757/5min-data-from-yahoo

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