For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
Buying N day high for trend following
-
I'm having trouble with a simple trend following strategy of buying 55 day highs. I tried using something similar to the
Ichimoku
indicator.hi_bar = Highest(self.data.high, period=self.p.period)
I get an error that
Highest
is not recognized.Thanks,
-
Seeing the code would make this easier to answer, but you are likely not importing these classes into your strategy code.
Something as follows:
import backtrader as bt import backtrader.indicators as btind hi_bar = btind.Highest(self.data.high, period=self.p.period)
-
The code by @randyt is 100% ok. Some versions ago and to reduce the number of needed imports, the main package gives direct access to subpackages, so you may also do
import backtrader as bt ... hi_bar = bt.indicators.Highest(...) ...
of for even less typing
import backtrader as bt ... hi_bar = bt.ind.Highest(...) ...