SMA(n) = sum(last n closes) / n
That's it. No magic.
Why it's useful:
- Trend identifier: price > SMA → uptrend. Price < SMA → downtrend.
- Crossovers: SMA(fast) crossing above SMA(slow) is a classic buy signal. (Golden cross on daily = SMA(50) above SMA(200).)
- Noise reducer: smoothing out the chart so you can see the shape.
Caveats
- SMA is lagging by definition — it always reflects past data.
- It weighs all bars equally. A huge dump 19 days ago still affects today's SMA(20) as much as yesterday's movement.
Your task: compute SMA(20) for the BTC dataset and print the last 5 values.