// This lesson demonstrates how to create a higher-timeframe EMA script that draws a key Daily chart moving average over our intraday price action.
// Update 20th June 2023: I changed the security function call to reflect the latest 'best practice' for non-repainting code as mentioned in the TradingView documentation: https://www.tradingview.com/pine-script-docs/en/v5/concepts/Repainting.html#repainting-request-security-calls
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// @version=5
indicator(title="HTF EMA", overlay=true)
// Get user input
res = input.string(title="EMA Timeframe", defval="D")
len = input.int(title="EMA Length", defval=50)
col = input.bool(title="Color EMA", defval=true)
smooth = input.bool(title="Smooth", defval=false)
// Calculate EMA
ema = ta.ema(close, len)
emaStep = request.security(syminfo.tickerid, res, ema[barstate.isrealtime ? 1 : 0])[barstate.isrealtime ? 0 : 1]
emaSmooth = request.security(syminfo.tickerid, res, ema[barstate.isrealtime ? 1 : 0], gaps=barmerge.gaps_on)[barstate.isrealtime ? 0 : 1]
// Draw EMA
plot(smooth ? emaSmooth : emaStep, color=col ? (close > emaStep ? color.green : color.red) : color.blue, linewidth=2, title="HTF EMA")
Overview
The script calculates the EMA using a configurable length and timeframe, then applies request.security to retrieve the value without repainting. It draws the line over the chart, colored green when price is above the EMA or red when below, with an option to smooth the plot. Main settings allow changing the EMA timeframe to daily or other intervals, adjusting the length, toggling color, and enabling smoothing. This tool helps traders identify trend direction in intraday markets using higher timeframe data.
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
EMA Timeframe
string
D
res
EMA Length
int
50
len
Color EMA
bool
true
col
Smooth
bool
false
smooth
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.
The Adaptive Laguerre Filter calculates a smoothed, dynamically adjusted trendline plotted directly on the main price chart. It dynamically adjusts its damping factor (alpha) based on recent price range variations and median percentile calculations over a spec
This script plots three moving averages on the price chart: a fast EMA or SMA with 10 periods, a slow EMA or SMA with 20 periods, and a trend EMA or SMA with 100 periods. It signals trend changes by drawing a white cross when the fast moving average crosses ab
This indicator plots four customizable moving averages directly on the main price chart using default lengths of 3, 8, 21, and 50 periods. It fills the space between adjacent averages in green or maroon depending on trend alignment. Additionally, it computes B
This indicator plots three exponential moving averages and ATR volatility envelopes on the price chart. It compares the fast and slow EMAs to shade a trend ribbon and marks confirmed upward and downward crossovers with triangle labels. Settings change the thre
Donald SPX - Options Trading is an overlay indicator designed for intraday SPX analysis. It plots a 200-period Weighted Moving Average (WMA) on the price chart while evaluating multi-timeframe market structure across Daily, 15-minute, 5-minute, and 2-minute ba
This indicator computes moving average and RSI bias signals across the current timeframe and four higher timeframes. It sums biases from the MA and RSI to derive an overall bullish or bearish signal. The results appear in a configurable table that displays eac