diff --git a/pinescripts/Three_ATR_EMA.pine b/pinescripts/Three_ATR_EMA.pine index dcf5bb9..692b446 100644 --- a/pinescripts/Three_ATR_EMA.pine +++ b/pinescripts/Three_ATR_EMA.pine @@ -4,6 +4,12 @@ strategy(title="3ATR EMA Basic", shorttitle="3ATR-Basic", overlay=true, currency // 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) @@ -11,8 +17,9 @@ atr = ta.atr(ema_length) upper_band = ema + (atr * atr_multiplier) lower_band = ema - (atr * atr_multiplier) -// Entry Condition -bullish_entry = (close < ema) and +// Modified Entry Condition (requires bull market) +bullish_entry = bull_market and + (close < ema) and (close[1] <= lower_band[1]) and (close > close[1]) @@ -26,7 +33,10 @@ if bullish_entry if bullish_exit strategy.close("Long") -// Visualization +// 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)