Skip to content

Stochastic

STOCH identifies overbought and oversold conditions in a market.

Method

tm.ta.stoch(source_high, source_low, source_close, fastk_period, slowk_period, slowk_matype, slowd_period, slowd_matype)

Inputs

ParameterArgument typeDescriptionDefault Value
source_highpd.SeriesHigh prices series-
source_lowpd.SeriesLow prices series-
source_closepd.SeriesClose prices series-
fastk_periodintFast %K period for the indicator5
slowk_periodintSlow %K period for the indicator3
slowk_matypeintSlow %K Moving Average type0
slowd_periodintSlow %D period for the indicator3
slowd_matypeintSlow %D Moving Average type0

Outputs

OutputType
slowknp.ndarray
slowdnp.ndarray

Example usage

strategy.py
import tradomate as tm
@tm.strategy()
def my_strategy(config: tm.TradomateConfig, data: tm.TradomateData):
# Trying out Stochastic
slowk, slowd = tm.ta.stoch(data.high, data.low, data.close, fastk_period=5, slowk_period=3, slowk_matype=0, slowd_period=3, slowd_matype=0)
# Get the last value and print
last_value = slowk.iloc[-1]
tm.log(f"Last value of Stochastic is {last_value}")
# Plot the values of slowk
tm.plot(slowk, title="Stochastic", overlay=False)