---
id: "M:cAlgo.API.Internals.IIndicatorsAccessor.StochasticOscillator(System.Int32,System.Int32,System.Int32,cAlgo.API.MovingAverageType)"
kind: "method"
type: "T:cAlgo.API.Internals.IIndicatorsAccessor"
url: "https://help.ctrader.com/ctrader-algo/references/Indicators/IIndicatorsAccessor/StochasticOscillator/"
---

> Documentation index for agents: https://help.ctrader.com/ctrader-algo/llms.txt · machine index: https://help.ctrader.com/ctrader-algo/api.json

# IIndicatorsAccessor.StochasticOscillator

Member of [IIndicatorsAccessor](https://help.ctrader.com/ctrader-algo/references/Indicators/IIndicatorsAccessor/index.md).

## StochasticOscillator(int kPeriods, int kSlowing, int dPeriods, MovingAverageType maType)

The Stochastic Oscillator is a momentum indicator that aims to show price reversals by comparing the closing price to the price range.

Environments: Desktop supported · CLI supported · Cloud supported.

C#:

```csharp
StochasticOscillator StochasticOscillator(int kPeriods, int kSlowing, int dPeriods, MovingAverageType maType)
```

Python:

```python
api.Indicators.StochasticOscillator(kPeriods: int, kSlowing: int, dPeriods: int, maType: MovingAverageType) -> StochasticOscillator
```

### Parameters

- `kPeriods` (`int`, Python `int`): The value of the k periods used for calculation.
- `kSlowing` (`int`, Python `int`): The value of the k slowing used for calculation.
- `dPeriods` (`int`, Python `int`): The value of the d periods used for calculation.
- `maType` (`MovingAverageType`, Python `MovingAverageType`): Type of the Moving Average.

### Returns

`StochasticOscillator` — Stochastic Oscillator indicator instance.

### Examples

C#:

```csharp
var stochastic = Indicators.StochasticOscillator(9, 3, 9, MovingAverageType.Simple);
if (stochastic.PercentK.LastValue < 20)
    Print("Stochastic %K is oversold: {0}, %D: {1}", stochastic.PercentK.LastValue, stochastic.PercentD.LastValue);
```

Python:

```python
stochastic = api.Indicators.StochasticOscillator(9, 3, 9, MovingAverageType.Simple)
if stochastic.PercentK.LastValue < 20:
    api.Print(f"Stochastic %K is oversold: {stochastic.PercentK.LastValue}, %D: {stochastic.PercentD.LastValue}")
```

## StochasticOscillator(int kPeriods, int kSlowing, int dPeriods, MovingAverageType maType, StochasticCalculationType calculationType)

The Stochastic Oscillator is a momentum indicator that aims to show price reversals by comparing the closing price to the price range.

Environments: Desktop supported · CLI supported · Cloud supported.

C#:

```csharp
StochasticOscillator StochasticOscillator(int kPeriods, int kSlowing, int dPeriods, MovingAverageType maType, StochasticCalculationType calculationType)
```

Python:

```python
api.Indicators.StochasticOscillator(kPeriods: int, kSlowing: int, dPeriods: int, maType: MovingAverageType, calculationType: StochasticCalculationType) -> StochasticOscillator
```

### Parameters

- `kPeriods` (`int`, Python `int`): The value of the k periods used for calculation.
- `kSlowing` (`int`, Python `int`): The value of the k slowing used for calculation.
- `dPeriods` (`int`, Python `int`): The value of the d periods used for calculation.
- `maType` (`MovingAverageType`, Python `MovingAverageType`): Type of the Moving Average.
- `calculationType` (`StochasticCalculationType`, Python `StochasticCalculationType`): Type of calculation.

### Returns

`StochasticOscillator` — Stochastic Oscillator indicator instance.

### Examples

C#:

```csharp
var stochastic = Indicators.StochasticOscillator(9, 3, 9, MovingAverageType.Simple, StochasticCalculationType.CloseClose);
Print("Stochastic (close/close) %K: {0}, %D: {1}", stochastic.PercentK.LastValue, stochastic.PercentD.LastValue);
```

Python:

```python
stochastic = api.Indicators.StochasticOscillator(9, 3, 9, MovingAverageType.Simple, StochasticCalculationType.CloseClose)
api.Print(f"Stochastic (close/close) %K: {stochastic.PercentK.LastValue}, %D: {stochastic.PercentD.LastValue}")
```

## StochasticOscillator(Bars bars, int kPeriods, int kSlowing, int dPeriods, MovingAverageType maType)

The Stochastic Oscillator is a momentum indicator that aims to show price reversals by comparing the closing price to the price range.

Environments: Desktop supported · CLI supported · Cloud supported.

C#:

```csharp
StochasticOscillator StochasticOscillator(Bars bars, int kPeriods, int kSlowing, int dPeriods, MovingAverageType maType)
```

Python:

```python
api.Indicators.StochasticOscillator(bars: Bars, kPeriods: int, kSlowing: int, dPeriods: int, maType: MovingAverageType) -> StochasticOscillator
```

### Parameters

- `bars` (`Bars`, Python `Bars`): The Bars that will be used by indicator, you can pass another timeframe/symbol bars
- `kPeriods` (`int`, Python `int`): The value of the k periods used for calculation.
- `kSlowing` (`int`, Python `int`): The value of the k slowing used for calculation.
- `dPeriods` (`int`, Python `int`): The value of the d periods used for calculation.
- `maType` (`MovingAverageType`, Python `MovingAverageType`): Type of the Moving Average.

### Returns

`StochasticOscillator` — Stochastic Oscillator indicator instance.

### Examples

C#:

```csharp
var dailyBars = MarketData.GetBars(TimeFrame.Daily);
var dailyStochastic = Indicators.StochasticOscillator(dailyBars, 9, 3, 9, MovingAverageType.Simple);
Print("Daily stochastic %K: {0}, %D: {1}", dailyStochastic.PercentK.LastValue, dailyStochastic.PercentD.LastValue);
```

Python:

```python
dailyBars = api.MarketData.GetBars(TimeFrame.Daily)
dailyStochastic = api.Indicators.StochasticOscillator(dailyBars, 9, 3, 9, MovingAverageType.Simple)
api.Print(f"Daily stochastic %K: {dailyStochastic.PercentK.LastValue}, %D: {dailyStochastic.PercentD.LastValue}")
```

## StochasticOscillator(Bars bars, int kPeriods, int kSlowing, int dPeriods, MovingAverageType maType, StochasticCalculationType calculationType)

The Stochastic Oscillator is a momentum indicator that aims to show price reversals by comparing the closing price to the price range.

Environments: Desktop supported · CLI supported · Cloud supported.

C#:

```csharp
StochasticOscillator StochasticOscillator(Bars bars, int kPeriods, int kSlowing, int dPeriods, MovingAverageType maType, StochasticCalculationType calculationType)
```

Python:

```python
api.Indicators.StochasticOscillator(bars: Bars, kPeriods: int, kSlowing: int, dPeriods: int, maType: MovingAverageType, calculationType: StochasticCalculationType) -> StochasticOscillator
```

### Parameters

- `bars` (`Bars`, Python `Bars`): The Bars that will be used by indicator, you can pass another timeframe/symbol bars
- `kPeriods` (`int`, Python `int`): The value of the k periods used for calculation.
- `kSlowing` (`int`, Python `int`): The value of the k slowing used for calculation.
- `dPeriods` (`int`, Python `int`): The value of the d periods used for calculation.
- `maType` (`MovingAverageType`, Python `MovingAverageType`): Type of the Moving Average.
- `calculationType` (`StochasticCalculationType`, Python `StochasticCalculationType`): Type of calculation.

### Returns

`StochasticOscillator` — Stochastic Oscillator indicator instance.

### Examples

C#:

```csharp
var dailyBars = MarketData.GetBars(TimeFrame.Daily);
var dailyStochastic = Indicators.StochasticOscillator(dailyBars, 9, 3, 9, MovingAverageType.Simple, StochasticCalculationType.LowHigh);
Print("Daily stochastic (low/high) %K: {0}", dailyStochastic.PercentK.LastValue);
```

Python:

```python
dailyBars = api.MarketData.GetBars(TimeFrame.Daily)
dailyStochastic = api.Indicators.StochasticOscillator(dailyBars, 9, 3, 9, MovingAverageType.Simple, StochasticCalculationType.LowHigh)
api.Print(f"Daily stochastic (low/high) %K: {dailyStochastic.PercentK.LastValue}")
```

