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/

    Problem with too many closing trades.

    General Code/Help
    1
    1
    122
    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.
    • Jeffrey C F Wong
      Jeffrey C F Wong last edited by

      Hi everyone, I have the following codes where crossover_exit should only close when there is an existing long order and crossunder_exit should close when there is a ongoing short order. But my results shows that it is closes a trade whenever there is a crossover_exit or crossunder_exit condition, resulting in too many closes. It'd be great if someone can shine some light on this. Thank you in advance.

                  if not self.position:
                      if self.crossover:                  
                          self.buy()
                  
                      if self.crossunder:        
                          self.sell()
                  
                  if self.position.size!=0:                        
                      if self.position is self.buy and self.crossover_exit:
                          self.close()            
                     
                      if self.position is self.sell and self.crossunder_exit:
                          self.close()
      
      1 Reply Last reply Reply Quote 0
      • 1 / 1
      • First post
        Last post
      Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors