//@version=5 strategy(title="3ATR EMA Basic", shorttitle="3ATR-Basic", overlay=true, currency=currency.USD, initial_capital=10000, commission_type=strategy.commission.percent, commission_value=0.1) // Inputs ema_length = input.int(21, "EMA Length") atr_multiplier = input.float(3.0, "ATR Multiplier") bull_market_length = input.int(200, "Bull Market SMA Period") // Get daily close prices for market state calculation daily_close = request.security(syminfo.tickerid, "D", close) bull_market_sma = ta.sma(daily_close, bull_market_length) bull_market = daily_close > bull_market_sma // Calculations ema = ta.ema(close, ema_length) atr = ta.atr(ema_length) upper_band = ema + (atr * atr_multiplier) lower_band = ema - (atr * atr_multiplier) // Modified Entry Condition (requires bull market) bullish_entry = bull_market and (close < ema) and (close[1] <= lower_band[1]) and (close > close[1]) // Exit Condition (when price crosses upper band) bullish_exit = close > upper_band // Trade Execution if bullish_entry strategy.entry("Long", strategy.long) if bullish_exit strategy.close("Long") // Visualization - Add market state background bgcolor(bull_market ? color.new(color.green, 90) : color.new(color.red, 90), title="Market State") // Original visualizations plot(ema, "EMA", color=color.new(#4A90E2, 0)) plot(upper_band, "Upper", color=color.orange) plot(lower_band, "Lower", color=color.green) plotshape(bullish_entry ? low : na, style=shape.triangleup, location=location.belowbar, color=color.new(#00FF00, 0), size=size.small, title="Bull Entry") plotshape(bullish_exit ? high : na, style=shape.triangledown, location=location.abovebar, color=color.new(#FF0000, 0), size=size.small, title="Bull Exit")