//version=4
study(title="EMA & MA Crossover with Cloud", shorttitle="EMA & MA Cloud", overlay=true)

// Input lengths for MA and EMA
LengthMA = input(10, minval=1, title="SMA Length")
LengthEMA = input(10, minval=1, title="EMA Length")

// Calculate SMA and EMA
xMA = sma(close, LengthMA)
xEMA = ema(xMA, LengthEMA)

// Determine position based on crossover
longCondition = crossover(xEMA, xMA)
shortCondition = crossunder(xEMA, xMA)

// Plot the SMA and EMA
plot(xMA, color=color.red, title="SMA")
plot(xEMA, color=color.blue, title="EMA")

// Create the cloud between the SMA and EMA
hline1 = plot(xMA, color=color.red, transp=90, title="SMA")
hline2 = plot(xEMA, color=color.blue, transp=90, title="EMA")

// Fill the cloud with color based on the phase
fill(hline1, hline2, color=xEMA > xMA ? color.green : color.red, transp=90)

// Color the bars based on position (optional)
barcolor(xEMA < xMA ? color.red : color.green)

// Alert conditions
alertcondition(longCondition, title="Long Alert", message="Go Long!")
alertcondition(shortCondition, title="Short Alert", message="Go Short!")

// Plot shapes on chart for visual confirmation
plotshape(series=longCondition, title="Long Signal", location=location.belowbar, color=color.green, style=shape.labelup, text="BUY")
plotshape(series=shortCondition, title="Short Signal", location=location.abovebar, color=color.red, style=shape.labeldown, text="SELL")
Chart PatternsTechnical IndicatorsTrend Analysis

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