Indicator · Pine Script v4 · Own pane

Schaff Trend Cycle

by everget

This indicator plots the Schaff Trend Cycle in a separate pane.

View on GitHub

GitHub stars948on the repository
Pine versionv4older, still runs
Lines of code56
Settings9inputs
LicenceGPL-3.0
Last update10 days ago18 Oct 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

56 lines of Pine Script v4 from oscillators/stc_schaff_trend_cycle.pine, published under GPL-3.0. Keep the author's credit and licence lines when you reuse it.

stc_schaff_trend_cycle.pine
//@version=4
// Copyright (c) 2018-present, Alex Orekhov (everget)
// Schaff Trend Cycle script may be freely distributed under the terms of GPL-3.0 license.
study("Schaff Trend Cycle", shorttitle="STC")

fastLength = input(title="MACD Fast Length", type=input.integer, defval=23)
slowLength = input(title="MACD Slow Length", type=input.integer, defval=50)
cycleLength = input(title="Cycle Length", type=input.integer, defval=10)
d1Length = input(title="1st %D Length", type=input.integer, defval=3)
d2Length = input(title="2nd %D Length", type=input.integer, defval=3)
src = input(title="Source", type=input.source, defval=close)
upper = input(title="Upper Band", type=input.integer, defval=75)
lower = input(title="Lower Band", type=input.integer, defval=25)
highlightBreakouts = input(title="Highlight Breakouts ?", type=input.bool, defval=true)

macd = ema(src, fastLength) - ema(src, slowLength)
k = nz(fixnan(stoch(macd, macd, macd, cycleLength)))
d = ema(k, d1Length)
kd = nz(fixnan(stoch(d, d, d, cycleLength)))
stc = ema(kd, d2Length)
stc := max(min(stc, 100), 0)

stcColor1 = stc > stc[1] ? color.green : color.red
stcColor2 = stc > upper ? color.green : stc <= lower ? color.red : color.orange

stcColor = highlightBreakouts ? stcColor2 : stcColor1
stcPlot = plot(stc, title="STC", color=stcColor, transp=0)

upperLevel = plot(upper, title="Upper", color=color.gray)
hline(50, title="Middle", linestyle=hline.style_dotted)
lowerLevel = plot(lower, title="Lower", color=color.gray)

fill(upperLevel, lowerLevel, title="Middle Zone", color=#f9cb9c, transp=90)

upperFillColor = stc > upper and highlightBreakouts ? color.green : na
lowerFillColor = stc < lower and highlightBreakouts ? color.red : na

fill(upperLevel, stcPlot, color=upperFillColor, transp=80)
fill(lowerLevel, stcPlot, color=lowerFillColor, transp=80)

buySignal = crossover(stc, lower)
sellSignal = crossunder(stc, upper)
upperCrossover = crossover(stc, upper)
upperCrossunder = crossunder(stc, upper)
lowerCrossover = crossover(stc, lower)
lowerCrossunder = crossunder(stc, lower)

plotshape(upperCrossunder ? upper : na, title="Sell Signal", location=location.absolute, style=shape.circle, size=size.tiny, color=color.red, transp=0)
plotshape(lowerCrossover ? lower : na, title="Buy Signal", location=location.absolute, style=shape.circle, size=size.tiny, color=color.green, transp=0)

alertcondition(buySignal, title="Alert: Buy", message="STC: Buy!\nSymbol: {{exchange}}:{{ticker}}\nPrice: {{close}}")
alertcondition(sellSignal, title="Alert: Sell", message="STC: Sell!\nSymbol: {{exchange}}:{{ticker}}\nPrice: {{close}}")
alertcondition(upperCrossover, title="Alert: Upper Band Crossover", message="STC: Upper Band Crossover!\nSymbol: {{exchange}}:{{ticker}}\nPrice: {{close}}")
alertcondition(upperCrossunder, title="Alert: Upper Band Crossunder", message="STC: Upper Band Crossunder!\nSymbol: {{exchange}}:{{ticker}}\nPrice: {{close}}")
alertcondition(lowerCrossover, title="Alert: Lower Band Crossover", message="STC: Lower Band Crossover!\nSymbol: {{exchange}}:{{ticker}}\nPrice: {{close}}")
alertcondition(lowerCrossunder, title="Alert: Lower Band Crossunder", message="STC: Lower Band Crossunder!\nSymbol: {{exchange}}:{{ticker}}\nPrice: {{close}}")

Overview

Schaff Trend Cycle subtracts a slow exponential moving average from a fast one, applies a stochastic cycle twice, and smooths each result to form a 0–100 oscillator. Line color follows the slope, or the upper and lower bands when breakout highlighting is on. Circles mark a cross above the lower band and a cross below the upper band, and alerts fire on those and other band crosses. Lengths, source, and band levels are adjustable. It is an indicator only and does not manage trades.

Details

Published by

everget on GitHub

Type

Indicator, Pine Script v4

Draws

Separate pane below the chart

Category

Oscillators & momentum, Trend, Breakout

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Topics

pinepinescripttechnical-indicatorsindicatorsoscillatorbandsaveragetradingviewindicatormoving-average

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
MACD Fast Lengthint23fastLength
MACD Slow Lengthint50slowLength
Cycle Lengthint10cycleLength
1st %D Lengthint3d1Length
2nd %D Lengthint3d2Length
Sourcesourceclosesrc
Upper Bandint75upper
Lower Bandint25lower
Highlight Breakouts ?booltruehighlightBreakouts
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.

Similar Pine Scripts

MACD Breakout

by jerryinyang
5 stars

Calculates multi-timeframe Moving Average Convergence Divergence (MACD) alongside a Money Flow filter to identify potential market breakouts. It evaluates higher-timeframe MACD calculations using exponential or simple moving averages combined with Money Flow o

Indicator v4 TrendOscillators & momentum Repaints
Updated 2 years ago · None stated GitHub repository of MACD Breakout

Target Radar

by eddiebelaval
7 stars

Target Radar is a multi-factor forecasting indicator that plots projection bands, forward boxes, and dynamic target zones directly on the main price chart. It calculates a forecast score by combining z-scores for trend, momentum, volume pressure, and volatilit

Indicator v5 TrendOscillators & momentum
Updated 3 months ago · None stated GitHub repository of Target Radar

Edge 59

by subos2008
6 stars

This indicator identifies trend-following breakout opportunities by combining directional movement, trend channels, and multi-period price extremes. It calculates an ADX-colored weighted moving average, a linear regression trend filter based on a volatility ch

Indicator v5 TrendBreakout
Updated 2 years ago · Custom licence GitHub repository of Edge 59

Beep Boop

by magic8bot
409 stars

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

Indicator v4 Oscillators & momentumTrend
Updated 3 years ago · MIT GitHub repository of Beep Boop

[RS]Standardized Trend Map

by ricardosantos79
261 stars

Standardized Trend Map calculates series momentum relative to active price range across 40 distinct lookback periods ranging from 2 to 80 bars on an exponential moving average source. Each standardized calculation rounds to an integer values of -1, 0, or 1 to

Indicator v4 TrendOscillators & momentum
Updated 4 years ago · None stated GitHub repository of [RS]Standardized Trend Map

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers