Stochastic Oscillator
Category: Momentum · Updated November 2026
The TAAPI.IO Stochastic API returns the Stochastic Oscillator's %K and %D lines as JSON for crypto pairs and US stocks. Send an exchange, symbol and timeframe to get real-time or historical values, with no candles to download and no calculations to maintain.
What one request returns
- The two lines:
valueK, where the close sits in the recent high-low range from 0 to 100, andvalueD, its moving average. - A series, with
results: one pair of values per candle, oldest first, to find crossovers. - Several timeframes at once, with
/bulk: for example a 4-hour Stochastic for signals and a daily trend check, in one request.
So one call answers two questions: is the close near the top or bottom of its range, and has momentum just turned?
Example: buy signals in a falling market, 20 October to 14 November 2026
Request: one /bulk call for SOLUSDT on 4-hour Binance candles, with the Stochastic (results=2, backtrack=1, so the last two closed candles). Sent at 22:37 UTC on 14 November with the default settings of 5, 3 and 3.
| Candle | %K | %D | Reading |
|---|---|---|---|
| 4h, 14 Nov 12:00 | 11.55 | 9.96 | %K above %D below 20: a bullish crossover |
| 4h, 14 Nov 16:00 | 12.52 | 11.09 | Still above %D, no new crossover |
How to interpret this: A %K crossing above %D below 20 is the textbook buy signal, and SOL gave it on 14 November at 12:00, at 73.89. The next candle closed at 72.24, a new low. That was the fourth such signal since 20 October, and the pattern was the same each time. On 22 October, 6 November and 10 November SOL rose by up to 3.5% within a day, then made a lower low. By 14 November it was 13% to 30% below each signal. The one bearish crossover above 80, on 28 October at 102.75, came at the top of a bounce, and SOL fell 2.3% over the next day. In a downtrend the close keeps landing near the bottom of its range, so the Stochastic keeps showing oversold. That describes the trend. It doesn't predict a turn. A trader who only took crossovers in the direction of the daily trend would have skipped the November buys and kept the October sell.
| Crossover | Date | SOL close | %K | One day later | By 14 Nov 16:00 | Daily trend |
|---|---|---|---|---|---|---|
| Bullish | 22 Oct 16:00 | 103.63 | 16.9 | −0.1% | −30.3% | up |
| Bearish | 28 Oct 08:00 | 102.75 | 84.3 | −2.3% | −29.7% | down |
| Bullish | 6 Nov 04:00 | 89.68 | 15.1 | +0.6% | −19.4% | down |
| Bullish | 10 Nov 16:00 | 82.95 | 19.8 | +2.3% | −12.9% | down |
| Bullish | 14 Nov 12:00 | 73.89 | 11.6 | — | −2.2% | down |
Values are from the production API on 14 November 2026, using closed 4-hour candles. "One day later" compares the close six candles on. The daily trend is the previous daily close against its 50-day EMA. Five signals are an illustration, not a backtest. Nothing here is financial advice.
| Spec | Value |
|---|---|
| Endpoint | GET https://v2.taapi.io/indicator/stoch |
| Outputs | %K, %D, timestamp |
| Default settings | K period 5, D period 3, K smoothing 3 |
| Markets | Binance, Binance Futures, Bybit, Gate.io, Kraken and US stocks |
| Timeframes | 1m to 1w |
| Delivery | REST, bulk and WebSocket |
Get Stochastic with one API call
This request returns Stochastic for BTCUSDT on 1-hour Binance candles. Add your API key to run it here.
curl -G https://v2.taapi.io/indicator/stoch \ -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/stoch',
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/stoch?${params}`, {
headers: { Authorization: 'Bearer YOUR_API_KEY' },
});
console.log(await res.json());Stochastic API response
This response came from the live API on 9 November 2026.
{
"valueK": [34.3772073598305],
"valueD": [31.551435483400635],
"timestamp": [1794218400]
}| Field | Type | Description |
|---|---|---|
valueK | number[] | K |
valueD | number[] | D |
timestamp | integer[] | Unix time of each candle, in seconds |
Stochastic 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 |
kPeriod | integer | No | 14 | Candles in the high-low range |
dPeriod | integer | No | 3 | Moving average length for %D |
kSmooth | integer | No | 3 | Smoothing applied to raw %K |
results | integer | No | 1 | Number of values to return, or max |
backtrack | integer | No | 0 | Candles to skip from the most recent |
What is the Stochastic Oscillator?
The Stochastic Oscillator, popularised by George Lane, shows where the close sits within the recent high-low range on a scale of 0 to 100. The idea is that closes cluster near the highs in uptrends and near the lows in downtrends.
Stochastic formula
| Output | Calculation |
|---|---|
| Raw %K | (close − lowest low) ÷ (highest high − lowest low) × 100, over kPeriod candles |
| %K | Average of the last kSmooth raw %K values |
| %D | Average of the last dPeriod %K values |
On the 14 November 16:00 candle, SOL's highest high over 14 candles was 82.80 and its lowest low 71.67, and it closed at 72.24. So raw %K is (72.24 − 71.67) ÷ (82.80 − 71.67) × 100 = 5.12. The average of the last three raw values gives %K = 8.35, and the average of the last three %K values gives %D = 7.65.
How to read the Stochastic in your code
| Signal | Meaning | Condition |
|---|---|---|
| Overbought | Close near the top of its range | valueK above 80 |
| Oversold | Close near the bottom of its range | valueK below 20 |
| Bullish crossover | Momentum turning up | valueK crosses above valueD |
| Bearish crossover | Momentum turning down | valueK crosses below valueD |
Limitations: it stays pinned near the extremes during strong trends, as in the example. Nothing on this page is financial advice.
Fast, slow and full stochastic
The names describe how much smoothing is applied. The fast stochastic uses raw %K, the slow version smooths %K once, and a full stochastic lets you set every length. On this endpoint, kSmooth controls that smoothing, which makes it a full stochastic.
Two related endpoints are available. stochf returns the unsmoothed fast form, and stochrsi applies the same maths to RSI rather than price.
Using the Stochastic in trends
In a rally the close keeps landing near the top of the range, so %K can remain above 80 for a long time. That is the indicator working as designed, and not a reason to sell. Crossovers are generally more useful when taken in the direction of the larger trend: buying oversold crossovers in an uptrend, for instance.
The API defaults to 14, 3, 3, the same settings TradingView and most charting tools use, so values line up with a chart of the same exchange without extra parameters.
Detect a Stochastic crossover in oversold with Python
This looks for %K crossing above %D while %K is below 20, using the common 14, 3, 3 settings on the last two closed candles.
curl -G https://v2.taapi.io/indicator/stoch \ -H "Authorization: Bearer YOUR_API_KEY" \ --data-urlencode "exchange=binance" \ --data-urlencode "symbol=BTCUSDT" \ --data-urlencode "timeframe=1h" \ --data-urlencode "kPeriod=14" \ --data-urlencode "dPeriod=3" \ --data-urlencode "kSmooth=3" \ --data-urlencode "results=2" \ --data-urlencode "backtrack=1"
import requests
resp = requests.get(
'https://v2.taapi.io/indicator/stoch',
headers={'Authorization': 'Bearer YOUR_API_KEY'},
params={'exchange': 'binance', 'symbol': 'BTCUSDT', 'timeframe': '1h', 'kPeriod': 14, 'dPeriod': 3, 'kSmooth': 3, 'results': 2, 'backtrack': 1},
)
data = resp.json()
k_prev, k = data['valueK']
d_prev, d = data['valueD']
if k_prev <= d_prev and k > d and k < 20:
print('Bullish crossover in oversold')
elif k_prev >= d_prev and k < d and k > 80:
print('Bearish crossover in overbought')
else:
print(f'No signal, %K is {k:.2f}')Filter crossovers with the daily trend
Crossovers on short timeframes fire often, and in a trend most of the ones against it fail, as in the example. A common fix is to take a 4-hour crossover only when the daily trend agrees, here the previous daily close against its 50-day EMA. One /bulk request returns both. Two constructs need the Pro plan or above. On Basic, make two GET requests instead.
curl -X POST https://v2.taapi.io/bulk \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"constructs": [
{
"id": "sol_4h",
"exchange": "binance",
"symbol": "SOLUSDT",
"timeframe": "4h",
"indicators": [
{
"id": "stoch",
"indicator": "stoch",
"results": 2,
"backtrack": 1
}
]
},
{
"id": "sol_1d",
"exchange": "binance",
"symbol": "SOLUSDT",
"timeframe": "1d",
"indicators": [
{
"id": "ema50",
"indicator": "ema",
"period": 50,
"backtrack": 1
},
{
"id": "close",
"indicator": "price",
"backtrack": 1
}
]
}
]
}'import requests
payload = {
"constructs": [
{
"id": "sol_4h",
"exchange": "binance",
"symbol": "SOLUSDT",
"timeframe": "4h",
"indicators": [
{
"id": "stoch",
"indicator": "stoch",
"results": 2,
"backtrack": 1
}
]
},
{
"id": "sol_1d",
"exchange": "binance",
"symbol": "SOLUSDT",
"timeframe": "1d",
"indicators": [
{
"id": "ema50",
"indicator": "ema",
"period": 50,
"backtrack": 1
},
{
"id": "close",
"indicator": "price",
"backtrack": 1
}
]
}
]
}
resp = requests.post(
'https://v2.taapi.io/bulk',
headers={'Authorization': 'Bearer YOUR_API_KEY'},
json=payload,
)
data = resp.json()
k, d = data['sol_4h']['stoch']['valueK'], data['sol_4h']['stoch']['valueD']
daily = data['sol_1d']
trend = 'up' if daily['close']['value'][-1] > daily['ema50']['value'][-1] else 'down'
bull = k[0] <= d[0] and k[1] > d[1] and k[1] < 20
bear = k[0] >= d[0] and k[1] < d[1] and k[1] > 80
if bull and trend == 'up':
print('Bullish crossover below 20 in a daily uptrend: buy signal')
elif bear and trend == 'down':
print('Bearish crossover above 80 in a daily downtrend: sell signal')
elif bull or bear:
print(f'Crossover against the daily {trend}trend: skip')
else:
print(f'No crossover in a zone (%K {k[1]:.1f}, %D {d[1]:.1f}), daily trend {trend}')The response at 22:37 UTC on 14 November. The last crossover happened one candle earlier, and SOL's daily close of 78.19 is far below its 50-day EMA of 97.55, so the script prints No crossover in a zone (%K 12.5, %D 11.1), daily trend down. Run at 16:05 UTC, just after the 12:00 candle closed, it would have printed Crossover against the daily downtrend: skip.
{
"sol_4h": {
"stoch": {
"valueK": [11.553528761090655, 12.520411190701886],
"valueD": [9.96263463455284, 11.093952084687736],
"timestamp": [1794657600, 1794672000]
}
},
"sol_1d": {
"ema50": {
"value": [97.54767533658503],
"timestamp": [1794528000]
},
"close": {
"value": [78.19],
"timestamp": [1794528000]
}
}
}Since 20 October this rule would have taken two signals: the bullish crossover on 22 October, when SOL's daily close was 0.16 above its EMA (−0.1% a day later), and the bearish one on 28 October (−2.3%). It skipped the three November buys. Two of those bounced by a day's end, but all three were lower within days.
Get historical Stochastic 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/stoch \ -H "Authorization: Bearer YOUR_API_KEY" \ --data-urlencode "exchange=binance" \ --data-urlencode "symbol=BTCUSDT" \ --data-urlencode "timeframe=1h" \ --data-urlencode "results=100"
Get Stochastic for multiple symbols
Combine Stochastic 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": "stoch",
"indicator": "stoch"
},
{
"id": "rsi",
"indicator": "rsi"
}
]
}
]
}'Stream Stochastic 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": "stoch",
"exchange": "binance",
"symbol": "BTCUSDT",
"interval": "1m",
"indicator": "stoch"
}Why Stochastic values can differ between platforms
- Settings: This endpoint defaults to 14, 3, 3, like TradingView. If your chart uses other lengths, pass the same
kPeriod,kSmoothanddPeriod. - Exchange data: Highs and lows vary between exchanges, and the stochastic depends directly on them.
- Open candle: Compare closed candles with
backtrack=1.
Stochastic API FAQ
What does the Stochastic API return?
Two arrays, valueK and valueD, plus a timestamp for each candle.
Does this match the Stochastic on TradingView?
Yes. The defaults are 14, 3, 3, the same as TradingView's built-in Stochastic, so compare a closed candle from the same exchange and the values match. The old stochtv endpoint now returns exactly what stoch returns.
Is a bullish crossover below 20 a buy signal?
Not on its own. In a downtrend it fires repeatedly while price keeps falling, as in the example above. Checking a higher-timeframe trend filters out many of these.
Is the latest Stochastic 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 the Stochastic for US stocks?
Yes. Use exchange=stocks with a ticker such as AAPL. US stocks are included on the Pro plan and above.
Related indicators
- Stochastic RSI: the same maths applied to RSI
- Stochastic Fast: unsmoothed %K
- Relative Strength Index (RSI): momentum from price changes
- Williams %R: the range position, inverted
Build with Stochastic on Binance, Bybit or US stocks. Start for free or browse all 262 indicators.