from core.models import Signal from strategies.base import Strategy from utils.indicators import ema, atr class EmaAtr(Strategy): name = "ema_atr" def on_bar(self, symbol, df): p = self.p f, s, t = ema(df.close, p["fast"]), ema(df.close, p["slow"]), ema(df.close, p["trend"]) a = atr(df, p["atr_period"]).iloc[-1] up = f.iloc[-2] <= s.iloc[-2] and f.iloc[-1] > s.iloc[-1] and df.close.iloc[-1] > t.iloc[-1] dn = f.iloc[-2] >= s.iloc[-2] and f.iloc[-1] < s.iloc[-1] and df.close.iloc[-1] < t.iloc[-1] if up or dn: return Signal(symbol, "buy" if up else "sell", p["sl_atr"] * a, p["tp_atr"] * a, self.name, "EMA cross")