Simple Moving Average (SMA)
Category: Trend · Updated November 2026
The TAAPI.IO SMA API returns the Simple Moving Average as JSON for crypto pairs and US stocks. Send an exchange, symbol, timeframe and period to get real-time or historical values, with no candles to download and no calculations to maintain.
What one request returns
- The average (
value): the mean of the lastperiodcloses, 30 by default. - A series, with
results: one value per candle, oldest first, to see the slope or find where two averages crossed. - Several periods at once, with
/bulk: the 50-day and 200-day SMA together, each with its ownid, plus the closing price.
So one call answers two questions: which way is the trend, and has the long-term picture changed?
Example: a death cross that kept rising, April to November 2026
Request: one /bulk call for TSLA on daily US stock candles, with the 50-day and 200-day SMA (results=2, so the last two closes) and the closing price. Sent at 22:37 UTC on Saturday 14 November, so the latest daily candle is Friday's close and no backtrack is needed.
| Candle | TSLA close | SMA 50 | SMA 200 | Reading |
|---|---|---|---|---|
| 12 Nov | 399.85 | 373.98 | 382.46 | 50-day below the 200-day: the death cross is in effect |
| 13 Nov | 387.11 | 374.23 | 382.26 | Close above both averages, 50-day still 8.02 below |
How to interpret this: TSLA's 50-day SMA crossed below its 200-day on 9 April 2026, at a close of 344.94. That is the textbook death cross, a long-term sell signal. Seven months later it is still in effect, yet TSLA closed at 387.11 on 13 November, 12.2% higher and above both averages. In between, the stock rose to 448.20 by 13 May, 30% above the death cross, then fell to 296.64 by 29 July, and crossed its 200-day SMA 11 times. The golden cross before it, on 16 September 2025 at 422.89, had the same problem in reverse: TSLA went on to 490.57 in December, then gave it all back, and the death cross came 18.4% below the golden cross. A 200-day average moves slowly, so crosses of the 50-day and 200-day arrive months after the move they describe. They tell you which regime a market has been in, not where it goes next.
| Cross | Date | TSLA close | What came next |
|---|---|---|---|
| Golden | 16 Sep 2025 | 422.89 | High of 490.57 on 16 Dec, then the death cross 18.4% lower |
| Death | 9 Apr 2026 | 344.94 | High of 448.20 on 13 May (+29.9%), low of 296.64 on 29 Jul (−14.0%) |
| None since | 13 Nov 2026 | 387.11 | 12.2% above the death cross, above both averages |
Values are from the production API on 14 November 2026, using daily closes. Two crosses are an illustration, not a backtest. Nothing here is financial advice.
| Spec | Value |
|---|---|
| Endpoint | GET https://v2.taapi.io/indicator/sma |
| Outputs | SMA value, timestamp |
| Default settings | Period 30 |
| Markets | Binance, Binance Futures, Bybit, Gate.io, Kraken and US stocks |
| Timeframes | 1m to 1w |
| Delivery | REST, bulk and WebSocket |
Get SMA with one API call
This request returns SMA for BTCUSDT on 1-hour Binance candles. Add your API key to run it here.
curl -G https://v2.taapi.io/indicator/sma \ -H "Authorization: Bearer YOUR_API_KEY" \ --data-urlencode "exchange=binance" \ --data-urlencode "symbol=BTCUSDT" \ --data-urlencode "timeframe=1h"
import requests
resp = requests.get(
'https://v2.taapi.io/indicator/sma',
headers={'Authorization': 'Bearer YOUR_API_KEY'},
params={'exchange': 'binance', 'symbol': 'BTCUSDT', 'timeframe': '1h'},
)
print(resp.json())const params = new URLSearchParams({"exchange": "binance", "symbol": "BTCUSDT", "timeframe": "1h"});
const res = await fetch(`https://v2.taapi.io/indicator/sma?${params}`, {
headers: { Authorization: 'Bearer YOUR_API_KEY' },
});
console.log(await res.json());SMA API response
This response came from the live API on 9 November 2026.
{
"value": [75299.52233333327],
"timestamp": [1794218400]
}| Field | Type | Description |
|---|---|---|
value | number[] | SMA result |
timestamp | integer[] | Unix time of each candle, in seconds |
SMA API parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
exchange | string | Yes | — | binance, binancefutures, bybit, gateio, kraken or stocks |
symbol | string | Yes | — | Pair or ticker, e.g. BTCUSDT or AAPL |
timeframe | string | Yes | — | 1m 5m 15m 1h 4h 1d 1w |
period | integer | No | 30 | Number of closes in the average |
results | integer | No | 1 | Number of values to return, or max |
backtrack | integer | No | 0 | Candles to skip from the most recent |
What is SMA?
The Simple Moving Average is the arithmetic mean of the last n closes. It is the most widely used trend filter, and the middle line of Bollinger Bands.
SMA formula
| Output | Calculation |
|---|---|
| SMA | Sum of the last n closes ÷ n |
| Next SMA | Previous SMA + (newest close − close leaving the window) ÷ n |
The second line is why an SMA can move even when price doesn't: a large close leaving the window changes the average as much as a large close entering it. TSLA's 50-day SMA of 374.23 on 13 November is exactly the sum of its last 50 closes divided by 50, and its 200-day SMA of 382.26 the same over 200.
How to read SMA in your code
| Signal | Meaning | Condition |
|---|---|---|
| Price above average | Bullish bias | Close above value |
| Price below average | Bearish bias | Close below value |
| Slope | Direction of the trend | Latest value versus the previous one |
| Golden cross | Short-term average overtakes long-term | SMA(50) crosses above SMA(200) |
| Death cross | Short-term average falls under long-term | SMA(50) crosses below SMA(200) |
Limitations: Every candle in the window has equal weight, so a large candle moves the average twice: when it enters and when it leaves. Long averages lag by design, as in the example above. Nothing on this page is financial advice.
Price against the average, or the cross?
There are two common ways to use a long average. The first compares price with it: above the 200-day SMA is an uptrend, below it a downtrend. That reacts within a day, but it flips often. TSLA crossed its 200-day 11 times between April and November. The second waits for a faster average to cross the slower one. That flips rarely, but late. Many systems use the cross to decide the regime and price against a shorter average for timing.
Detect a golden or death cross with Python
One /bulk request returns both averages for the last two candles and the latest close. Each indicator gets its own id, which becomes its key in the response. It uses one construct, so it works on every plan. For crypto, or for stocks during market hours, add backtrack=1 to each indicator so you compare closed candles only.
curl -X POST https://v2.taapi.io/bulk \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"constructs": [
{
"id": "tsla_1d",
"exchange": "stocks",
"symbol": "TSLA",
"timeframe": "1d",
"indicators": [
{
"id": "sma50",
"indicator": "sma",
"period": 50,
"results": 2
},
{
"id": "sma200",
"indicator": "sma",
"period": 200,
"results": 2
},
{
"id": "close",
"indicator": "price"
}
]
}
]
}'import requests
payload = {
"constructs": [
{
"id": "tsla_1d",
"exchange": "stocks",
"symbol": "TSLA",
"timeframe": "1d",
"indicators": [
{
"id": "sma50",
"indicator": "sma",
"period": 50,
"results": 2
},
{
"id": "sma200",
"indicator": "sma",
"period": 200,
"results": 2
},
{
"id": "close",
"indicator": "price"
}
]
}
]
}
resp = requests.post(
'https://v2.taapi.io/bulk',
headers={'Authorization': 'Bearer YOUR_API_KEY'},
json=payload,
)
data = resp.json()
c = data['tsla_1d']
fast = c['sma50']['value']
slow = c['sma200']['value']
close = c['close']['value'][-1]
if fast[0] <= slow[0] and fast[1] > slow[1]:
print('Golden cross on the last candle')
elif fast[0] >= slow[0] and fast[1] < slow[1]:
print('Death cross on the last candle')
else:
state = 'golden' if fast[1] > slow[1] else 'death'
side = 'above' if close > slow[1] else 'below'
print(f'No new cross. The {state} cross is in effect, and the close of {close:.2f} is {side} the 200-day SMA ({slow[1]:.2f})')The response at 22:37 UTC on 14 November. The 50-day stayed below the 200-day on both candles, so there is no new cross, and the script prints No new cross. The death cross is in effect, and the close of 387.11 is above the 200-day SMA (382.26).
{
"tsla_1d": {
"sma50": {
"value": [373.984018, 374.233496],
"timestamp": [1794441600, 1794528000]
},
"sma200": {
"value": [382.4641704999992, 382.25721699999923],
"timestamp": [1794441600, 1794528000]
},
"close": {
"value": [387.1093],
"timestamp": [1794528000]
}
}
}To find past crosses for a backtest, request a longer series, for example results=300, and compare each pair of neighbouring values. Other common filters: require price to close on the same side of the 200-day SMA as the cross, or confirm it with MACD.
Get historical SMA values
Add results to return a series for backtesting or charting. The last element is the most recent candle.
curl -G https://v2.taapi.io/indicator/sma \ -H "Authorization: Bearer YOUR_API_KEY" \ --data-urlencode "exchange=binance" \ --data-urlencode "symbol=BTCUSDT" \ --data-urlencode "timeframe=1h" \ --data-urlencode "results=100"
Get SMA for multiple symbols
Combine SMA with other indicators in one request. Each exchange, symbol and timeframe combination is one construct: Basic allows 1 per request, Pro 3 and Expert 10.
curl -X POST https://v2.taapi.io/bulk \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"constructs": [
{
"id": "btc_1h",
"exchange": "binance",
"symbol": "BTCUSDT",
"timeframe": "1h",
"indicators": [
{
"id": "sma",
"indicator": "sma"
},
{
"id": "rsi",
"indicator": "rsi"
}
]
}
]
}'Stream SMA in real time
Subscribe over WebSocket to receive new values every 5 seconds while the candle is forming. Streaming supports 1m, 5m, 15m and 1h, and uses interval where REST uses timeframe.
{
"type": "subscribe",
"id": "sma",
"exchange": "binance",
"symbol": "BTCUSDT",
"interval": "1m",
"indicator": "sma"
}Common SMA settings
These are starting points, not recommendations. Test any setting on your own market and timeframe.
| Settings | Character | Typical use |
|---|---|---|
| 20 | Short-term | Base of Bollinger Bands |
| 50 | Medium | Swing trend filter |
| 200 | Long-term | Long-term trend filter |
Why SMA values can differ between platforms
- Exchange data: each exchange has its own closes, so a Binance SMA differs from another venue's.
- Open candle: the newest value changes until the candle closes. Use
backtrack=1to read closed candles. - Stock data: daily stock candles cover the regular session, so an SMA can differ from a chart that includes pre-market and after-hours trading.
SMA API FAQ
What does the SMA API return?
An array of averages in value, plus a timestamp for each candle.
How do I get the 50-day and 200-day SMA together?
Send a POST /bulk request with two sma indicators, one with "period": 50 and one with "period": 200, each with its own id. See Detect a golden or death cross with Python.
Is a death cross a sell signal?
It marks a change of regime, and it arrives late. In the example above, TSLA rose 30% in the five weeks after its death cross and was 12% higher seven months later. Many traders use it as a filter rather than an entry.
Is the latest SMA value final?
No. The newest value belongs to the candle still forming and can change until it closes. Add backtrack=1 to read the last closed candle.
Can I get SMA for US stocks?
Yes. Use exchange=stocks with a ticker such as TSLA. US stocks are included on the Pro plan and above.
Related indicators
- Exponential Moving Average (EMA): an average that reacts faster
- Bollinger Bands: bands around a 20-period SMA
- MACD: momentum from two moving averages
- ADX: trend strength, to filter crosses
Build with SMA on Binance, Bybit or US stocks. Start for free or browse all 262 indicators.