Backtrader Community

    • 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/

    Backtrader Close the position after 5 days

    General Code/Help
    2
    2
    116
    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.
    • tsz fung Chan
      tsz fung Chan last edited by

      The trading logic is the close is higher than EMA200 then buy
      close is lower than EMA200 then close the position

      How can I code:
      if after 5 days no close signal (price is lower than EMA200) then close the position

      G 1 Reply Last reply Reply Quote 0
      • G
        goloap @tsz fung Chan last edited by

        @tsz-fung-chan You can keep track of the time data via the self.data.datetime.datetime() function. You can save this value when you enter a position; if the latest datapoint's timestamp is bigger than a defined length of time you can then exit the position.

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