Indicator · Pine Script v5 · Own pane

Schaff Trend Cycle

by goki75

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.

View on GitHub

GitHub stars1on the repository
Pine versionv5runs as is
Lines of code66
Settings7inputs
LicenceNone statedfile: MPL-2.0
Last update3 years ago17 Sep 2023

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

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.

Details

Published by

goki75 on GitHub

Type

Indicator, Pine Script v5

Draws

Separate pane below the chart

Category

Trend, Moving averages

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.

Settings

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

SettingTypeDefaultVariable
Lengthint10length
Fast Lengthint23fastLength
Slow Lengthint50slowLength
smoothingFactorfloat0.5smoothingFactor
Show OverBought/OverSoldbooltrueShowZones
Over Boughtint25LowHL
Over Soldint75HiHL
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

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
218 stars

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

Indicator v6 Screeners & dashboardsTrend
Updated 3 months ago · None stated GitHub repository of Multi-Timeframe Analysis Suite

KamaFama

by Mastaaa1987
141 stars

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

Indicator v6 Moving averagesOscillators & momentum
Updated 6 weeks ago · MIT GitHub repository of KamaFama

MultiIndicator

by capissimo
114 stars

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

Indicator v4 Oscillators & momentumTrend
Updated 1 year ago · None stated GitHub repository of MultiIndicator
99 stars

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

Indicator v6 TrendMoving averages
Updated 4 weeks ago · Apache-2.0 GitHub repository of Archer Moving Averages Trends (AMAT)

Colored fill

by be-thomas
65 stars

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

Indicator v4 Moving averagesTrend
Updated 4 days ago · GPL-3.0 GitHub repository of Colored fill

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