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.

Settings

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.

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



Source Code

// Created by Matthew J. Slabosz
// www.zenandtheartoftrading.com
// @version=3
study(title="MJS - Higher Timeframe EMA", shorttitle="EMA+", overlay=true) 

// Get user input
res = input(title="EMA Timeframe", type=resolution, defval="5")
len = input(title="EMA Length", type=integer, defval=50)
col = input(title="Color EMA", type=bool, defval=false)
off = input(title="Offset", type=integer, defval=1)

// Calculate EMA
ema = ema(close, len)
sourceEma = security(tickerid, res, ema, barmerge.gaps_on, barmerge.lookahead_on)

// Draw EMA
plot(sourceEma, color=col ? (close > sourceEma ? green : red) : black, style=line, linewidth=1, title="EMA (HTF)", offset=off)

Last Updated: 21st March, 2019


TradingView Charting Platform

Leave a Comment, Question or Suggestion