OPEN-SOURCE SCRIPT

EMA with Dynamic Support and Resistance Signals

//version=5
indicator("EMA with Dynamic Support and Resistance Signals", overlay=true)

// Parameters
emaLength = 10
lookbackPeriod = 20

// Calculations
ema = ta.ema(close, emaLength)
highestHigh = ta.highest(high, lookbackPeriod)
lowestLow = ta.lowest(low, lookbackPeriod)

// Conditions
buyCondition = close > ema and close > highestHigh[1]
sellCondition = close < ema and close < lowestLow[1]

// Plot EMA
plot(ema, title="10-Period EMA", color=color.blue)

// Plot Support and Resistance Levels
plot(highestHigh[1], title="Resistance Level", color=color.red, style=plot.style_linebr)
plot(lowestLow[1], title="Support Level", color=color.green, style=plot.style_linebr)

// Plot Buy and Sell Signals
plotshape(series=buyCondition, location=location.belowbar, color=color.green, style=shape.labelup, text="BUY")
plotshape(series=sellCondition, location=location.abovebar, color=color.red, style=shape.labeldown, text="SELL")

Disclaimer