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/

    Last value of limted pattern length

    General Code/Help
    1
    2
    109
    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.
    • Kjiessar
      Kjiessar last edited by

      Hi everyone,

      what I'm trying to do is getting the last value of pattern recognition as a line. The data that is used in the pattern should be limitted.
      My current approach ending in an index error

      self.pattern_len =min(len(self.datas[0].open)-1, 10)
      self.PATTERN_CDLHARAMICROSS = bt.talib.CDLHARAMICROSS(self.datas[0].open.get(size= self.pattern_len), self.datas[0].high.get(size= self.pattern_len), self.datas[0].low.get(size= self.pattern_len), self.datas[0].close.get(size= self.pattern_len))[-1]
      
      IndexError: array index out of range
      

      I know it could probably be easier by just using the whole length for the pattern and just read the last value from the line.
      (Would that mean in every bar/step there would be an complete array of the pattern recognition?)

      Is the error, that it tries to establish the value before it has enough values? Why does my approach with min does not work?

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

        To answer my own question:

        def __init__(self):
            self.PATTERN_CDLHARAMICROSS = bt.talib.CDLHARAMICROSS(self.datas[0].open, self.datas[0].high, self.datas[0].low, self.datas[0].close)
        def next(self):
                self.log(self.PATTERN_CDLHARAMICROSS[0])
        

        gives exactly what i wanted. No doubled arrays and limiting the time line makes no sense here if it is applied to the whole line.
        Sorry for the stupid question.

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