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/

    Simple DMI strategy gives only buy

    Indicators/Strategies/Analyzers
    2
    2
    96
    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.
    • I
      Izem last edited by

      Hello all!

      I'm trying to implement a simple DMI strategy where:
      buy when ADX > 25 & DIPlus > DIMinus
      sell when ADX > 25 & DI Plus < DIMinus

      Here is the strategy:

      class DMI(bt.Strategy):
      
          def __init__(self):
              self.dmi = bt.ind.DirectionalMovementIndex()
      
          def next(self):
              if not self.position:
                  if self.dmi.adx[0] > 25 and (self.dmi.DIplus[0] > self.dmi.DIminus[0]):
                      self.buy()
      
              else:
                  if self.dmi.adx[0] > 25 and (self.dmi.DIplus[0] < self.dmi.DIminus[0]):
                      self.close()
      

      The strategy runs but gives an incorrect result as it buys once and never sells.

      Figure_0.png

      Someone has an idea of what's going on?
      Thanks

      1 Reply Last reply Reply Quote 0
      • Jockrs 0
        Jockrs 0 last edited by

        The directional movement indicator (also known as the directional movement index or DMI) is a valuable.

        Visit My Website: Jockrs

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