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/

    create OHLC-array

    Indicators/Strategies/Analyzers
    2
    3
    339
    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.
    • T
      TraderOnes last edited by

      Hi Backtraders,

      my Indicator-calculations works fine with 100 close-data (oneColum-array).

      class myIndi(bt.Indicator):
          def next(self):              
              lastdataclose = np.array([self.data.get(size = 100)])
      

      Great.
      But now I need to enhance oneColumn to 4Column-array (OHLC).
      But my cerabro explodes...

      Error:

      lastdataOHLC = [[self.data.open[0:100], self.data.high[0:100], self.data.low[0:100], self.data.close[0:100]]]
      

      ->Gives: "TypeError: unsupported operand type(s) for +: 'int' and 'slice'"

      Error:

      lastdataOHLC = [[self.data.open[0], self.data.high[0], self.data.low[0], self.data.close[0]]]
      for i in range(1,100):
          lastdataOHLC = np.append(lastdataOHLC,[[self.data.open[i], self.data.high[i], self.data.low[i], self.data.close[i]]], axis=0)
      

      -> works, but finally Breakes cerebro.run() after a while, even in un-vectorized mode (runonce=False)): "index out of range"

      All data should exist. but how address and slice? which array?
      Or can be read out from self.array? self.linebuffer? self. lineseries?
      Needs to be build with np.append?

      How to have [0] actuell within realtimeTrading? with every "next" the strategie?

      Where to place it?

      • Indicator-Class: init or next?
      • Strategie-Class: init or next?

      And finally the 4Column-Array (OHLC) will need even more columns (Indicator-values) without crashing the framework.
      Anybody with this usecase?
      I could not find anything in docs and community-topics...

      Thanks and Cheers in advance!

      1 Reply Last reply Reply Quote 0
      • A
        ab_trader last edited by

        What is the point of using this

        lastdataclose = np.array([self.data.get(size = 100)])
        

        but not simply this

        lastdataclose = self.data.get(size = 100) # baktrader approach
        
        • If my answer helped, hit reputation up arrow at lower right corner of the post.
        • Python Debugging With Pdb
        • New to python and bt - check this out
        1 Reply Last reply Reply Quote 0
        • T
          TraderOnes last edited by

          it is needed to be an numpy-array finally, to be understood by Tensorflow.
          But anyway, this works, as this is an oneColumn-array with only close-data.

          The question is, how to get an OHLC-fourColumn-array, in which the first row [0] allways actuell ...
          I have printed it out and "self.get.data" only gives close-data, not the whole row of data, with OHLC, Volume, date...right?!

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