ema + trendline

ema + trendline

//@version=5
indicator("EMA + Trendline + Support/Resistance", overlay=true)

// === INPUTS ===
emaLength = input.int(50, title="EMA Length")
src = input.source(close, title="Source")

// === EMA CALCULATION ===
ema = ta.ema(src, emaLength)
plot(ema, title="EMA", color=color.orange, linewidth=2)

// === TRENDLINE DETECTION ===
var line upTrend = na
var line downTrend = na

if (low > low and low > low )
line.delete(upTrend)
upTrend := line.new(bar_index , low , bar_index, low, color=color.green, width=1)

if (high < high and high < high )
line.delete(downTrend)
downTrend := line.new(bar_index , high , bar_index, high, color=color.red, width=1)

// === SUPPORT AND RESISTANCE LEVELS ===
pivotHigh = ta.pivothigh(high, 5, 5)
pivotLow = ta.pivotlow(low, 5, 5)

var float resistance = na
var float support = na

if not na(pivotHigh)
resistance := pivotHigh
if not na(pivotLow)
support := pivotLow

plot(support, title="Support", style=plot.style_linebr, color=color.teal, linewidth=2)
plot(resistance, title="Resistance", style=plot.style_linebr, color=color.fuchsia, linewidth=2)

// === SIGNALS ===
bullishSignal = ta.crossover(close, ema) and close > line.get_price(upTrend) and close > support
bearishSignal = ta.crossunder(close, ema) and close < line.get_price(downTrend) and close < resistance

plotshape(bullishSignal, title="Buy Signal", location=location.belowbar, color=color.green, style=shape.labelup, text="BUY")
plotshape(bearishSignal, title="Sell Signal", location=location.abovebar, color=color.red, style=shape.labeldown, text="SELL")

Read More

Share:

Latest News