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/

    Selling all positions

    General Code/Help
    2
    2
    990
    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.
    • Ziyi Liew
      Ziyi Liew last edited by

      My algo currently makes multiple buys (self.buy()) but when a sell/stop is hit, the positions are sold separately at different times (using self.sell()). How can I sell all the open positions at once in one order?

      tianjixuetu 1 Reply Last reply Reply Quote 0
      • tianjixuetu
        tianjixuetu @Ziyi Liew last edited by

        @Ziyi-Liew maybe you can implement it by yourself,I don't know it has this function.But you can use a for-loop

        for data in self.datas:
             size=self.getposition(data).size
             if  size!=0:
                 self.close(data)
        

        this for loop will close all your position.

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