I would like ask support to define a custom indicator that I could not manage to work it properly. I want to create a binary signal based on AverageDirectionalMovementIndex where the value becomes "1" when it crosses down a upper threshold and stay still as 1 unless two other criteria met (Either it may cross down DirectionalMovementIndext strength line or cross up upperthreshold). In such cases, I am expecting the signal turn 0. In my code, I manage to receive "1" signal when ADX cross down uppertreshold but it does not stay 1 unless two other conditions are met. Any suggestions?
Thanks in advance
lines = ('adxsignal',) params = ( ('Trend_Strength', 20), ('ADX_Up_Tresh', 40), ('adx_period',7) ) def __init__(self): self.adx=bt.indicators.AverageDirectionalMovementIndex(period=self.params.adx_period) self.adxcross=bt.indicators.CrossOver(self.adx,self.params.ADX_Up_Tresh) self.adxreset=bt.indicators.CrossDown(self.adx,self.params.Trend_Strength) def next(self): self.trigger=0 if self.adxcross<0: self.trigger=1 elif self.adxreset>0: self.trigger=-1 elif self.adxcross>0: self.trigger=-1 self.lines.adxsignal=+ self.trigger