Numpy Array to LineBuffer
-
I'm doing some math in an indicator and in the process
LineBuffer
is converted into a Numpyndarray
. Is it possible to convert back?Example:
log_hl = np.log(self.datas[0].high / self.datas[0].low)
-
As one of the goals of backtrader is to NOT depend on external packages, there is neither a
@developing-coder said in Numpy Array to LineBuffer:
LineBuffer is converted into a Numpy ndarray
nor
@developing-coder said in Numpy Array to LineBuffer:
Is it possible to convert back?
You have gotten a standard Python
list
from from of the lines and used to create andarray
.In any case there is no need to do neither a nor b. Use
ApplyN
and use the function of your choosing (apparentlylog
) - 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.