Schaff Trend Cycle (STC)
Summary
Schaff Trend Cycle (Doug Schaff): a MACD line passed twice through a stochastic, each pass smoothed by half. Bounded 0 to 100, read against 25 and 75: turning up from below 25 is bullish, turning down from above 75 bearish.
Formula
MACD[t] = EMA(x, fast)[t] - EMA(x, slow)[t]
Frac1[t] = 100 * (MACD[t] - min(MACD, cycle)) / (max(MACD, cycle) - min(MACD, cycle))
PF[t] = PF[t-1] + 0.5 * (Frac1[t] - PF[t-1])
Frac2[t] = 100 * (PF[t] - min(PF, cycle)) / (max(PF, cycle) - min(PF, cycle))
STC[t] = PFF[t] = PFF[t-1] + 0.5 * (Frac2[t] - PFF[t-1])
min and max are taken over the last cycle values, current one included. When a range is zero, the fraction keeps its previous value (0 before any). Each smoother starts on its first input.
Notes
- The smoothing factor is fixed at 0.5, as in Schaff's published code.
- The MACD line is TA-Lib's: both EMAs are seeded with a simple average over windows ending on the same bar. The published code runs the EMAs from the first bar of the data.
- If the slow period is set smaller than the fast period, the two are swapped, as in
MACD. - Being recursive, an output depends on how much history precedes it. The unstable period warms the two smoothers; the EMA unstable period warms the MACD line.
Inputs
inReal— Input series (typically close)
Outputs
outReal— Schaff Trend Cycle, from 0 to 100
Parameters
| Parameter | Type | Default | Accepted values | Description |
|---|---|---|---|---|
optInFastPeriod | integer | 23 | 2–100000 | Period of the fast EMA |
optInSlowPeriod | integer | 50 | 2–100000 | Period of the slow EMA |
optInCyclePeriod | integer | 10 | 2–100000 | Window of both stochastic stages |
Properties
Numerical Stability: Initial Unstable Period — Tunable via STC's own unstable period and EMA's, which STC computes internally.
| ☐ Overlap Input |
| ✅ Independent Y-Axis i |
| ☐ Candlestick |
| ☐ Can Output NaN or ±Inf |
| ☐ Identity at Period 1 |
Implementation
TA-Lib Definition: stc.c · stc.yaml
| Native | File |
|---|---|
| C | ta_STC.c |
| Rust | stc.rs |
| Java | Core_STC.java |
| C# | Core_STC.cs |
TA-Lib is also available for Python, R and more using a wrapper.
Aliases
Schaff Trend Cycle, Schaff TC
See Also
References
- Doug Schaff, "Releasing the Code to the Schaff Trend Cycle", FX-Strategy.com, published on FXStreet.com, February 15, 2008. The EasyLanguage source, and the 23/50/10 defaults.
- Doug Schaff, "Catching Currency Moves with The Schaff Trend Cycle Indicator", Chartpoint, July/August 2002.