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



  • 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!



  • 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
    


  • 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?!


Log in to reply
 

});