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/

    Buying at the High of a Bar

    General Code/Help
    2
    2
    49
    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.
    • R
      rishabmah5 last edited by

      I am trying to write the order code where the program will buy at the high when my signal occurs. Below is the code I am using for order placement.

      self.order = self.buy(exectype=bt.Order.Stop, size=100, price=self.data.high[0], valid=dt.timedelta(days=1))
      

      For some reason, if the high is not met, the order is not getting canceled, and if there is another signal at a later time, instead of buying 100 shares, the program then buys 200, which means it is combining the share count. Does anyone know how to fix this?

      1 Reply Last reply Reply Quote 0
      • run-out
        run-out last edited by

        Maybe some of this thread helps? https://community.backtrader.com/topic/2/limit-order-with-a-day-valid-never-gets-executed-220/13

        RunBacktest.com

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