All free tools

Momentum indicator

Stochastic Oscillator Calculator

Compute the fast %K for one bar from the current close and the high and low of the lookback period. The concept, where price closes within its recent range, is what makes it useful.

%K
91.30
Above 80, traditionally described as overbought.
%D
The %D line is a short moving average of %K (see below).

What the Stochastic Oscillator is

George Lane popularized the Stochastic Oscillator in the late 1950s. Its idea is that as momentum builds, closing prices tend to settle near the extreme of the recent range: near the highs in a strong advance, near the lows in a strong decline. The oscillator turns that idea into a value between 0 and 100.

The fast line, %K, is 100 × (close − lowest low) ÷ (highest high − lowest low), where the highest high and lowest low are taken over the lookback period, by default 14 bars. A reading near 100 means the close sits at the top of its recent range; a reading near 0 means it sits at the bottom. Because raw %K can be jumpy, a second line, %D, smooths it with a short moving average, by default 3 periods, which is why %D needs a series rather than a single point.

Why the Stochastic Oscillator is used

The Stochastic is used to study momentum and where price closes within its recent range. Traders traditionally treat readings above 80 as overbought and below 20 as oversold, and often watch for the %K line crossing %D or for divergences between the oscillator and price.

These thresholds and the 14/3 defaults are conventions that many adjust to the market and timeframe. Interpretation is always your own.

What are TradingView and Pine Script?

TradingView is one of the most widely used charting and market-analysis platforms, where traders and analysts study price movement across stocks, crypto, forex, and futures on interactive charts. Pine Script is TradingView's own lightweight programming language, created so anyone can build custom tools that run directly on those charts.

People use Pine Script to build four main kinds of tools. Indicators calculate and plot values on the chart, exactly like the calculation above, but recomputed automatically on every bar. Strategies add explicit entry and exit rules and can be backtested against historical data in TradingView's Strategy Tester to see how they would have behaved. Screeners scan many symbols at once for conditions you define. Alerts notify you the moment a condition you specified occurs, so you do not have to watch the screen.

The value is precision and automation. Instead of eyeballing a chart, you describe exactly what you want measured, visualized, or notified about, and TradingView runs it consistently across any market and timeframe. That is why traders, analysts, and developers write Pine Script: it turns a manual charting idea into a repeatable tool. These tools are for tracking, visualizing, and testing market ideas; they do not tell you what to trade, and that decision always remains yours.

Writing that code by hand means learning Pine Script's syntax, its type system, and the exact names of hundreds of built-in functions. It is a real programming language, and small mistakes stop a script from compiling in the Pine Editor.

Turn this into Pine Script

This tool computes one %K reading. On a chart both %K and %D update every bar in the oscillator pane. Pine Script gives you %K directly with ta.stoch(close, high, low, 14) and %D as a quick ta.sma of it, but the crossover logic, zones, and alerts are still yours to build.

Pine Script v6
//@version=6
indicator("Stochastic", overlay=false)

k = ta.stoch(close, high, low, 14)
d = ta.sma(k, 3)

plot(k, "%K", color=color.blue)
plot(d, "%D", color=color.orange)
hline(80, "Overbought")
hline(20, "Oversold")

PineScripter is an AI built specifically for Pine Script. You describe what you want in plain English and it writes TradingView-ready v5 or v6 code. Because it is specialized on the Pine Script language and its exact function signatures, it tends to produce code that compiles far more reliably than general-purpose models like ChatGPT, which often invent functions that do not exist in Pine Script.

PineScripter is an AI developer tool that helps you write Pine Script code. It is not a financial advisor and will never offer financial, investment, or trading advice. Everything on this page, including the calculator and the explanations, is provided purely for educational and informational purposes. Any decision about how to interpret an indicator or trade a market is entirely your own. See our full disclaimer for more.