Exponential Moving Average
Syntax
Description
The ema
function calculates the Exponential Moving Average (EMA) for a given symbol over a specified period. The function can also be applied directly to an array of numerical data to calculate the EMA. The EMA places more weight on recent data points, making it more responsive to short-term price changes compared to the Simple Moving Average (SMA).
Returns
The ema
function returns a single EMA value by default. If the rolling
option is specified, it returns an array of EMA values for the specified rolling period.
Parameters
len
: The length of the period over which to calculate the EMA.symbol
: The symbol for which to calculate the EMA.options?
(optional): An object with the following optional properties:rolling
: The number of days for which to return the EMA values. If specified, an array of EMA values is returned.offset
: The number of days ago to start the calculation. Default is 0 (current day).prop
: The property of the data to use for calculation. Default is'close'
. This option is only applicable when using with symbol.
Examples
Using with Symbol and Length
Using with Data Array
Use Cases
Identifying Trend Reversals:
Applying EMA Crossover Strategy:
Notes
- The
ema
function is a versatile indicator widely used in technical analysis for trend following, momentum analysis, and detecting potential reversals. - Similar to the SMA, the EMA can be used with different periods to analyze short-term or long-term trends.
- Traders often use EMA crossovers as signals for entering or exiting positions, where a bullish crossover (short-term EMA crossing above long-term EMA) signals a potential buy, and a bearish crossover (short-term EMA crossing below long-term EMA) signals a potential sell.