I am a beginner just trying to learn how to use backtrader. I have tried several times and looked at the documentation for adding a trailing stop loss but can't seem to figure it out.
Here is my simple test code:
ema3 = bt.ind.EMA(period = 3)
ema5 = bt.ind.EMA(period = 5)
ema50 = bt.ind.EMA(period = 50) ema60 = bt.ind.EMA(period = 60) cmin = bt.Min(ema3,ema5) cmax = bt.Max(ema50,ema60) self.crossover = bt.ind.CrossOver(cmin, cmax)
if not self.position: if self.crossover > 0: self.buy() elif self.crossover < 0: self.sell()
Can anyone explain how to add a trailing stop loss that trails by a 1%?