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/

    How to know whether 2 lines are crossing?

    General Code/Help
    3
    6
    38
    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.
    • C
      crypto_trader last edited by

      How to find out when 2 lines are crossing?
      Let's say I have a Strategy with indicator 2 lines, I want to execute an order once the to 2 indicator lines are crossing. I tried if (self.l.indicator1[0]-self.l.indicator2[0]) == 0 but this is not working of course, especially if the timeframe is not 1 Minute.

      E 1 Reply Last reply Reply Quote 0
      • E
        EMR @crypto_trader last edited by

        @crypto_trader Crossing mean one line was above the other on previous period, and is under on current period.
        This logic could be written like that :

        if (self.l.indicator1[1]>self.l.indicator2[1]) and (self.l.indicator1[0]<self.l.indicator2[0]):
        

        You may want to read below links, for a more efficient implementation :
        https://community.backtrader.com/topic/231/how-to-generate-crossover-signal-with-slowk-and-slowd-from-talib-and-or-bt-stochastic-fonction
        https://www.backtrader.com/blog/posts/2017-02-04-crossing-over-numbers/crossing-over-numbers/
        and have a look at crossover.py indicator.

        C 1 Reply Last reply Reply Quote 0
        • C
          crypto_trader @EMR last edited by

          unfortunately there is a error message:
          return self.array[self.idx + ago]
          IndexError: array index out of range

          E run-out 3 Replies Last reply Reply Quote 0
          • E
            EMR @crypto_trader last edited by

            @crypto_trader With crossover indicator ? with the if <...> and <...> logic ? You may get a faster and more accurate help if you post the part of your code which cause this error.

            1 Reply Last reply Reply Quote 0
            • E
              EMR @crypto_trader last edited by

              @crypto_trader try crossover indicator, or :

              if (self.l.indicator1[-1]>self.l.indicator2[-1]) and (self.l.indicator1[0]<self.l.indicator2[0]):
              
              1 Reply Last reply Reply Quote 0
              • run-out
                run-out @crypto_trader last edited by

                @crypto_trader I think you should consider CrossUp and CrossDown

                1 Reply Last reply Reply Quote 0
                • 1 / 1
                • First post
                  Last post
                Copyright © 2016, 2017, 2018 NodeBB Forums | Contributors
                $(document).ready(function () { app.coldLoad(); }); }