Simple moving average
All indicators

LibraryTrend

Indicator

Simple moving average

The plain average of the last prices over the chosen length, a smoothed line that shows the direction of the trend.

TrendOn the price2 inputsSMA

How it is calculated

The sum of the source (the close by default) over the last length bars, divided by the length, every bar weighted the same. The first value comes once length bars are in, as TA-Lib's SMA.

Reference: TA-Lib SMA

How to read it

Price above a rising average points to an uptrend, below a falling one to a downtrend. It lags: the longer it is, the smoother it gets and the later it turns. In a sideways market price crosses it often and the crossings mean little.

In a strategy

A trend filter that only allows longs while the close is above ctx.ind("sma", length=200), or the cross of a fast and a slow SMA as entry signal.

Inputs

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

What it draws

LineDrawn as
SMALine

Used in

The strategy templates whose code reads this indicator.

OrionQuant