def process1(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) # # signals analysis # rsi_30_70 = 0 # -1 30, 1 70 rsi_40_60 = 0 # 1 if RSI in 40-60 volume_signal = 0 ema_sma_cross = 0 ema_sma_height = 0 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 # if self.volume.last > volume_sma[-1]: # volume_signal = 1 # elif self.volume.last < volume_sma[-1]: # 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 ema_sma_cross > 0 and rsi_30_70 > 0: signal = StrategySignal(self.tf, timestamp) signal.signal = StrategySignal.SIGNAL_ENTRY signal.dir = 1 signal.p = candles[-1].close elif ema_sma_cross < 0 and rsi_30_70 < 0: signal = StrategySignal(self.tf, timestamp) signal.signal = StrategySignal.SIGNAL_EXIT signal.dir = 1 signal.p = candles[-1].close if self.pivotpoint: self.pivotpoint.compute(last_timestamp, self.price.open, self.price.high, self.price.low, self.price.close) return signal
def is_cross_last(self, with_score): if len(self._scores < 2): return False return utils.cross((self._scores[-2], with_score._scores[-2]), self._scores[-1], with_score._scores[-1]) != 0
def process3(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.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.last > volume_sma[-1]: # volume_signal = 1 # elif self.volume.last < volume_sma[-1]: # 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.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) 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: self.tomdemark.compute(last_timestamp, self.price.timestamp, self.price.high, self.price.low, self.price.close) # # setup entry # # long entry on sell-setup + rsi oversell if (self.tomdemark.c.c == 2 and self.tomdemark.c.d < 0 and self.price.close[-1] > self.price.close[-2]) or ( self.tomdemark.c.c == 3): # avec td3 # if (td.c == 1 and td.d < 0 and candles[-1].close > candles[-2].close): # if (td.c == 2 and td.d < 0 and candles[-1].close > candles[-2].close): # if ((td.c == 2 or td.c == 3) and td.d < 0 and candles[-1].close > candles[-2].close): # if ((td.c == 2 or td.c == 3) and td.d < 0) and candles[-1].close > candles[-2].close: # if bb_break == 0: # if (bb_break == 0 and bb_ma < 0): # test with aggressive + bb # if (stochrsi_20_80 > 0 or rsi_30_70 > 0): # if (ema_sma_height > 0 or rsi_30_70 > 0) and bb_break >= 0: # if (bb_break == 0 and bb_ma < 0) and (stochrsi_20_80 > 0 or rsi_30_70 > 0): # used with average case but not with aggressive # if (bb_break == 0 and bb_ma < 0) and (ema_sma_height > 0 or rsi_30_70 > 0): # and volume_signal > 0: # if (stochrsi_20_80 > 0 or rsi_30_70 > 0): # la classique mais prend des risk, a voir avec un bon SL peut-être # if (rsi_trend > 0) and (ema_sma_height > 0 or rsi_30_70 > 0): # protege de perte mais rate des gains # if (ema_sma_height > 0 or rsi_30_70 > 0): # and volume_signal > 0: # C4 # if ema_sma_height > 0: # C5 # if ema_sma_height > 0 and bb_break >= 0 and rsi_trend > 0: # C6 # if ema_sma_height > 0 and bb_break >= 0 and stochrsi_20_80 > 0: # if 1: # C1 # if rsi_trend > 0 and bb_break > 0: # pas mal evite des entrees foireuses mais pas assez de profits if level1_signal > 0: # if (stochrsi_20_80 > 0 or rsi_30_70 > 0): # la classique mais prend des risk, il faut un bon stop-loss # if rsi_trend and (stochrsi_20_80 > 0 or rsi_30_70 > 0): # if (stochrsi_20_80 > 0 and rsi_30_70 > 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 # aggressive entry if self.tomdemark.c.c == 9 and self.tomdemark.c.d > 0: # if ((self.tomdemark.c.c == 9 or (self.tomdemark.c.c == 8 and self.tomdemark.c.p)) and self.tomdemark.c.d > 0): # if stochrsi_20_80 > 0 and rsi_30_70 > 0 and candles[-1].close > candles[-2].close: # C1 - # if 1: # C4 +++ # if stochrsi_20_80 > 0 and candles[-1].close > candles[-2].close: # C3 ++ # if rsi_30_70 > 0 and candles[-1].close > candles[-2].close: # C5 ?? # if ema_sma_height > 0 and bb_break >= 0 and rsi_trend > 0: # C6 ?? # if ema_sma_height > 0 and bb_break >= 0 and stochrsi_20_80 > 0: # C7 ?? # if (ema_sma_height > 0 or rsi_30_70 > 0): # C2 + # if 1: # if stochrsi_20_80 > 0 and candles[-1].close > candles[-2].close: # C3 ++ # if (stochrsi_20_80 > 0 or rsi_30_70 > 0): # C8 ?? if level1_signal > 0: signal = StrategySignal(self.tf, timestamp) signal.signal = StrategySignal.SIGNAL_ENTRY signal.dir = 1 signal.p = self.price.close[-1] # # invalidation 2 of opposite setup # # @todo or if a >= 3 <= 7 close below the previous candle close # can make loss in bull run # second condition might be optimized elif (self.tomdemark.c.c == 2 and self.tomdemark.c.d > 0 and self.price.close[-1] < self.price.close[-2]) or ( self.tomdemark.c.c == 3 and self.tomdemark.c.d > 0): # elif td.c == 3 and td.d > 0: # and self.price.close < self.price.close: # long cancelation on buy-setup formation # if ema_sma_height < 0 or rsi_40_60 > 0: # (excess of volume and ema under sma) # if stochrsi_20_80 < 0: # and volume_signal > 0: # if bb_break < 0: # if (rsi_trend < 0): # C2 # if ema_sma_height < 0: # and volume_signal > 0: if 1: # C1 + # if level1_signal < 0: # if (bb_break == 0 and bb_ma < 0): # C3 ++ signal = StrategySignal(self.tf, timestamp) signal.signal = StrategySignal.SIGNAL_EXIT # CANCEL signal.dir = 1 signal.p = self.price.close[-1] # # setup completed # elif (((self.tomdemark.c.c >= 8 and self.tomdemark.c.p) or (self.tomdemark.c.c == 9)) and self.tomdemark.c.d < 0): # and self.price.close[-1] > self.price.close[-2]: # if 1: # stochrsi_20_80 > 1: if 1: # if level1_signal < 0: signal = StrategySignal(self.tf, timestamp) signal.signal = StrategySignal.SIGNAL_EXIT signal.dir = 1 signal.p = self.price.close[-1] # # setup aborted # elif ((self.tomdemark.c.c >= 2 and self.tomdemark.c.c <= 7) and self.tomdemark.c.d < 0 ) and self.price.close[-1] < self.price.close[-2]: # C1 # if stochrsi_20_80 < 0 or rsi_30_70 < 0: # bearish stoch OR rsi # C1 # if stochrsi_20_80 < 0 and rsi_30_70 < 0: # bearish stoch AND rsi (seems better) # C2 if 1: # level1_signal < 0: signal = StrategySignal(self.tf, timestamp) signal.signal = StrategySignal.SIGNAL_EXIT signal.dir = 1 signal.p = self.price.close[-1] # # CD entry # if self.tomdemark.cd.c >= 1 and self.tomdemark.cd.c <= 3: # count-down buy-setup + rsi oversell if self.tomdemark.cd.d < 0: # and self.price.close[-1] > self.price.high[-2]: # if rsi_30_70 > 0: signal = StrategySignal(self.tf, timestamp) signal.signal = StrategySignal.SIGNAL_ENTRY signal.dir = 1 signal.p = self.price.close[-1] signal.sl = self.tomdemark.c.tdst # # CD13 setup # elif self.tomdemark.cd.c == 13: # count-down sell-setup completed if self.tomdemark.cd.d < 0: signal = StrategySignal(self.tf, timestamp) signal.signal = StrategySignal.SIGNAL_EXIT signal.p = self.price.close[-1] signal.dir = 1 return signal
def process1(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) # # signals analysis # rsi_30_70 = 0 # -1 30, 1 70 rsi_40_60 = 0 # 1 if RSI in 40-60 volume_signal = 0 ema_sma_cross = 0 ema_sma_height = 0 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 # if self.volume.last > volume_sma[-1]: # volume_signal = 1 # elif self.volume.last < volume_sma[-1]: # volume_signal = -1 if self.sma200: self.sma200.compute(last_timestamp, prices) if self.sma55: self.sma55.compute(last_timestamp, prices) 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 bb_way = 0 if self.bollingerbands: self.bollingerbands.compute(last_timestamp, prices) if self.bollingerbands.last_ma < prices[ -1] < self.bollingerbands.last_top: bb_way = -1 # if ema_sma_cross > 0 and rsi_30_70 > 0: # self.trend = 1 # elif ema_sma_cross < 0 and rsi_30_70 < 0: # signal = StrategySignal(self.tf, timestamp) # signal.signal = StrategySignal.SIGNAL_EXIT # signal.dir = 1 # signal.p = candles[-1].close # self.trend = -1 # else: # self.trend = 0 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 level1_signal < 0: signal = StrategySignal(self.tf, timestamp) signal.signal = StrategySignal.SIGNAL_EXIT signal.dir = 1 signal.p = candles[-1].close self.trend = -1 elif level1_signal > 0: self.trend = 1 else: self.trend = 0 self.can_long = self.trend >= 0 if self.pivotpoint: self.pivotpoint.compute(last_timestamp, self.price.open, self.price.high, self.price.low, self.price.close) if self.atr: self.atr.compute(last_timestamp, self.price.high, self.price.low, self.price.close) return signal