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/

    Square off on last/current bar close?

    General Code/Help
    2
    4
    314
    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.
    • Deepak Pandey
      Deepak Pandey last edited by

      How do I add a mandatory square off on the last bar of the backtest or a square off on the close of the current bar when a condition is met.

      Thanks in advance.

      1 Reply Last reply Reply Quote 0
      • B
        backtrader administrators last edited by

        And what is a "square off"?

        1 Reply Last reply Reply Quote 0
        • Deepak Pandey
          Deepak Pandey last edited by

          @backtrader said in Square off on last/current bar close?:

          And what is a "square off"?

          Means closing all open position. I want to close my open position when the condition met.

          1 Reply Last reply Reply Quote 0
          • B
            backtrader administrators last edited by backtrader

            @Deepak-Pandey said in Square off on last/current bar close?:

            on the last bar of the backtest

            The last bar is the last and has already been seen by the broker. You cannot close positions when the bar is the last one. Only if you use cheat-on-open (which means you do it before seeing the bar unless you choose to really cheat yourself)

            • Docs - Broker - Cheat-On-Open - https://www.backtrader.com/docu/cerebro/cheat-on-open/cheat-on-open/

            @Deepak-Pandey said in Square off on last/current bar close?:

            on the close of the current bar when a condition is met

            Using cheat-on-close in the broker and methods of the strategy, like close, buy, sell, order_target_percent, depending on your personal taste.

            • Docs - Broker - https://www.backtrader.com/docu/broker/
            • Docs - Strategy - https://www.backtrader.com/docu/strategy/
            1 Reply Last reply Reply Quote 1
            • 1 / 1
            • First post
              Last post
            Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors