//@version=6
strategy("Momentum Trend Strategy: Buy/Cautious/Add/Sell with EMA Filter",
overlay=true, margin_long=100, margin_short=100)
// === Technical Indicators ===
rsi = ta.rsi(close, 14)
ema21 = ta.ema(close, 21)
ema50 = ta.ema(close, 50)
ema100 = ta.ema(close, 100)
ema200 = ta.ema(close, 200)
// 30-week WMA approximated as 150-day WMA
wma30 = ta.wma(close, 150)
plot(wma30, title='30 Week WMA', color=color.rgb(243, 8, 8))
// === Buy Condition: Candle Pattern + RSI + EMA Filter ===
buyTrend = high > high[1] and high[1] > high[2] and low > low[1] and low[1] >
low[2] and close > close[1] and close[1] > close[2] and close > wma30
rsiOk = rsi > 50
emaOk = ema21 > ema50
buyCond = buyTrend and rsiOk and emaOk
// === Sell Condition ===
sellTrend = high < high[1] and high[1] < high[2] and low < low[1] and low[1] <
low[2] and close < close[1] and close[1] < close[2]
sellCond = sellTrend and close < ema21
// === Cautious Condition ===
cautiousCond = high < high[1] and close < close[1] and low < low[1]
// === Add More: bounce after EMA21, after Cautious, not after Sell ===
bounceFromEMA = close > close[1] and close > ema21 and close[1] <= ema21
// === Signal Tracking ===
var string trend = 'none'
var string lastSignal = 'none'
newBuy = buyCond and trend != 'buy'
newSell = sellCond and trend != 'sell'
newCautious = cautiousCond and (trend == 'buy' or trend == 'add') and trend !=
'cautious'
newAdd = buyCond and trend == 'cautious' and lastSignal != 'sell'
// === Update Trend & Signal States ===
if newBuy
trend := 'buy'
lastSignal := 'buy'
else if newAdd
trend := 'add'
lastSignal := 'add'
else if newSell
trend := 'sell'
lastSignal := 'sell'
else if newCautious
trend := 'cautious'
lastSignal := 'cautious'
// === Plot Signals ===
plotshape(newBuy, title='Buy', location=location.belowbar, color=color.green,
style=shape.labelup, text='B', offset=-1)
plotshape(newAdd, title='Add More', location=location.belowbar, color=color.teal,
style=shape.labelup, text='A', offset=-1)
plotshape(newSell, title='Sell', location=location.abovebar, color=color.red,
style=shape.labeldown, text='S', offset=-1)
plotshape(newCautious, title='Cautious', location=location.abovebar,
color=color.orange, style=shape.triangledown, text='⚠️', offset=-1)
// === Strategy Execution ===
// Entry conditions
if (newBuy)
strategy.entry("Main Long", strategy.long)
if (newAdd)
strategy.entry("Add Position", strategy.long)
// Exit condition
if (newSell)
strategy.close_all()
// === Performance Tracking ===
var float entryPrice = na
if (newBuy or newAdd)
entryPrice := close
if (newSell and not na(entryPrice))
profitPct = (close - entryPrice) / entryPrice * 100
label.new(bar_index, high,
text=str.tostring(profitPct, "#.##") + "%",
color=profitPct >= 0 ? color.green : color.red,
style=profitPct >= 0 ? label.style_label_up : label.style_label_down,
yloc=yloc.abovebar)
entryPrice := na
// Optional Risk Management
// strategy.exit("Take Profit/Stop Loss", "Main Long", stop=close*0.98,
limit=close*1.15)
// strategy.exit("Take Profit/Stop Loss", "Add Position", stop=close*0.98,
limit=close*1.15)