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
Parameter | Argument type | Description | Default Value |
---|---|---|---|
source_high | pd.Series | High prices series | - |
source_low | pd.Series | Low prices series | - |
source_close | pd.Series | Close prices series | - |
fastk_period | int | Fast %K period for the indicator | 5 |
slowk_period | int | Slow %K period for the indicator | 3 |
slowk_matype | int | Slow %K Moving Average type | 0 |
slowd_period | int | Slow %D period for the indicator | 3 |
slowd_matype | int | Slow %D Moving Average type | 0 |
Outputs
The outputs are returned as a tuple of objects. Make sure to unpack them as shown in the example usage.
Output | Type |
---|---|
slowk | np.ndarray |
slowd | np.ndarray |
Example usage
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)