Numpy Array to LineBuffer
Developing Coder last edited by Developing Coder
I'm doing some math in an indicator and in the process
LineBufferis converted into a Numpy
ndarray. Is it possible to convert back?
log_hl = np.log(self.datas.high / self.datas.low)
As one of the goals of backtrader is to NOT depend on external packages, there is neither a
LineBuffer is converted into a Numpy ndarray
Is it possible to convert back?
You have gotten a standard Python
listfrom from of the lines and used to create a
In any case there is no need to do neither a nor b. Use
ApplyNand use the function of your choosing (apparently
log) - Docs - Indicator Reference
im not particularly sure that it matters, but there is a workaround:
inside your indicator class
from copy import deepcopy some_data_linebuff = deepcopy(self.data.close) my_new_array = [.....] #same len as self.data.close for idx in range(len(my_new_array)): some_data_linebuff.set(my_new_array[idx], ago=idx) self.lines.new_line = some_data_linebuff
basically whats happening is you make a copy of a linebuffer object, with all the dates already determined, and then reassign all the values for your array into it. presto chango.