OPEN-SOURCE SCRIPT

XAUUSD Reversal Indicator (EMA + SND) - Fixed

134
//version=5
indicator("XAUUSD Reversal Indicator (EMA + SND) - Fixed", overlay=true)

// Exponential Moving Averages
ema50 = ta.ema(close, 50)
ema100 = ta.ema(close, 100)
ema200 = ta.ema(close, 200)

// Store EMA values at confirmed candles to prevent shifting
var float storedEMA50 = na
var float storedEMA100 = na
var float storedEMA200 = na

if bar_index % 1 == 0
storedEMA50 := ema50
storedEMA100 := ema100
storedEMA200 := ema200

// Identify Supply & Demand Zones
lengthSND = 50
demandZone = ta.lowest(low, lengthSND)
supplyZone = ta.highest(high, lengthSND)

// Store SND values at confirmed candles to prevent shifting
var float storedDemand = na
var float storedSupply = na

if bar_index % 1 == 0
storedDemand := demandZone
storedSupply := supplyZone

// Draw Supply & Demand Zones as Bands (Fixed)
plot(storedDemand, title="Demand Zone", color=color.green, linewidth=2, style=plot.style_stepline)
plot(storedSupply, title="Supply Zone", color=color.red, linewidth=2, style=plot.style_stepline)

// Buy Entry: Price Pulls Back to EMA 50 & Demand Zone
buyEntry = ta.crossover(close, storedEMA50) and close > storedDemand and storedEMA50 > storedEMA100 and storedEMA50 > storedEMA200

// Sell Entry: Price Pulls Back to EMA 50 & Supply Zone
sellEntry = ta.crossunder(close, storedEMA50) and close < storedSupply and storedEMA50 < storedEMA100 and storedEMA50 < storedEMA200

// Buy/Sell Entry Arrows
plotshape(series=buyEntry, location=location.belowbar, color=color.green, style=shape.labelup, title="Buy Entry")
plotshape(series=sellEntry, location=location.abovebar, color=color.red, style=shape.labeldown, title="Sell Entry")

// Alerts
alertcondition(buyEntry, title="Buy Entry Signal", message="Buy Entry Detected at Demand Zone")
alertcondition(sellEntry, title="Sell Entry Signal", message="Sell Entry Detected at Supply Zone")

// Background Highlighting (Fixed)
bgcolor(buyEntry ? color.new(color.green, 80) : sellEntry ? color.new(color.red, 80) : na)

// Plot EMAs (Fixed)
plot(storedEMA50, title="EMA 50", color=color.blue, linewidth=2)
plot(storedEMA100, title="EMA 100", color=color.purple, linewidth=2)
plot(storedEMA200, title="EMA 200", color=color.orange, linewidth=2)

إخلاء المسؤولية

لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.