Untitled

 avatar
unknown
plain_text
2 years ago
1.2 kB
5
Indexable
// @version=5
indicator(title="Higher Timeframe EMA (HTF EMA)", shorttitle="EMA+", overlay=true)

// Get user input
res     = input.timeframe(title="EMA Timeframe", defval="D")
len1    = input.int(title="EMA Length", defval=50)
len2   = input.int(title="EMA Length", defval=100)

col     = input.bool(title="Color EMA", defval=true)
smooth  = input.bool(title="Smooth", defval=false)

// Calculate EMA
ema1 = ta.ema(close, len1)
ema2 = ta.ema(close, len2)

emaStep1 = request.security(syminfo.tickerid, res, ema1[barstate.isrealtime ? 1 : 0])
emaStep2 = request.security(syminfo.tickerid, res, ema2[barstate.isrealtime ? 1 : 0])

emaSmooth = request.security(syminfo.tickerid, res, ema1[barstate.isrealtime ? 1 : 0], gaps=barmerge.gaps_on)

longEntry = ta.crossover(emaStep1,emaStep2)
plotshape(longEntry, title='Long Entry', location=location.belowbar, style=shape.labelup, color=color.new(#2C9670, 0), text='Long', textcolor=color.new(color.white, 0))

// Draw EMA
plot(smooth ? emaSmooth : emaStep1, color=col ? (close > emaStep1 ? color.green : color.red) : color.black, linewidth=2, title="HTF EMA")
plot(smooth ? emaSmooth : emaStep2, color=col ? (close > emaStep2 ? color.green : color.red) : color.black, linewidth=2, title="HTF EMA")
Editor is loading...