For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
How to get the last value from line in next()?
-
Hello! This is my indicator
class TestIndicator(bt.Indicator): ... def next(self): dynamic_period = get_dynamic_period(self.data) sma = bt.indicators.SMA(self.data, period=dynamic_period) last_value = sma.get(-1) self.lines.dynamic_sma[0] = last_value # not work
How to get the last value from line in next()?
Thanks ! -
correction:
class TestIndicator(bt.Indicator): ... def next(self): dynamic_period = get_dynamic_period(self.data) sma = bt.indicators.SMA(self.data.close.get(0, self.p.data_period), period=dynamic_period) last_value = sma.get(-1) self.lines.dynamic_sma[0] = last_value # not work
-
@pizza You don't have a good grasp on using
init
and/ornext
. Please have a look here. https://www.backtrader.com/docu/induse/ -
@run-out Thanks!