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/

    Understand long revers short logic

    General Code/Help
    3
    6
    145
    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.
    • J
      JAS2210 last edited by

      Hello,
      I find this in a blog https://backtest-rookies.com/2017/08/22/backtrader-multiple-data-feeds-indicators/?unapproved=1976&moderation-hash=b8dac3607f1017db7f47ff98c5d042e6#comment-1976

      regardless the multiple data feed. I am not fully understand the logic of the next method :

      pos = self.getposition(d).size
      if not pos:  # no market / no orders
                      if self.inds[d]['cross'][0] == 1:
                          self.buy(data=d, size=1000)
                      elif self.inds[d]['cross'][0] == -1:
                          self.sell(data=d, size=1000)
      else:
                      if self.inds[d]['cross'][0] == 1:
                          self.close(data=d)
                          self.buy(data=d, size=1000)
                      elif self.inds[d]['cross'][0] == -1:
                          self.close(data=d)
                          self.sell(data=d, size=1000)
      

      Suppose that we are not in position and first signal of the crossover is a long signal, ok we go long.

      Than I don’ t understand this:
      If the next bar is stil in crossover = 1 ( fast ma is above) what stops the self.close() command to close the the long submitted in the previous bar while open another non sense long in the same time/bar?
      What am I missing here? :/

      thx, regards

      run-out 1 Reply Last reply Reply Quote 0
      • run-out
        run-out @JAS2210 last edited by

        @jas2210 I can't see the indicator but I imagine it's a crossover indicator, meaning it only equals one or minus one when the signal crosses over, not the whole time it is over.

        RunBacktest.com

        J 1 Reply Last reply Reply Quote 1
        • J
          JAS2210 @run-out last edited by

          @run-out ahhh ok that's what I missed..
          And what value does crosover indicatore take from the moment when cross in one direction to the moment of crossing in the opposite direction? 0 ? or None?

          run-out 1 Reply Last reply Reply Quote 0
          • run-out
            run-out @JAS2210 last edited by

            @jas2210 It's here in the docs.

            RunBacktest.com

            J 1 Reply Last reply Reply Quote 0
            • J
              JAS2210 @run-out last edited by

              @run-out right thanks, it seems unknown the value between

              Tony Shacklock 1 Reply Last reply Reply Quote 0
              • Tony Shacklock
                Tony Shacklock @JAS2210 last edited by

                @jas2210
                The value will be 0 when there is no cross.
                From the docs:
                "Formula:

                • diff = data - data1
                • upcross = last_non_zero_diff < 0 and data0(0) > data1(0)
                • downcross = last_non_zero_diff > 0 and data0(0) < data1(0)
                • crossover = upcross - downcross"

                So when upcross = False (0) and downcross = False (0), then crossover = 0 - 0.

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