How it is calculated
Each bar the EMA moves towards the new price by the factor 2 / (length + 1): price times the factor plus the previous EMA times one minus the factor. It is seeded with the simple average of the first length prices, so its first value comes on the same bar as the SMA's, as TA-Lib's EMA. Older prices never drop out entirely, their weight shrinks every bar.
Reference: TA-Lib EMA
How to read it
The slope shows the trend, price above or below the line the side the market is on. It reacts sooner than an SMA and so also turns falsely more often in a sideways market.
In a strategy
Crosses of a fast and a slow EMA as entry and exit, ctx.ind("ema", length=12) against ctx.ind("ema", length=26), or a pullback to a 20 bar EMA in a trend as entry point.
Inputs
| Input | Type | Default | Range or choices |
|---|---|---|---|
Lengthlength | Whole number | 20 | min 1, max 5000 |
Sourcesource | Price | "close" | close, open, high, low, hl2, hlc3, ohlc4, hlcc4 |
What it draws
| Line | Drawn as |
|---|---|
| EMA | Line |
Used in
No strategy template reads it yet.