Need assistance to properly calculate STC(schaff trend cycle) and graph it using pandas and plotly

Viewed 712

I've been trying to graph STC using fintas equation.

    period_fast = 23
    period_slow = 50
    period = 10

    EMA_fast = pd.Series(
        ohlc["close"].ewm(ignore_na=False, span=period_fast, adjust=adjust).mean(),
        name="EMA_fast",
    )

    EMA_slow = pd.Series(
        ohlc["close"].ewm(ignore_na=False, span=period_slow, adjust=adjust).mean(),
        name="EMA_slow",
    )

    MACD = pd.Series((EMA_fast - EMA_slow), name="MACD")
    STOK = (
        (MACD - MACD.rolling(window=period).min())
        / (MACD.rolling(window=period).max() - MACD.rolling(window=period).min())
    ) * 100
    STOD = STOK.rolling(window=period).mean()

    return pd.Series(
        100 * (MACD - (STOK * MACD)) / ((STOD * MACD) - (STOK * MACD)),
        name="{0} period STC.".format(period),
    )

I get the data from:https://api.binance.com/api/v3/klines?symbol=BTCUSDC&interval=1h

Looking at ERDBTC you can see the values are supposed to be between 0 and 100 ERDBTC with STC graphed

However I am getting values that are below 0 and very much above 100. When I graph it I get this: Plotly Graph of STC

I'm wondering if there is something I am missing in order to be able to graph STC? Are the values perhaps normal and the graphing script is somehow turning it into a graph between 0-100? I have properly entered the data as I can graph the candlesticks properly: Candlestick

I just seem to have a problem with STC

0 Answers
Related