Exponential Moving Average
Exponential moving average is the average of the stock price calculated backwards, but the most recent values have always higher weight than older values. The more recent the value is, the higher weight it has in calculating ema. I mean the current bar value has move “weight” than the previous bar value “weight“. as a result ema react faster to market price changes than ema.
EMA has 2 parameters in calculating it. First is “Smoothing“ which is the value of the relative weight to the newwe values to older values. In most usages, smoothing is set to 2. Second, is the numer of days used to calculate the ema indicator.
//@version=6 indicator("Exponential Moving Average (EMA)", overlay=true) // Input for the length of the EMA // 'defval' sets the default value to 20 periods. // 'minval' sets the minimum allowed value to 1. // 'title' provides a user-friendly label for the input. emaLength = input.int(defval=9, minval=1, title="EMA Length") // Calculate the Exponential Moving Average (EMA) // 'ta.ema(source, length)' calculates the EMA of the 'source' series // over the specified 'length'. // 'close' is used as the default source, representing the closing price of each bar. emaValue = ta.ema(close, emaLength) // Plot the EMA on the chart // 'plot' draws the calculated EMA value on the chart. // 'color' sets the color of the plot (here, blue). // 'title' provides a label for the plotted line in the indicator settings. // 'linewidth' sets the thickness of the plotted line. plot(emaValue, color=color.blue, title="EMA", linewidth=2)