For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See:

create OHLC-array

  • Hi Backtraders,

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

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

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


    lastdataOHLC = [[[0:100],[0:100],[0:100],[0:100]]]

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


    lastdataOHLC = [[[0],[0],[0],[0]]]
    for i in range(1,100):
        lastdataOHLC = np.append(lastdataOHLC,[[[i],[i],[i],[i]]], axis=0)

    -> works, but finally Breakes 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!

  • What is the point of using this

    lastdataclose = np.array([ = 100)])

    but not simply this

    lastdataclose = = 100) # baktrader approach

  • 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 "" only gives close-data, not the whole row of data, with OHLC, Volume, date...right?!

Log in to reply