trailing stop order with trailamount=ATR
-
I have followed the post Mixing Timeframes in Indicators to resample my minute data to get daily data and then calculate ATR from daily data.
self.atr = btindic.ATR(self.datas[1], plot=True)
Then I would like to implement stoptrail orders whose trailamount equaLs to current ATR value
def next(self): current_atr = self.atr() #I unerstand self.atr() as a LineCoupler which fills the daily atr values with the latest value to make it minute frequency. if buy: self.buy(exectype=bt.Order.StopTrail, trailamount=current_atr)
I got error:
if self.trailamount: TypeError: __nonezero__ should return boll or int, returned LineOwnOperations
I suppose I should supply trailamount by an explicit numeric value, but how to get this value?
Many thanks for help!
-
You cannot send an order to your broker and tell your broker to adjust the trail amount according to the value of an indicator you have (it's the
ATR
but it could be anything)If you want to follow the value of the
ATR
you have to constantly monitor the value and decide whether to launch an order or not.