OPEN-SOURCE SCRIPT

Buy/Sell Zones – TV Style

94
//version=5
indicator("Buy/Sell Zones – TV Style", overlay=true, timeframe="", timeframe_gaps=true)

//=====================
// الإعدادات
//=====================
len = input.int(100, "Length", minval=10)
useATR = input.bool(true, "Use ATR (بدل الانحراف المعياري)")
mult = input.float(2.0, "Band Multiplier", step=0.1)
useRSI = input.bool(true, "تفعيل فلتر RSI")
rsiOB = input.int(70, "RSI Overbought", minval=50, maxval=90)
rsiOS = input.int(30, "RSI Oversold", minval=10, maxval=50)

//=====================
// القناة: أساس + انحراف
//=====================
basis = ta.linreg(close, len, 0)
off = useATR ? ta.atr(len) * mult : ta.stdev(close, len) * mult

upper = basis + off
lower = basis - off

// نطاق علوي/سفلي بعيد لعمل تعبئة المناطق
lookback = math.min(bar_index, 500)
topBand = ta.highest(high, lookback) + 50 * syminfo.mintick
bottomBand = ta.lowest(low, lookback) - 50 * syminfo.mintick

//=====================
// الرسم
//=====================
pUpper = plot(upper, "Upper", color=color.new(color.blue, 0), linewidth=1)
pLower = plot(lower, "Lower", color=color.new(color.red, 0), linewidth=1)
pBasis = plot(basis, "Basis", color=color.new(color.gray, 60), linewidth=2)

// تعبئة المناطق: فوق القناة (أزرق)، تحت القناة (أحمر)
pTop = plot(topBand, display=display.none)
pBottom = plot(bottomBand, display=display.none)

fill(pUpper, pTop, color=color.new(color.blue, 80)) // منطقة مقاومة/بيع
fill(pBottom, pLower, color=color.new(color.red, 80)) // منطقة دعم/شراء

//=====================
// خط أفقي من قمّة قريبة (يمثل مقاومة) – قريب من الخط المنقّط في الصورة
//=====================
resLen = math.round(len * 0.6)
dynRes = ta.highest(high, resLen)
plot(dynRes, "Recent Resistance", color=color.new(color.white, 0), linewidth=1)

//=====================
// إشارات BUY / SELL + فلتر RSI (اختياري)
//=====================
rsi = ta.rsi(close, 14)

touchLower = ta.crossover(close, lower) or close <= lower
touchUpper = ta.crossunder(close, upper) or close >= upper

buyOK = useRSI ? (touchLower and rsi <= rsiOS) : touchLower
sellOK = useRSI ? (touchUpper and rsi >= rsiOB) : touchUpper

plotshape(buyOK, title="BUY", location=location.belowbar, style=shape.labelup,
text="BUY", color=color.new(color.green, 0), textcolor=color.white, size=size.tiny, offset=0)
plotshape(sellOK, title="SELL", location=location.abovebar, style=shape.labeldown,
text="SELL", color=color.new(color.red, 0), textcolor=color.white, size=size.tiny, offset=0)

// تنبيهات
alertcondition(buyOK, title="BUY", message="BUY signal: price touched/closed below lower band (RSI filter may apply).")
alertcondition(sellOK, title="SELL", message="SELL signal: price touched/closed above upper band (RSI filter may apply).")

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.