Schaff Trend Cycle is a trend following indicator that computes a smoothed version of the MACD difference between fast and slow EMAs applied to close prices.
1Copy the scriptPress Copy script above, or the copy button on the code below.
2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.
Source Code
66 lines of Pine Script v5 from stc.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.
stc.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// @version=5
// Schaff Trend Cycle Indicator
indicator(title='Schaff Trend Cycle', shorttitle='STC', overlay=false)
var GRP1 = "Input Parameters"
var GRP2 = "Over Bought/Sold Zones"
length = input(10, 'Length',group=GRP1)
fastLength = input(23, 'Fast Length',group=GRP1)
slowLength = input(50, 'Slow Length',group=GRP1)
calculateMADiff(src,fastLength, slowLength) =>
fastMA = ta.ema(src,fastLength)
slowMA = ta.ema(src,slowLength)
MADiff = fastMA - slowMA
MADiff
calculateSTC(length, fastLength, slowLength) =>
smoothingFactor = input(0.5,group=GRP1)
var stcPercent = 0.0
var stcValue = 0.0
var stcPer =0.0
var STC= 0.0
MADiff = calculateMADiff(close,fastLength,slowLength)
lowestSTC = ta.lowest(MADiff, length)
highestSTC = ta.highest(MADiff, length) - lowestSTC
stcPercent := highestSTC > 0 ? (MADiff - lowestSTC) / highestSTC * 100 : nz(stcPercent[1])
stcValue := na(stcValue[1]) ? stcPercent : stcValue[1] + smoothingFactor * (stcPercent - stcValue[1])
lowestValue = ta.lowest(stcValue, length)
highestValue = ta.highest(stcValue, length) - lowestValue
stcPer := highestValue > 0 ? (stcValue - lowestValue) / highestValue * 100 : nz(stcPer[1])
STC:= na(STC[1]) ? stcPer: STC[1] + smoothingFactor * (stcPer - STC[1])
STC
stcline = calculateSTC(length, fastLength, slowLength)
stcColor = (stcline > stcline[1] ) ? color.new(#03ec0b, 20) : color.new(#f81b1b, 20)
var float HighClose = na
var float LowClose=na
var T=0.0
var R=0.0
HighClose := T == 0 ? close : ta.highest(close,T)
LowClose := R == 0 ? close : ta.highest(close,R)
rg=HighClose-LowClose
divid=100/rg
stcline2=stcline*divid+LowClose
plot(stcline2, color=stcColor, title='STC', linewidth=2)
ShowZones=input.bool(true, "Show OverBought/OverSold", inline = "01",group=GRP2)
var clrtop=color.new(#1e65ff, 20)
var clrbot=color.new(#ff2929, 27)
var fillcolor=color.new(#919cc4, 50)
if (ShowZones==false)
clrtop:=color.new(#6645f8, 100)
clrbot:=color.new(#ff2929, 100)
fillcolor:=color.new(#7d91db, 100)
LowHL=input(25,"Over Bought",group=GRP2)
HiHL=input(75,"Over Sold",group=GRP2)
upperLevel = plot(LowHL, title="OverBought",color=clrbot)
lowerLevel = plot(HiHL, title="OverSold",color=clrtop)
fill(upperLevel, lowerLevel,title="Area OverBought/Sell Zone", color=fillcolor)
Overview
Schaff Trend Cycle normalizes this difference over a specified length, applies iterative smoothing, and plots the resulting STC line in a separate pane. Green color indicates rising trend while red signals falling trend. Users adjust cycle length, fast length, slow length, and smoothing factor. Overbought and oversold zones can be shown at custom levels and are filled with color. The indicator draws only on the price chart pane and requires no additional exit rules beyond color changes.
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
Length
int
10
length
Fast Length
int
23
fastLength
Slow Length
int
50
slowLength
smoothingFactor
float
0.5
smoothingFactor
Show OverBought/OverSold
bool
true
ShowZones
Over Bought
int
25
LowHL
Over Sold
int
75
HiHL
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.
This indicator calculates a modified MACD oscillator and signal line alongside a trend EMA filter, plotting the output as a stylized column histogram in a separate pane. Instead of plotting true MACD distance, it quantifies positive and negative histogram mome
Multi-Timeframe Analysis Suite calculates trend direction and momentum conditions across five user-selected timeframes using moving averages, RSI, and Stochastic oscillators. It evaluates moving average slope and oscillator levels to compute trend alignment, m
KamaFama is an indicator that translates a Freqtrade trading strategy into Pine Script for visualization. It combines Kaufman Adaptive Moving Average (KAMA), MAMA/FAMA calculations derived via Hilbert Transform, Williams %R, and correlation trend filters to ev
MultiIndicator combines multiple technical indicators into a single separate pane to save chart space. It calculates and displays market regime detection based on ordinary least squares regression, a Holt exponential smoothing crossover, normalized RSI, ADX, a
Calculates the Archer Moving Averages Trends (AMAT) indicator by comparing fast and slow Exponential Moving Averages (EMAs) alongside their slope directions. A bullish trend (+1) is identified when the fast EMA exceeds the slow EMA with both rising, while a be
This indicator plots two simple moving averages of close, one over five bars and one over twenty bars, in a separate pane. It shades the area between the two plots green when the shorter average is above the longer average and red when it is below. There are n