Introduction
Automation Platform
Botmain DAO
Building Trading Strategies
API References Dev Live Stream
@botmain/indicators / Class

StochasticOscillator

The StochasticOscillator is a momentum indicator that compares a security’s closing price to its price range over a specific time period. This indicator is shown as two lines on a chart:

  • %K, which is the main line representing the level of the Stochastic Oscillator.
  • %D, which is a moving average of %K and typically displayed as a dotted line. The Stochastic Oscillator provides signals for buying and selling:
  • Buy Signal: When either %K or %D falls below a certain threshold (e.g., 20) and then climbs back above it.
  • Sell Signal: When the Oscillator rises above a higher threshold (e.g., 80) and then drops below it.

These levels indicate overbought or oversold conditions and suggest potential price reversals. The calculation of the Stochastic Oscillator involves several steps:

RawK = 100 * (Close - Lowest(Low, RawPeriod)) / (Highest(High, RawPeriod) - Lowest(Low, RawPeriod))
%K = SMA(RawK, KPeriod)
%D = SMA(%K, DPeriod)
  • RawK calculates the raw Stochastic value.
  • %K smooths this value using a Simple Moving Average (SMA) over KPeriod.
  • %D then takes an SMA of %K over DPeriod to provide a signal line.

Constructor

The default constructor will set the rawPeriod = 14, kPeriod = 3, dPeriod = 3

Presentation
constructor(
	
): StochasticOscillator;

Properties

NameTypeDescription
historyCapacity
inherited from BaseIndicator
number

The maximum history held by the indicator. As new data comes in only this many points are kept.

historyCount
inherited from BaseIndicator
number

The number of historical points currently held by the indicator. Will never be larger than historyCapacity.

last
inherited from BaseIndicator
T
values
inherited from BaseIndicator
T[]

Methods

add()

inherited from BaseBarsIndicator
No documentation has been provided.
Presentation
add(bar: Bar): void;
Parameters
NameTypeDescription
bar
Bar

Adds the latest OHLCV bar to the indicator. Normally called for each indicator in onBarClose()

Returns

void