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
| 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 |
|---|---|
| SMA | Line |
Used in
The strategy templates whose code reads this indicator.