HTF EMA Indicator

This simple script draws a higher-timeframe EMA to your chart. It can be useful for creating day-trading strategies and for extra confluence in trading decisions.

How It Works

The script functions as a regular EMA indicator except that it calculates its value based on a different timeframe.


EMA Timeframe:
This sets the timeframe for the EMA calculation.

EMA Length:
This sets the calculation period for the EMA (in HTF bars).

Color EMA:
If enabled then the EMA line will change color based on whether price is above or below it.

This tells the script how far to offset the line drawing from the current candle.

Source Code

// @version=4
// Created by Matthew J. Slabosz
study(title="Higher Timeframe EMA (HTF EMA)", shorttitle="EMA+", overlay=true)

// Get user input
res = input(title="EMA Timeframe", type=input.resolution, defval="D")
len = input(title="EMA Length", type=input.integer, defval=50)
col = input(title="Color EMA", type=input.bool, defval=true)
smooth = input(title="Smooth", type=input.bool, defval=false)

// Calculate EMA
ema = ema(close, len)
emaSmooth = security(syminfo.tickerid, res, ema, barmerge.gaps_on, barmerge.lookahead_off)
emaStep = security(syminfo.tickerid, res, ema, barmerge.gaps_off, barmerge.lookahead_off)

// Draw EMA
plot(smooth ? emaSmooth : emaStep, color=col ? close > emaStep ? : :, style=plot.style_line, linewidth=2, title="EMA (HTF)")

Last Updated: 11th April, 2020

Free Premium Charts!

0 0 vote
Article Rating

Leave a Comment, Question or Suggestion

Inline Feedbacks
View all comments