OPEN-SOURCE SCRIPT
已更新 Schaff Trend Cycle - STC | TR

🎯 Overview
Schaff Trend Cycle – STC | TR is a sophisticated technical indicator developed by Doug Schaff that combines elements of MACD and stochastic to identify trend direction, cycle phases, and potential turning points. This enhanced version, created by Tiagorocha1989, offers extensive customization – including twelve moving average types, eight color themes, and comprehensive visual feedback. The STC oscillator oscillates between 0 and 100, helping traders spot overbought/oversold conditions, trend strength, and cycle completions with exceptional clarity.
🔧 How It Works
The Schaff Trend Cycle (STC) is a multi‑stage indicator that first computes a MACD line (the difference between two moving averages of the price), then applies a double stochastic smoothing process to this MACD line. This unique approach filters out market noise and highlights the underlying cyclical trend.
Core Logic (Conceptual)
MACD Calculation: A fast and a slow moving average are applied to the price source. Their difference forms a MACD line, representing momentum.
First Stochastic Smoothing: The MACD line is normalized using a stochastic formula over a specified cycle length, producing a value between 0 and 100. This step identifies where the current MACD value stands within its recent range.
First Smoothing: The resulting stochastic value is smoothed with a moving average.
Second Stochastic Smoothing: The smoothed value is again normalized using the same cycle length, then smoothed once more.
Final STC Value: The result is a bounded oscillator (0–100) that reflects the position of the price within its cyclical trend.
Readings above the overbought level (default 75) suggest that the uptrend may be mature and a reversal or pullback could occur.
Readings below the oversold level (default 25) suggest that the downtrend may be exhausted and a bounce or reversal could be imminent.
The 50 level acts as a neutral zone or centerline.
✨ Key Features
🔹 Dual‑Stage Stochastic Smoothing
The double stochastic process on the MACD line effectively filters out random price movements, making the STC particularly effective in trending and cyclical markets.
🔹 Flexible Moving Average Selection
Twelve moving average types are available for both the initial MACD calculation and the smoothing stages:
EMA, SMA, RMA, WMA, VWMA, HMA, DEMA, TEMA, TRIMA, FRAMA, SWMA, T3 (with adjustable factor).
🔹 Customizable Parameters
Fast Length – Period for the fast moving average (default 12).
Slow Length – Period for the slow moving average (default 26).
Cycle Length – Lookback period for the stochastic calculations (default 28).
1st Smoothing Length – Smoothing applied after the first stochastic (default 3).
2nd Smoothing Length – Smoothing applied after the second stochastic (default 3).
Overbought Level – Upper threshold (default 75, adjustable 20–100).
Oversold Level – Lower threshold (default 25, adjustable 0–80).
Source – Price data used for the moving averages (default close).
MA Type – The moving average method for all calculations.
T3 Factor – Specific factor for the T3 moving average (default 0.7).
🔹 Eight Distinct Color Themes
Identical to the companion CMO | TR indicator, ensuring visual consistency across your charts:
Classic – Green/Red
Modern – White/Purple
Robust – Amber/Maroon
Accented – Violet/Pink
Monochrome – Light gray/Dark gray
Moderate – Green/Red
Aqua – Blue/Orange
Cosmic – Pink/Purple
🔹 Comprehensive Visual Feedback
Colored STC Line: Changes color based on its zone: green/theme color above overbought, red/theme color below oversold, gray in the neutral zone.
Overbought & Oversold Lines: Horizontal lines at the user‑defined levels, semi‑transparent.
Midline: A faint line at 50 for reference.
Gradient Fill Zones:
Overbought Fill: Gradient from the STC line down to the overbought level when STC is above it.
Oversold Fill: Gradient from the STC line up to the oversold level when STC is below it.
Dynamic Fill: Additional fill that highlights the area between the STC line and the midline, coloured according to the prevailing zone.
Background Fill: A subtle gray fill between the overbought and oversold lines.
Color‑Coded Candles: Candles on the price chart take the bullish/bearish color when STC is above overbought or below oversold, providing a clear visual cue of extreme conditions.
Signal Markers: Triangle up/down symbols appear when STC crosses above the overbought level (bearish signal, “SHORT”) or below the oversold level (bullish signal, “LONG”).
Live Value Display: A floating label near the last bar shows the current STC value, color‑coded by zone.
Trend Table: A table on the chart displays “⬆️ Bullish” or “⬇️ Bearish” based on whether STC is above overbought or below oversold.
🔹 Ready‑to‑Use Alerts
Built‑in alert conditions trigger on:
LONG signals when STC crosses below the oversold level (bullish reversal).
SHORT signals when STC crosses above the overbought level (bearish reversal).
⚙️ Settings Summary
Setting Description Default
Color Choice Select from eight visual themes Classic
Fast Length Period for fast MA (MACD component) 12
Slow Length Period for slow MA (MACD component) 26
Cycle Length Lookback for stochastic calculations 28
1st Smoothing Len Smoothing after first stochastic 3
2nd Smoothing Len Smoothing after second stochastic 3
Overbought Level Upper threshold (20–100) 75
Oversold Level Lower threshold (0–80) 25
Source Price source for moving averages Close
MA Type Moving average method (12 options) EMA
T3 Factor Factor for T3 moving average 0.7
📈 Practical Applications
🔹 Overbought / Oversold Detection
STC values above the overbought level indicate that the uptrend may be overextended, warning of a possible reversal or pullback.
STC values below the oversold level suggest the downtrend is exhausted, hinting at a potential bounce or reversal.
Gradient fills make these extreme zones instantly recognizable.
🔹 Crossover Signals
Bullish Signal: When STC crosses below the oversold level and then turns upward, it can signal the start of a new uptrend. The indicator plots a “LONG” triangle below the bar.
Bearish Signal: When STC crosses above the overbought level and then turns downward, it can signal the start of a new downtrend. A “SHORT” triangle appears above the bar.
These signals are plotted only once per crossing to avoid clutter.
🔹 Trend Confirmation
STC staying above the overbought level for an extended period confirms a strong uptrend.
STC staying below the oversold level confirms a strong downtrend.
When STC oscillates between the two thresholds, the market is likely range‑bound.
🔹 Divergence Trading
Bullish Divergence: Price makes a lower low, but STC makes a higher low (especially near or below oversold) → potential upside reversal.
Bearish Divergence: Price makes a higher high, but STC makes a lower high (especially near or above overbought) → potential downside reversal.
Divergences are most reliable when they occur at extreme levels.
🔹 Cycle Identification
The STC is specifically designed to identify cyclical turning points. By adjusting the cycle length, traders can adapt the indicator to different market rhythms (short‑term, medium‑term, or long‑term cycles).
🔹 Multiple Timeframe Analysis
Compare STC readings across timeframes to align trades with the larger trend. For example, a bullish signal on a lower timeframe carries more weight if the higher‑timeframe STC is also bullish (above oversold or rising).
🎯 Ideal For
Cycle Traders seeking to capitalize on recurring market rhythms.
Momentum Traders wanting a clean, filtered view of trend strength.
Mean Reversion Traders looking for overbought/oversold opportunities.
Swing Traders capturing medium‑term trend shifts.
System Developers needing a bounded, reliable oscillator for strategy building.
Traders familiar with MACD & Stochastic who appreciate a hybrid approach.
📌 Key Takeaways
Bounded Range: STC oscillates between 0 and 100, providing clear overbought/oversold levels at 75/25 (user‑adjustable).
Noise Reduction: The double stochastic smoothing filters out market noise, making signals more reliable than raw MACD or single stochastic.
Customizable Smoothing: Twelve moving average types allow fine‑tuning for any trading style.
Comprehensive Visualization: Color themes, gradient fills, candle coloring, and live labels offer immediate market insight.
Signal Clarity: Triangle markers appear only at significant crossovers, reducing visual clutter.
Divergence Capability: Excellent for spotting both regular and hidden divergences.
Alert‑Ready: Built‑in alerts for long/short signals.
⚠️ Important Notes
The default parameters (12, 26, 28) are inspired by the classic MACD and stochastic settings, but they can be adjusted to suit different timeframes and market conditions. Shorter cycle lengths make the indicator more responsive but may increase false signals; longer lengths provide smoother readings. The overbought/oversold levels (75/25) are guidelines – in strongly trending markets, STC can remain in extreme zones for extended periods. Divergences are most reliable when they occur at extreme readings. Always combine with proper risk management and additional confirmation for best results.
Disclaimer: This indicator is provided for educational and informational purposes only. Past performance is not indicative of future results. Always conduct thorough testing and align with your risk management strategy before live deployment.
Schaff Trend Cycle – STC | TR is a sophisticated technical indicator developed by Doug Schaff that combines elements of MACD and stochastic to identify trend direction, cycle phases, and potential turning points. This enhanced version, created by Tiagorocha1989, offers extensive customization – including twelve moving average types, eight color themes, and comprehensive visual feedback. The STC oscillator oscillates between 0 and 100, helping traders spot overbought/oversold conditions, trend strength, and cycle completions with exceptional clarity.
🔧 How It Works
The Schaff Trend Cycle (STC) is a multi‑stage indicator that first computes a MACD line (the difference between two moving averages of the price), then applies a double stochastic smoothing process to this MACD line. This unique approach filters out market noise and highlights the underlying cyclical trend.
Core Logic (Conceptual)
MACD Calculation: A fast and a slow moving average are applied to the price source. Their difference forms a MACD line, representing momentum.
First Stochastic Smoothing: The MACD line is normalized using a stochastic formula over a specified cycle length, producing a value between 0 and 100. This step identifies where the current MACD value stands within its recent range.
First Smoothing: The resulting stochastic value is smoothed with a moving average.
Second Stochastic Smoothing: The smoothed value is again normalized using the same cycle length, then smoothed once more.
Final STC Value: The result is a bounded oscillator (0–100) that reflects the position of the price within its cyclical trend.
Readings above the overbought level (default 75) suggest that the uptrend may be mature and a reversal or pullback could occur.
Readings below the oversold level (default 25) suggest that the downtrend may be exhausted and a bounce or reversal could be imminent.
The 50 level acts as a neutral zone or centerline.
✨ Key Features
🔹 Dual‑Stage Stochastic Smoothing
The double stochastic process on the MACD line effectively filters out random price movements, making the STC particularly effective in trending and cyclical markets.
🔹 Flexible Moving Average Selection
Twelve moving average types are available for both the initial MACD calculation and the smoothing stages:
EMA, SMA, RMA, WMA, VWMA, HMA, DEMA, TEMA, TRIMA, FRAMA, SWMA, T3 (with adjustable factor).
🔹 Customizable Parameters
Fast Length – Period for the fast moving average (default 12).
Slow Length – Period for the slow moving average (default 26).
Cycle Length – Lookback period for the stochastic calculations (default 28).
1st Smoothing Length – Smoothing applied after the first stochastic (default 3).
2nd Smoothing Length – Smoothing applied after the second stochastic (default 3).
Overbought Level – Upper threshold (default 75, adjustable 20–100).
Oversold Level – Lower threshold (default 25, adjustable 0–80).
Source – Price data used for the moving averages (default close).
MA Type – The moving average method for all calculations.
T3 Factor – Specific factor for the T3 moving average (default 0.7).
🔹 Eight Distinct Color Themes
Identical to the companion CMO | TR indicator, ensuring visual consistency across your charts:
Classic – Green/Red
Modern – White/Purple
Robust – Amber/Maroon
Accented – Violet/Pink
Monochrome – Light gray/Dark gray
Moderate – Green/Red
Aqua – Blue/Orange
Cosmic – Pink/Purple
🔹 Comprehensive Visual Feedback
Colored STC Line: Changes color based on its zone: green/theme color above overbought, red/theme color below oversold, gray in the neutral zone.
Overbought & Oversold Lines: Horizontal lines at the user‑defined levels, semi‑transparent.
Midline: A faint line at 50 for reference.
Gradient Fill Zones:
Overbought Fill: Gradient from the STC line down to the overbought level when STC is above it.
Oversold Fill: Gradient from the STC line up to the oversold level when STC is below it.
Dynamic Fill: Additional fill that highlights the area between the STC line and the midline, coloured according to the prevailing zone.
Background Fill: A subtle gray fill between the overbought and oversold lines.
Color‑Coded Candles: Candles on the price chart take the bullish/bearish color when STC is above overbought or below oversold, providing a clear visual cue of extreme conditions.
Signal Markers: Triangle up/down symbols appear when STC crosses above the overbought level (bearish signal, “SHORT”) or below the oversold level (bullish signal, “LONG”).
Live Value Display: A floating label near the last bar shows the current STC value, color‑coded by zone.
Trend Table: A table on the chart displays “⬆️ Bullish” or “⬇️ Bearish” based on whether STC is above overbought or below oversold.
🔹 Ready‑to‑Use Alerts
Built‑in alert conditions trigger on:
LONG signals when STC crosses below the oversold level (bullish reversal).
SHORT signals when STC crosses above the overbought level (bearish reversal).
⚙️ Settings Summary
Setting Description Default
Color Choice Select from eight visual themes Classic
Fast Length Period for fast MA (MACD component) 12
Slow Length Period for slow MA (MACD component) 26
Cycle Length Lookback for stochastic calculations 28
1st Smoothing Len Smoothing after first stochastic 3
2nd Smoothing Len Smoothing after second stochastic 3
Overbought Level Upper threshold (20–100) 75
Oversold Level Lower threshold (0–80) 25
Source Price source for moving averages Close
MA Type Moving average method (12 options) EMA
T3 Factor Factor for T3 moving average 0.7
📈 Practical Applications
🔹 Overbought / Oversold Detection
STC values above the overbought level indicate that the uptrend may be overextended, warning of a possible reversal or pullback.
STC values below the oversold level suggest the downtrend is exhausted, hinting at a potential bounce or reversal.
Gradient fills make these extreme zones instantly recognizable.
🔹 Crossover Signals
Bullish Signal: When STC crosses below the oversold level and then turns upward, it can signal the start of a new uptrend. The indicator plots a “LONG” triangle below the bar.
Bearish Signal: When STC crosses above the overbought level and then turns downward, it can signal the start of a new downtrend. A “SHORT” triangle appears above the bar.
These signals are plotted only once per crossing to avoid clutter.
🔹 Trend Confirmation
STC staying above the overbought level for an extended period confirms a strong uptrend.
STC staying below the oversold level confirms a strong downtrend.
When STC oscillates between the two thresholds, the market is likely range‑bound.
🔹 Divergence Trading
Bullish Divergence: Price makes a lower low, but STC makes a higher low (especially near or below oversold) → potential upside reversal.
Bearish Divergence: Price makes a higher high, but STC makes a lower high (especially near or above overbought) → potential downside reversal.
Divergences are most reliable when they occur at extreme levels.
🔹 Cycle Identification
The STC is specifically designed to identify cyclical turning points. By adjusting the cycle length, traders can adapt the indicator to different market rhythms (short‑term, medium‑term, or long‑term cycles).
🔹 Multiple Timeframe Analysis
Compare STC readings across timeframes to align trades with the larger trend. For example, a bullish signal on a lower timeframe carries more weight if the higher‑timeframe STC is also bullish (above oversold or rising).
🎯 Ideal For
Cycle Traders seeking to capitalize on recurring market rhythms.
Momentum Traders wanting a clean, filtered view of trend strength.
Mean Reversion Traders looking for overbought/oversold opportunities.
Swing Traders capturing medium‑term trend shifts.
System Developers needing a bounded, reliable oscillator for strategy building.
Traders familiar with MACD & Stochastic who appreciate a hybrid approach.
📌 Key Takeaways
Bounded Range: STC oscillates between 0 and 100, providing clear overbought/oversold levels at 75/25 (user‑adjustable).
Noise Reduction: The double stochastic smoothing filters out market noise, making signals more reliable than raw MACD or single stochastic.
Customizable Smoothing: Twelve moving average types allow fine‑tuning for any trading style.
Comprehensive Visualization: Color themes, gradient fills, candle coloring, and live labels offer immediate market insight.
Signal Clarity: Triangle markers appear only at significant crossovers, reducing visual clutter.
Divergence Capability: Excellent for spotting both regular and hidden divergences.
Alert‑Ready: Built‑in alerts for long/short signals.
⚠️ Important Notes
The default parameters (12, 26, 28) are inspired by the classic MACD and stochastic settings, but they can be adjusted to suit different timeframes and market conditions. Shorter cycle lengths make the indicator more responsive but may increase false signals; longer lengths provide smoother readings. The overbought/oversold levels (75/25) are guidelines – in strongly trending markets, STC can remain in extreme zones for extended periods. Divergences are most reliable when they occur at extreme readings. Always combine with proper risk management and additional confirmation for best results.
Disclaimer: This indicator is provided for educational and informational purposes only. Past performance is not indicative of future results. Always conduct thorough testing and align with your risk management strategy before live deployment.
版本注释
Color Mode – Added 'Heat' option ([#ff0000, #87cefb]).Dynamic Fill Transparency – Calculates Momentum and Norm_Momentum to set a variable transparency (Fill_Transp) for the overbought/oversold fills, replacing the fixed 0/100 values.
Gradient Candle Colors – Computes a normalized and uses color.from_gradient() to color candles with a smooth transition between down and up colors.
Persistent Trend State – Introduces Trend_ (1 for bull, -1 for bear) that holds the trend direction, used in:
The third fill() (now based on Trend_ instead of a direct.
bgcolor() (now uses Trend_ instead of isBull_/isBear_).
The table and label (display and color based on Trend_).
Label Color – Simplified to use Trend_ colors without transparency.
开源脚本
秉承TradingView的精神,该脚本的作者将其开源,以便交易者可以查看和验证其功能。向作者致敬!您可以免费使用该脚本,但请记住,重新发布代码须遵守我们的网站规则。
免责声明
这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。
开源脚本
秉承TradingView的精神,该脚本的作者将其开源,以便交易者可以查看和验证其功能。向作者致敬!您可以免费使用该脚本,但请记住,重新发布代码须遵守我们的网站规则。
免责声明
这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。