DINEXSPACEXAUUSD SpecialistEAs available to rentCustom EA: Strategy → Code → BacktestView rentable EA bots
// STOCHASTIC.MQ5

What is the Stochastic oscillator?

Stochastic OscillatorMomentum

Compares the close with the full range of the last N candles to show where price sits within that range.

What is Stochastic Oscillator?

Compares the close with the recent high–low range to measure momentum and overbought/oversold zones.

Stochastic Oscillator — Stochastic(14,3,3) %K 90.8 / %D 92.3 — SIMULATEDDINEXSPACE / MomentumStochastic(14,3,3) %K 90.8 / %D 92.3XAUUSD · 1H / SIMULATEDRESSUP2,331.12,359.42,426.0▲ BUYCandle 94: BUY▲ BUYCandle 100: BUY▼ SELLCandle 112: SELLVOL*2080%K / %DCANDLE 1CANDLE 29CANDLE 57CANDLE 85CANDLE 112MA · EMA 14 ━━━━ / VOL* · ILLUSTRATIVE CANDLE RANGEEMA 14Illustrative data — not real market data, not a trading signalStochastic Oscillator — Stochastic(14,3,3) %K 90.8 / %D 92.3 — SIMULATEDSTOCHASTIC 14/3/3XAUUSD · 1H / SIMULATEDRESSUP2,331.12,426.0▼ SELLCandle 112: SELLVOL*2080%K / %DStochastic Oscillator — Stochastic(14,3,3) %K 90.8 / %D 92.3 — SIMULATEDSTOCHASTIC 14/3/3XAUUSD · 1H / SIMULATEDRESSUP2,331.12,426.0▼ SELLCandle 112: SELLVOL*2080%K / %DStochastic Oscillator — Stochastic(14,3,3) %K 90.8 / %D 92.3 — SIMULATEDSTOCHASTIC 14/3/3XAUUSD · 1H / SIMULATEDRESSUP2,331.12,426.0▼ SELLCandle 112: SELLVOL*2080%K / %DEMA 14Illustrative data — not real market data, not a trading signal

Illustrative signals of the rule on simulated data — not a trading recommendation.

Rule: %K crosses above %D in the zone below 20: buy; crosses below in the zone above 80: sell. Entry = close of the signal candle; SL = entry ∓ 1.5 × ATR(14); TP1/TP2/TP3 = 1R/2R/3R.

Use this indicator to create a Custom EA brief →
// WHY_USE_IT

Where this indicator is strong

Three reasons Stochastic Oscillator is still used after decades.

More sensitive than RSI

It reacts earlier to short-term changes, which suits intraday trading.

Two confirming lines

The %K and %D cross creates a second layer of confirmation instead of a single threshold.

Suits ranging markets

Very effective when price moves within a defined range.

// READING_SIGNALS

How to read Stochastic Oscillator signals

How Stochastic Oscillator produces its number, and what each shape on the chart means.

Formula and how it works

Raw %K = 100 × (close − lowest low of N periods) / (highest high − lowest low). Slow %K is the SMA of raw %K, and %D is the SMA of slow %K. Values above 80 are overbought, below 20 oversold.

How to use it in an EA

Enter when %K crosses %D in an extreme zone; combine with the main trend to avoid noisy signals in a strong one-way market.

Fits when

The market moves sideways, with a relatively clear upper and lower boundary.

Struggles when

A strong trend. The indicator stays saturated in the extreme zone for many sessions and keeps suggesting trades against the trend.

%K crosses above %D in the oversold zoneThis indicator's usual buy signal.
Both lines above 80The close is in the upper part of the recent range.
Both lines stuck together, flat in the extreme zoneThe trend is very strong — this is when the indicator is most misleading.
Common mistakes

Using it alone in a trending market. It always needs a trend filter in front to know which direction is allowed.

// PARAMETERS

Recommended MT5 parameters for Stochastic Oscillator

Default values of the sample file; test them for your market and timeframe.

ParameterDescription
InpKRaw %K period (default 14).
InpSlow%K smoothing period (default 3).
InpDSMA period for the %D line (default 3).
// INSTALL

Put the indicator into MetaTrader 5

Four steps, no software needed besides MT5.

01Download the .mq5 file

Click the download button above; the file saves to your computer under the indicator's name.

02Open the data folder

In MetaTrader 5 choose File → Open Data Folder, then go to MQL5/Indicators.

03Compile

Open the file in MetaEditor and click Compile. No errors means the indicator is ready.

04Drag it onto the chart

Go back to MT5, refresh the Navigator and drag the indicator onto the price chart.

📄 stochastic.mq5

DinexSpace wrote this file from the indicator's public formula, not from any commercial source. You are free to edit and reuse it.

// THE_DIFFERENCE

How it differs from MetaTrader 5's built-in indicator

The short answer: the formula is not different. What differs is what you can do with it.

Stochastic Oscillator here gives exactly the same number as MetaTrader 5's built-in version — on purpose. The four points below are what differs, and all four can be read from the very stochastic.mq5 you download.

Calls a built-in indicator
No — the calculation sits in OnCalculate and can be copied straight into an EA
External libraries
Not a single #import declaration
Code length
64 lines · 3 input parameters
How it draws
A separate window below the price chart · calculated incrementally, does not redraw the past

Why this library promises no secret formula — read the full explanation on the library page.

// COMBINATIONS

Which indicators to pair Stochastic Oscillator with, and what you gain

Each indicator only answers one question. Pairing well means covering the right weakness, not stacking more.

Stochastic OscillatorAverage Directional Index
What you gain
An off switch. Stochastic saturates and keeps suggesting counter-trend trades when the trend is strong; ADX shows exactly when that is.
Note
This is the most important pair for Stochastic, because its weakness lies entirely in trending phases.
See Average Directional Index
Stochastic OscillatorMoving Average
What you gain
Only take signals in the direction of the main trend and drop all the counter signals.
Note
You drop half of the signals. The number of trades falls sharply — that is the price you pay.
See Moving Average
Stochastic OscillatorBollinger Bands
What you gain
Zone confluence: price touches the band edge while %K and %D are in the extreme zone.
Note
Only use it once the market is confirmed to be sideways; otherwise both indicators are wrong at the same time.
See Bollinger Bands
// FAQ

Frequently asked questions about Stochastic Oscillator

How is Stochastic different from RSI?

RSI compares gains with losses over N candles. Stochastic compares the close with the full high–low range of N candles. Stochastic is more sensitive, so it gives more signals, with more noise.

What are the %K and %D lines?

%K is the base value, %D is a moving average of %K, so it is smoother and slower. The signal usually used is %K crossing %D in the overbought or oversold zone, adding a layer of confirmation compared with just looking at the threshold.

Does Stochastic Oscillator on this page use real or simulated data?

The chart on this page uses a deterministic simulated candle series; it is not market prices or trading results.

// SAME_GROUP

Other momentum indicators

Indicators in the same momentum group, often used instead of or alongside Stochastic Oscillator.

Turn Stochastic Oscillator into an automated EA

An indicator draws signals, but when to enter, where to stop out and how much to risk are still your set of rules. Send those rules and DinexSpace builds them into an EA.

Use this indicator to create a Custom EA brief