PROTECTED SOURCE SCRIPT

EMRVA (2)

48
//version=5
indicator("EMRVA2)", overlay=true)

// === Inputs ===
emaLen = input.int(200, "EMA Length")
emaFilter = input.int(200, "Trend EMA Filter")
rsiLen = input.int(14, "RSI Length")
volLen = input.int(20, "Volume MA Length")
bodyLen = input.int(14, "Body SMA Length")
minBars = input.int(10, "Min Bars Before New Signal")
atrMult = input.float(0.5, "ATR Body Filter")
spikeATR = input.float(3.0, "Ignore if candle > ATR ×")

// === Heikin Ashi ===
haClose = (open + high + low + close) / 4.0
var float haOpen = na
haOpen := na(haOpen[1]) ? (open + close) / 2.0 : (haOpen[1] + haClose[1]) / 2.0
haHigh = math.max(high, math.max(haClose, haOpen))
haLow = math.min(low, math.min(haClose, haOpen))

// === MAs ===
ema21 = ta.ema(haClose, emaLen)
ema200 = ta.ema(haClose, emaFilter)
plot(ema21, color=color.orange, linewidth=2, title="EMA21")
plot(ema200, color=color.blue, linewidth=2, title="EMA200")

// === Indicators ===
macdLine = ta.ema(haClose, 12) - ta.ema(haClose, 26)
signalLine = ta.ema(macdLine, 9)
rsi = ta.rsi(haClose, rsiLen)

volMA = ta.sma(volume, volLen)
volCond = volume > volMA

bodySize = math.abs(haClose - haOpen)
avgBody = ta.sma(bodySize, bodyLen)
atr = ta.atr(14)
candleRange = high - low

// === فلتر الشمعة غير الطبيعية ===
isSpike = candleRange > atr * spikeATR

// === Conditions ===
longCond = haClose > ema21 and macdLine > signalLine and rsi > 50 and volCond and haClose > haOpen
shortCond = haClose < ema21 and macdLine < signalLine and rsi < 50 and volCond and haClose < haOpen

// === Filters ===
longCond := longCond and haClose > ema200 and bodySize > atr * atrMult and not isSpike
shortCond := shortCond and haClose < ema200 and bodySize > atr * atrMult and not isSpike

// === Signal management ===
var int lastSignalBar = na
var int lastSignalType = 0 // 0=none, 1=buy, -1=sell

enoughBars = na(lastSignalBar) or (bar_index - lastSignalBar >= minBars)

canBuy = longCond and enoughBars and (lastSignalType != 1)
canSell = shortCond and enoughBars and (lastSignalType != -1)

buySignal = canBuy
sellSignal = canSell

if buySignal
lastSignalBar := bar_index
lastSignalType := 1
if sellSignal
lastSignalBar := bar_index
lastSignalType := -1

plotshape(buySignal, title="BUY", location=location.belowbar, color=color.green, style=shape.labelup, text="BUY")
plotshape(sellSignal, title="SELL", location=location.abovebar, color=color.red, style=shape.labeldown, text="SELL")

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.