def compute(self, timestamp, last_timestamp, candles, prices, volumes): signal = None # volume sma, increase signal strength when volume increase over its SMA # volume_sma = utils.MM_n(self.depth-1, self.volume.volumes) if self.rsi: self.rsi.compute(timestamp, prices) if self.pivotpoint: if self.pivotpoint.compute_at_close and self.last_closed: self.pivotpoint.compute(timestamp, self.price.open, self.price.high, self.price.low, self.price.close) if self.atr: if self.last_closed: self.atr.compute(timestamp, self.price.high, self.price.low, self.price.close) if self.tomdemark: if self.tomdemark.compute_at_close and self.last_closed: # last_timestamp self.tomdemark.compute(timestamp, self.price.timestamp, self.price.high, self.price.low, self.price.prices) # sell-setup if self.tomdemark.c.c == 9 and self.tomdemark.c.d < 0: signal = StrategySignal(self.tf, timestamp) signal.signal = StrategySignal.SIGNAL_EXIT signal.dir = 1 signal.p = self.price.close[-1] # buy-setup elif self.tomdemark.c.c == 9 and self.tomdemark.c.d > 0: signal = StrategySignal(self.tf, timestamp) signal.signal = StrategySignal.SIGNAL_EXIT signal.dir = -1 signal.p = self.price.close[-1] if self.bsawe: if self.last_closed: # use OHLC4 as price in place of close bsawe = self.bsawe.compute(timestamp, self.price.high, self.price.low, self.price.prices) if bsawe > 0: signal = StrategySignal(self.tf, timestamp) signal.signal = StrategySignal.SIGNAL_ENTRY signal.dir = 1 signal.p = self.price.close[-1] if self.tomdemark.c.tdst: signal.sl = self.tomdemark.c.tdst if len(self.pivotpoint.resistances[2]): signal.tp = np.max(self.pivotpoint.resistances[2]) elif bsawe < 0: signal = StrategySignal(self.tf, timestamp) signal.signal = StrategySignal.SIGNAL_ENTRY signal.dir = -1 signal.p = self.price.close[-1] if self.tomdemark.c.tdst: signal.sl = self.tomdemark.c.tdst if len(self.pivotpoint.supports[2]): signal.tp = np.min(self.pivotpoint.supports[2]) return signal
def compute(self, timestamp, last_timestamp, candles, prices, volumes): signal = None # volume sma, increase signal strength when volume increase over its SMA # volume_sma = utils.MM_n(self.depth-1, self.volume.volumes) if self.rsi: self.rsi.compute(last_timestamp, prices) # if self.volume_ema: # self.volume_ema.compute(last_timestamp, volumes) # if self.volume.last > self.volume_ema.last: # volume_signal = 1 # elif self.volume.last < self.volume_ema.last: # volume_signal = -1 if self.pivotpoint: self.pivotpoint.compute(last_timestamp, self.price.open, self.price.high, self.price.low, self.price.close) # if self.bollingerbands: # self.bollingerbands.compute(last_timestamp, prices) # bb_break = 0 # bb_ma = 0 # if prices[-1] > self.bollingerbands.last_top: # bb_break = 1 # elif prices[-1] < self.bollingerbands.last_bottom: # bb_break = -1 # if prices[-1] > self.bollingerbands.last_ma: # bb_ma = -1 # elif prices[-1] > self.bollingerbands.last_ma: # bb_ma = 1 if self.atr: self.atr.compute(last_timestamp, self.price.high, self.price.low, self.price.close) if self.bbawe: # use OHLC4 as price in place of close bbawe = self.bbawe.compute(last_timestamp, self.price.high, self.price.low, self.price.prices) if self.tomdemark: self.tomdemark.compute(last_timestamp, self.price.timestamp, self.price.high, self.price.low, self.price.prices) level1_signal = 0 if bbawe > 0: signal = StrategySignal(self.tf, timestamp) signal.signal = StrategySignal.SIGNAL_ENTRY signal.dir = 1 signal.p = self.price.close[-1] if self.tomdemark.c.tdst: signal.sl = self.tomdemark.c.tdst if len(self.pivotpoint.resistances[2]): signal.tp = np.max(self.pivotpoint.resistances[2]) elif bbawe < 0: signal = StrategySignal(self.tf, timestamp) signal.signal = StrategySignal.SIGNAL_ENTRY signal.dir = -1 signal.p = self.price.close[-1] if self.tomdemark.c.tdst: signal.sl = self.tomdemark.c.tdst if len(self.pivotpoint.supports[2]): signal.tp = np.min(self.pivotpoint.supports[2]) # # setup completed # # sell-setup if self.tomdemark.c.c == 9 and self.tomdemark.c.d < 0: signal = StrategySignal(self.tf, timestamp) signal.signal = StrategySignal.SIGNAL_EXIT signal.dir = 1 signal.p = self.price.close[-1] # buy-setup elif self.tomdemark.c.c == 9 and self.tomdemark.c.d > 0: signal = StrategySignal(self.tf, timestamp) signal.signal = StrategySignal.SIGNAL_EXIT signal.dir = -1 signal.p = self.price.close[-1] return signal
def process_ch(self, timestamp, last_timestamp, candles, prices, volumes): """ Entry : EMA trend + RSI level + TD9 entry confirmation Exit : TD9 or opposite signal """ signal = None # volume sma, increase signal strength when volume increase over its SMA volume_sma = utils.MM_n(self.depth-1, self.volume.volumes) rsi_30_70 = 0 # 1 <30, -1 >70 rsi_40_60 = 0 # 1 if RSI in 40-60 rsi_trend = 0 stochrsi_20_80 = 0 # 1 <20, -1 >80 stochrsi_40_60 = 0 # 1 if stochRSI in 40-60 volume_signal = 0 ema_sma_cross = 0 ema_sma_height = 0 if self.tf == 4*60*60: self.sma200.compute(timestamp, prices) self.sma55.compute(timestamp, prices) if self.rsi: self.rsi.compute(timestamp, prices) if self.rsi.last < self.rsi_low: rsi_30_70 = 1.0 elif self.rsi.last > self.rsi_high: rsi_30_70 = -1.0 if self.rsi.last > 0.4 and self.rsi.last < 0.6: rsi_40_60 = 1 rsi_trend = utils.trend_extremum(self.rsi.rsis) # if self.stochrsi: # self.stochrsi.compute(timestamp, prices) # if self.stochrsi.last_k < 0.2: # stochrsi_20_80 = 1.0 # elif self.stochrsi.last_k > 0.8: # stochrsi_20_80 = -1.0 # if self.stochrsi.last_k > 0.4 and self.stochrsi.last_k < 0.6: # stochrsi_40_60 = 1 # if self.volume_ema: # self.volume_ema.compute(timestamp, volumes) # if self.volume.last > self.volume_ema.last: # volume_signal = 1 # elif self.volume.last < self.volume_ema.last: # volume_signal = -1 if self.sma and self.ema: self.sma.compute(timestamp, prices) self.ema.compute(timestamp, prices) # ema over sma crossing ema_sma_cross = utils.cross((self.ema.prev, self.sma.prev), (self.ema.last, self.sma.last)) if self.ema.last > self.sma.last: ema_sma_height = 1 elif self.ema.last < self.sma.last: ema_sma_height = -1 if self.bollingerbands: self.bollingerbands.compute(timestamp, prices) bb_break = 0 bb_ma = 0 if prices[-1] > self.bollingerbands.last_top: bb_break = 1 elif prices[-1] < self.bollingerbands.last_bottom: bb_break = -1 # if prices[-1] > self.bollingerbands.last_ma: # bb_ma = -1 # elif prices[-1] > self.bollingerbands.last_ma: # bb_ma = 1 if self.atr: if self.last_closed: self.atr.compute(timestamp, self.price.high, self.price.low, self.price.close) if self.pivotpoint: if self.pivotpoint.compute_at_close and self.last_closed: self.pivotpoint.compute(timestamp, self.price.open, self.price.high, self.price.low, self.price.close) level1_signal = 0 if self.ema.last < self.sma.last: # bear trend if self.rsi.last > 0.5: # initial: 0.5 level1_signal = -1 elif self.rsi.last < 0.2: # initial: 0.2 level1_signal = 1 else: # bull trend if self.rsi.last > 0.8: # initial: 0.8 level1_signal = -1 elif self.rsi.last < 0.6: # initial: 0.6 level1_signal = 1 if self.tomdemark: if self.tomdemark.compute_at_close and self.last_closed: # last_timestamp self.tomdemark.compute(timestamp, self.price.timestamp, self.price.high, self.price.low, self.price.close) # long entry on sell-setup if self.tomdemark.c.c >= 1 and self.tomdemark.c.c <= 6 and self.tomdemark.c.d < 0 and level1_signal > 0: signal = StrategySignal(self.tf, timestamp) signal.signal = StrategySignal.SIGNAL_ENTRY signal.dir = 1 signal.p = self.price.close[-1] if self.tomdemark.c.tdst: signal.sl = self.tomdemark.c.tdst if len(self.pivotpoint.resistances[1]): signal.tp = np.max(self.pivotpoint.resistances[1]) # Terminal.inst().info("Entry long %s %s" % (self.tomdemark.c.tdst, signal.sl), view='default') # short entry on buy-setup elif self.tomdemark.c.c >= 1 and self.tomdemark.c.c <= 6 and self.tomdemark.c.d > 0 and level1_signal < 0: signal = StrategySignal(self.tf, timestamp) signal.signal = StrategySignal.SIGNAL_ENTRY signal.dir = -1 signal.p = self.price.close[-1] if self.tomdemark.c.tdst: signal.sl = self.tomdemark.c.tdst if len(self.pivotpoint.supports[1]): signal.tp = np.min(self.pivotpoint.supports[1]) # Terminal.inst().info("Entry short %s %s" % (self.tomdemark.c.tdst, signal.sl), view='default') # aggressive long entry elif self.tomdemark.c.c >= 8 and self.tomdemark.c.d > 0 and level1_signal > 0: signal = StrategySignal(self.tf, timestamp) signal.signal = StrategySignal.SIGNAL_ENTRY signal.dir = 1 signal.p = self.price.close[-1] if len(self.pivotpoint.resistances[1]): signal.tp = np.max(self.pivotpoint.resistances[1]) # td9 cannot provide us a SL, take it from ATR signal.sl = self.atr.stop_loss(signal.dir) # Terminal.inst().info("Aggressive long entry %s %s" % (self.tomdemark.c.tdst, signal.sl), view='default') # aggressive long entry elif self.tomdemark.c.c >= 8 and self.tomdemark.c.d < 0 and level1_signal < 0: signal = StrategySignal(self.tf, timestamp) signal.signal = StrategySignal.SIGNAL_ENTRY signal.dir = -1 signal.p = self.price.close[-1] if len(self.pivotpoint.supports[1]): signal.tp = np.min(self.pivotpoint.supports[1]) # td9 cannot provide us a SL, take it from ATR signal.sl = self.atr.stop_loss(signal.dir) # Terminal.inst().info("Aggressive short entry %s %s" % (self.tomdemark.c.tdst, signal.sl), view='default') # # setup completed # # sell-setup elif self.tomdemark.c.c >= 8 and self.tomdemark.c.d < 0 and level1_signal < 0: signal = StrategySignal(self.tf, timestamp) signal.signal = StrategySignal.SIGNAL_EXIT signal.dir = 1 signal.p = self.price.close[-1] # Terminal.inst().info("Exit long %s %s c8p-c9 (%s%s)" % (self.strategy_trader.instrument.symbol, self.tf, self.tomdemark.c.c, 'p' if signal.p else ''), view='default') # buy-setup elif self.tomdemark.c.c >= 8 and self.tomdemark.c.d > 0 and level1_signal > 0: signal = StrategySignal(self.tf, timestamp) signal.signal = StrategySignal.SIGNAL_EXIT signal.dir = -1 signal.p = self.price.close[-1] # Terminal.inst().info("Exit short %s %s c8p-c9 (%s%s)" % (self.strategy_trader.instrument.symbol, self.tf, self.tomdemark.c.c, 'p' if signal.p else ''), view='default') # # setup aborted (@todo how to in this long/short case) # elif ((self.tomdemark.c.c >= 4 and self.tomdemark.c.c <= 7) and self.tomdemark.c.d < 0) and level1_signal < 0: signal = StrategySignal(self.tf, timestamp) signal.signal = StrategySignal.SIGNAL_EXIT signal.dir = 1 signal.p = self.price.close[-1] # Terminal.inst().info("Abort long %s %s c3-c7 (%s%s)" % (self.strategy_trader.instrument.symbol, self.tf, self.tomdemark.c.c, 'p' if signal.p else ''), view='default') elif ((self.tomdemark.c.c >= 4 and self.tomdemark.c.c <= 7) and self.tomdemark.c.d > 0) and level1_signal > 0: signal = StrategySignal(self.tf, timestamp) signal.signal = StrategySignal.SIGNAL_EXIT signal.dir = -1 signal.p = self.price.close[-1] # Terminal.inst().info("Abort long %s %s c3-c7 (%s%s)" % (self.strategy_trader.instrument.symbol, self.tf, self.tomdemark.c.c, 'p' if signal.p else ''), view='default') # # # # invalidation 2 of opposite setup # # # elif self.tomdemark.c.c > 2 and self.tomdemark.c.d > 0 and level1_signal < 0: # signal = StrategySignal(self.tf, timestamp) # signal.signal = StrategySignal.SIGNAL_EXIT # signal.dir = 1 # signal.p = self.price.close[-1] # Terminal.inst().info("Canceled long entry %s c2-c3, p:%s tf:%s" % (self.strategy_trader.instrument.symbol, signal.p, self.tf), view='default') if signal and signal.signal == StrategySignal.SIGNAL_ENTRY: # if level1_signal > 0 and len(self.pivotpoint.supports[1]): # # cancel if not below a support (long direction) # if self.price.last >= np.nanmax(self.pivotpoint.supports[1]): # level1_signal = 0 # if level1_signal < 0 and len(self.pivotpoint.resistances[1]): # # cancel if not above a resistance (short direction) # if self.price.last <= np.nanmin(self.pivotpoint.resistances[1]): # level1_signal = 0 if level1_signal > 0 and len(self.pivotpoint.supports[1]): # cancel if not below a support (long direction) if self.price.last >= np.nanmax(self.pivotpoint.supports[1]): level1_signal = 0 signal = None if level1_signal < 0 and len(self.pivotpoint.resistances[1]): # cancel if not below a resistance (short direction) if self.price.last <= np.nanmin(self.pivotpoint.resistances[1]): level1_signal = 0 signal = None return signal
def process_cb(self, timestamp, last_timestamp, candles, prices, volumes): """ Entry : EMA crossing + TD9 entry confirmation Exit : TD9 or opposite signal + EMA trend + RSI level """ signal = None # volume sma, increase signal strength when volume increase over its SMA volume_sma = utils.MM_n(self.depth-1, self.volume.volumes) rsi_30_70 = 0 # 1 <30, -1 >70 rsi_40_60 = 0 # 1 if RSI in 40-60 rsi_trend = 0 stochrsi_20_80 = 0 # 1 <20, -1 >80 stochrsi_40_60 = 0 # 1 if stochRSI in 40-60 volume_signal = 0 ema_sma_cross = 0 ema_sma_height = 0 if self.tf == Instrument.TF_4HOUR: self.sma200.compute(timestamp, prices) self.sma55.compute(timestamp, prices) if self.rsi: self.rsi.compute(timestamp, prices) if self.rsi.last < self.rsi_low: rsi_30_70 = 1.0 elif self.rsi.last > self.rsi_high: rsi_30_70 = -1.0 if self.rsi.last > 0.4 and self.rsi.last < 0.6: rsi_40_60 = 1 rsi_trend = utils.trend_extremum(self.rsi.rsis) # if self.stochrsi: # self.stochrsi.compute(timestamp, prices) # if self.stochrsi.last_k < 0.2: # stochrsi_20_80 = 1.0 # elif self.stochrsi.last_k > 0.8: # stochrsi_20_80 = -1.0 # if self.stochrsi.last_k > 0.4 and self.stochrsi.last_k < 0.6: # stochrsi_40_60 = 1 # if self.volume_ema: # self.volume_ema.compute(timestamp, volumes) # if self.volume.last > self.volume_ema.last: # volume_signal = 1 # elif self.volume.last < self.volume_ema.last: # volume_signal = -1 if self.sma and self.ema: self.sma.compute(timestamp, prices) self.ema.compute(timestamp, prices) # ema over sma crossing ema_sma_cross = utils.cross((self.ema.prev, self.sma.prev), (self.ema.last, self.sma.last)) if self.ema.last > self.sma.last: ema_sma_height = 1 elif self.ema.last < self.sma.last: ema_sma_height = -1 # if self.bollingerbands: # self.bollingerbands.compute(timestamp, prices) # bb_break = 0 # bb_ma = 0 # if prices[-1] > self.bollingerbands.last_top: # bb_break = 1 # elif prices[-1] < self.bollingerbands.last_bottom: # bb_break = -1 # # if prices[-1] > self.bollingerbands.last_ma: # # bb_ma = -1 # # elif prices[-1] > self.bollingerbands.last_ma: # # bb_ma = 1 if self.atr: if self.last_closed: self.atr.compute(timestamp, self.price.high, self.price.low, self.price.close) if self.pivotpoint: if self.pivotpoint.compute_at_close and self.last_closed: self.pivotpoint.compute(timestamp, self.price.open, self.price.high, self.price.low, self.price.close) if self.bsawe: if self.last_closed: # use OHLC4 as price in place of close bsawe = self.bsawe.compute(timestamp, self.price.high, self.price.low, self.price.prices) # # trend signal # ema_rsi_signal = 0 if self.ema.last < self.sma.last: # bear trend if self.rsi.last > 0.5: # initial: 0.5 ema_rsi_signal = -1 elif self.rsi.last < 0.2: # initial: 0.2 ema_rsi_signal = 1 else: # bull trend if self.rsi.last > 0.8: # initial: 0.8 ema_rsi_signal = -1 elif self.rsi.last < 0.6: # initial: 0.6 ema_rsi_signal = 1 # # entry computation # if bsawe > 0 and ema_rsi_signal != -1: # long entry signal = StrategySignal(self.tf, timestamp) signal.signal = StrategySignal.SIGNAL_ENTRY signal.dir = 1 signal.p = self.price.close[-1] if self.tomdemark.c.tdst and signal.sl < signal.p: signal.sl = self.tomdemark.c.tdst if len(self.pivotpoint.resistances[2]): tp = np.max(self.pivotpoint.resistances[2]) if tp > self.atr.stop_loss(-1): # try with twice (same for short) signal.tp = (tp - signal.p) * 2.0 + signal.p # signal.tp = tp elif bsawe < 0 and ema_rsi_signal != 1: # short entry signal = StrategySignal(self.tf, timestamp) signal.signal = StrategySignal.SIGNAL_ENTRY signal.dir = -1 signal.p = self.price.close[-1] if self.tomdemark.c.tdst and signal.sl > signal.p: signal.sl = self.tomdemark.c.tdst if len(self.pivotpoint.supports[2]): tp = np.min(self.pivotpoint.supports[2]) if tp < self.atr.stop_loss(1): signal.tp = signal.p - (signal.p - tp) * 2.0 # signal.tp = tp # # exit computation # if self.tomdemark: if self.tomdemark.compute_at_close and self.last_closed: # last_timestamp self.tomdemark.compute(timestamp, self.price.timestamp, self.price.high, self.price.low, self.price.close) # only on 5min timeframe, or could manage at strategy only for parent timeframe # sell-setup if self.tomdemark.c.c >= 8 and self.tomdemark.c.d < 0 and ema_rsi_signal < 0 and self.tf == Instrument.TF_5MIN: signal = StrategySignal(self.tf, timestamp) signal.signal = StrategySignal.SIGNAL_EXIT signal.dir = 1 signal.p = self.price.close[-1] # buy-setup elif self.tomdemark.c.c >= 8 and self.tomdemark.c.d > 0 and ema_rsi_signal > 0 and self.tf == Instrument.TF_5MIN: signal = StrategySignal(self.tf, timestamp) signal.signal = StrategySignal.SIGNAL_EXIT signal.dir = -1 signal.p = self.price.close[-1] # # setup aborted (@todo how to in this long/short case) # elif ((self.tomdemark.c.c >= 4 and self.tomdemark.c.c <= 7) and self.tomdemark.c.d < 0) and ema_rsi_signal < 0 and self.tf == Instrument.TF_5MIN: signal = StrategySignal(self.tf, timestamp) signal.signal = StrategySignal.SIGNAL_EXIT signal.dir = 1 signal.p = self.price.close[-1] elif ((self.tomdemark.c.c >= 4 and self.tomdemark.c.c <= 7) and self.tomdemark.c.d > 0) and ema_rsi_signal > 0 and self.tf == Instrument.TF_5MIN: signal = StrategySignal(self.tf, timestamp) signal.signal = StrategySignal.SIGNAL_EXIT signal.dir = -1 signal.p = self.price.close[-1] return signal
def process4(self, timestamp, last_timestamp, candles, prices, volumes): signal = None # volume sma, increase signal strength when volume increase over its SMA volume_sma = utils.MM_n(self.depth-1, self.volume.volumes) rsi_30_70 = 0 # 1 <30, -1 >70 rsi_40_60 = 0 # 1 if RSI in 40-60 rsi_trend = 0 stochrsi_20_80 = 0 # 1 <20, -1 >80 stochrsi_40_60 = 0 # 1 if stochRSI in 40-60 volume_signal = 0 ema_sma_cross = 0 ema_sma_height = 0 if self.tf == 4*60*60: self.sma200.compute(last_timestamp, prices) self.sma55.compute(last_timestamp, prices) if self.rsi: self.rsi.compute(last_timestamp, prices) if self.rsi.last < self.rsi_low: rsi_30_70 = 1.0 elif self.rsi.last > self.rsi_high: rsi_30_70 = -1.0 if self.rsi.last > 0.4 and self.rsi.last < 0.6: rsi_40_60 = 1 rsi_trend = utils.trend_extremum(self.rsi.rsis) # if self.stochrsi: # self.stochrsi.compute(last_timestamp, prices) # if self.stochrsi.last_k < 0.2: # stochrsi_20_80 = 1.0 # elif self.stochrsi.last_k > 0.8: # stochrsi_20_80 = -1.0 # if self.stochrsi.last_k > 0.4 and self.stochrsi.last_k < 0.6: # stochrsi_40_60 = 1 # if self.volume_ema: # self.volume_ema.compute(last_timestamp, volumes) # if self.volume.last > self.volume_ema.last: # volume_signal = 1 # elif self.volume.last < self.volume_ema.last: # volume_signal = -1 if self.sma and self.ema: self.sma.compute(last_timestamp, prices) self.ema.compute(last_timestamp, prices) # ema over sma crossing ema_sma_cross = utils.cross((self.ema.prev, self.sma.prev), (self.ema.last, self.sma.last)) if self.ema.last > self.sma.last: ema_sma_height = 1 elif self.ema.last < self.sma.last: ema_sma_height = -1 if self.pivotpoint: self.pivotpoint.compute(last_timestamp, self.price.open, self.price.high, self.price.low, self.price.close) if self.bollingerbands: self.bollingerbands.compute(last_timestamp, prices) bb_break = 0 bb_ma = 0 if prices[-1] > self.bollingerbands.last_top: bb_break = 1 elif prices[-1] < self.bollingerbands.last_bottom: bb_break = -1 # if prices[-1] > self.bollingerbands.last_ma: # bb_ma = -1 # elif prices[-1] > self.bollingerbands.last_ma: # bb_ma = 1 if self.atr: self.atr.compute(last_timestamp, self.price.high, self.price.low, self.price.close) if self.bbawe: bbawe = self.bbawe.compute(last_timestamp, self.price.high, self.price.low, self.price.close) if self.tomdemark: self.tomdemark.compute(last_timestamp, self.price.timestamp, self.price.high, self.price.low, self.price.close) level1_signal = 0 # if self.ema.last < self.sma.last: # # bear trend # if self.rsi.last > 0.5: # initial: 0.5 # level1_signal = -1 # elif self.rsi.last < 0.2: # initial: 0.2 # level1_signal = 1 # else: # # bull trend # if self.rsi.last > 0.8: # initial: 0.8 # level1_signal = -1 # elif self.rsi.last < 0.6: # initial: 0.6 # level1_signal = 1 # if self.ema.last < self.sma.last: # level1_signal = -1 # else: # level1_signal = 1 # if level1_signal > 0 and bb_break <= 0: # level1_signal = 0 # elif bb_break > 0 and level1_signal >= 0: # level1_signal = 1 # if bb_break > 0: # level1_signal = 1 if bbawe > 0: signal = StrategySignal(self.tf, timestamp) signal.signal = StrategySignal.SIGNAL_ENTRY signal.dir = 1 signal.p = self.price.close[-1] if self.tomdemark.c.tdst: signal.sl = self.tomdemark.c.tdst if len(self.pivotpoint.resistances[2]): signal.tp = np.max(self.pivotpoint.resistances[2]) elif bbawe < 0: signal = StrategySignal(self.tf, timestamp) signal.signal = StrategySignal.SIGNAL_ENTRY signal.dir = -1 signal.p = self.price.close[-1] if self.tomdemark.c.tdst: signal.sl = self.tomdemark.c.tdst if len(self.pivotpoint.supports[2]): signal.tp = np.min(self.pivotpoint.supports[2]) # # setup completed # # sell-setup if self.tomdemark.c.c == 9 and self.tomdemark.c.d < 0: signal = StrategySignal(self.tf, timestamp) signal.signal = StrategySignal.SIGNAL_EXIT signal.dir = 1 signal.p = self.price.close[-1] # buy-setup elif self.tomdemark.c.c == 9 and self.tomdemark.c.d > 0: signal = StrategySignal(self.tf, timestamp) signal.signal = StrategySignal.SIGNAL_EXIT signal.dir = -1 signal.p = self.price.close[-1] # if signal and signal.signal == StrategySignal.SIGNAL_ENTRY: # # if level1_signal > 0 and len(self.pivotpoint.supports[1]): # # # cancel if not below a support (long direction) # # if self.price.last >= np.nanmax(self.pivotpoint.supports[1]): # # level1_signal = 0 # # if level1_signal < 0 and len(self.pivotpoint.resistances[1]): # # # cancel if not above a resistance (short direction) # # if self.price.last <= np.nanmin(self.pivotpoint.resistances[1]): # # level1_signal = 0 # if level1_signal > 0 and len(self.pivotpoint.supports[1]): # # cancel if not below a support (long direction) # if self.price.last >= np.nanmax(self.pivotpoint.supports[1]): # level1_signal = 0 # signal = None # if level1_signal < 0 and len(self.pivotpoint.resistances[1]): # # cancel if not below a resistance (short direction) # if self.price.last <= np.nanmin(self.pivotpoint.resistances[1]): # level1_signal = 0 # signal = None return signal