from core.models import Signal from strategies.base import Strategy from utils.indicators import rsi, atr, bollinger class RsiMeanRev(Strategy): name = "rsi_meanrev" def on_bar(self, symbol, df): p = self.p r = rsi(df.close, p["rsi_period"]) lo, _, hi = bollinger(df.close, p["bb_period"], p["bb_dev"]) a = atr(df, 14).iloc[-1] c = df.close.iloc[-1] if r.iloc[-1] < p["low"] and c < lo.iloc[-1]: return Signal(symbol, "buy", p["sl_atr"] * a, p["tp_atr"] * a, self.name, "RSI+BB oversold") if r.iloc[-1] > p["high"] and c > hi.iloc[-1]: return Signal(symbol, "sell", p["sl_atr"] * a, p["tp_atr"] * a, self.name, "RSI+BB overbought")