For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
strategy next() out of alginment
-
I am noticing something a little weird, and not exactly sure whats happening. I have a simple SMA strategy with a 5/20 cross, just like in the example in my init function:
self.sma_fast = self.p._movav(period=self.p.fast) self.sma_slow = self.p._movav(period=self.p.slow)
in my next() function:
self.logger.info(f'current pos: {self.position.size}') self.logger.info(f'{num2date(self.data.datetime[0])} \ close: {self.data.close[0]}') self.logger.info(f'current bar: {len(self)}') #so the indicators self.logger.info(self.sma_fast.lines[0].array[len(self)]) self.logger.info(self.sma_slow.lines[0].array[len(self)])
i verified with my data, that the date, and close price are accurate for the given bar, however the indicators produce the average(5/20) with the next bar's closing price
should this be the case? i would expect that they include up to the current bar. or am i misunderstanding how this works? thanks-
-
@adamb032 The next() method runs after a candle has been closed when all final ohlc data for that candle is available.
Does it answer your question?