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.


Pine Script Basics Course Pine Script Mastery Course

Source Code

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © 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")
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)
emaStep = security(syminfo.tickerid, res, ema[barstate.isrealtime ? 1 : 0])
emaSmooth = security(syminfo.tickerid, res, ema[barstate.isrealtime ? 1 : 0], gaps=barmerge.gaps_on)

plot(smooth ? emaSmooth : emaStep, color=col ? (close > emaStep ? color.green : color.red) : color.black, linewidth=2, title="HTF EMA")

Last Updated: 1st June, 2020


Free Premium Charts!

5 1 vote
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments