Higher Timeframe EMAs - 21/50/100/200
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// modifed from © ZenAndTheArtOfTrading

//@version=4
study(title="Higher Timeframe EMA (HTF EMA)", shorttitle="EMA+", overlay=true)

// Get user input
res = input(title="EMA Timeframe", type=input.resolution, defval="D")
len1 = input(title="EMA Length", type=input.integer, defval=21)
len2 = input(title="EMA Length", type=input.integer, defval=50)
len3 = input(title="EMA Length", type=input.integer, defval=100)
len4 = input(title="EMA Length", type=input.integer, defval=200)

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

// Calculate EMA
ema1 = ema(close, len1)
ema2 = ema(close, len2)
ema3 = ema(close, len3)
ema4 = ema(close, len4)

emaStep1 = security(syminfo.tickerid, res, ema1[barstate.isrealtime ? 1 : 0])
emaSmooth1 = security(syminfo.tickerid, res, ema1[barstate.isrealtime ? 1 : 0], gaps=barmerge.gaps_on)
plot(smooth ? emaSmooth1 : emaStep1, color=col ? (close > emaStep1 ? color.green : color.red) : color.black, linewidth=2, title="HTF EMA21")

emaStep2 = security(syminfo.tickerid, res, ema2[barstate.isrealtime ? 1 : 0])
emaSmooth2 = security(syminfo.tickerid, res, ema2[barstate.isrealtime ? 1 : 0], gaps=barmerge.gaps_on)
plot(smooth ? emaSmooth2 : emaStep2, color=col ? (close > emaStep2 ? color.green : color.red) : color.black, linewidth=2, title="HTF EMA50")

emaStep3 = security(syminfo.tickerid, res, ema3[barstate.isrealtime ? 1 : 0])
emaSmooth3 = security(syminfo.tickerid, res, ema3[barstate.isrealtime ? 1 : 0], gaps=barmerge.gaps_on)
plot(smooth ? emaSmooth3 : emaStep3, color=col ? (close > emaStep3 ? color.green : color.red) : color.black, linewidth=2, title="HTF EMA100")

emaStep4 = security(syminfo.tickerid, res, ema4[barstate.isrealtime ? 1 : 0])
emaSmooth4 = security(syminfo.tickerid, res, ema4[barstate.isrealtime ? 1 : 0], gaps=barmerge.gaps_on)
plot(smooth ? emaSmooth4 : emaStep4, color=col ? (close > emaStep4 ? color.green : color.red) : color.black, linewidth=2, title="HTF EMA200")




