Exponential moving average
All indicators

LibraryTrend

Indicator

Exponential moving average

An average of recent prices that gives the newest bars the most weight, so it follows price sooner than a simple average of the same length.

TrendOn the price2 inputsEMA

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

InputTypeDefaultRange or choices
LengthlengthWhole number20min 1, max 5000
SourcesourcePrice"close"close, open, high, low, hl2, hlc3, ohlc4, hlcc4

What it draws

LineDrawn as
EMALine

Used in

No strategy template reads it yet.

OrionQuant