Buying N day high for trend following
mpgentleman last edited by backtrader
I'm having trouble with a simple trend following strategy of buying 55 day highs. I tried using something similar to the
hi_bar = Highest(self.data.high, period=self.p.period)
I get an error that
Highestis not recognized.
RandyT last edited by
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(...) ...