Has anyone ever come across a Schaff Trend Cycle watchlist column? Something color-coded gradient for leaving the 100/0 levels and then crossing the threshold levels (green/red) would be helpful to see real-time. Thanks!
# TOS Schaff Cycle
declare lower ;
input show_label = yes ;
input OB = 80 ;
input OS = 20 ;
# ########################################################
#Using GlobalColors makes the colors modifiable
DefineGlobalColor("maxxed", CreateColor(0, 70, 30)) ;
DefineGlobalColor("rising", CreateColor(0, 165, 0)) ;
DefineGlobalColor("bear", CreateColor(225, 0, 0)) ;
DefineGlobalColor("begin", CreateColor(50, 200, 255)) ;
DefineGlobalColor("zero", CreateColor (200, 125, 255)) ;
# ########################################################
Plot Schaff = SchaffTrendCycle()."STC" ;
# ########################################################
#Schaff> Schaff[1] this statement is saying if the current candle is greater than the previous candle
#that is what [1] denotes. Thus defining uptick. The same is then done for downticks.
Schaff.AssignValueColor(
if Schaff> OB then GlobalColor("maxxed") else
if Schaff< OS and Schaff< Schaff[1] then GlobalColor("zero") else
if Schaff< OS and Schaff> Schaff[1] then GlobalColor("begin") else
if Schaff> Schaff[1] then GlobalColor("rising")
else GlobalColor("bear"));
Schaff.SetLineWeight(3);
# ########################################################
plot OverBought = OB;
plot OverSold = OS;
plot UpArrow = if Schaff crosses above OverSold then OverSold else Double.NaN;
plot DownArrow = if Schaff crosses below OverBought then OverBought else Double.NaN;
DefineGlobalColor("OBcolor", CreateColor(171, 171, 225)) ;
DefineGlobalColor("OScolor", CreateColor(220, 220, 128)) ;
OverBought.SetDefaultColor(GlobalColor("OBcolor"));
OverSold.SetDefaultColor(GlobalColor("OScolor"));
UpArrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
DownArrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
UpArrow.SetDefaultColor(color.dark_green);
DownArrow.SetDefaultColor(color.dark_red);
# ########################################################
# The same logic that was used in coloring the plot can be used in labels
AddLabel(show_label,
if Schaff> OB then "Schaff maxxed" else
if Schaff< OS and Schaff< Schaff[1] then "Schaff bottomed" else
if Schaff< OS and Schaff> Schaff[1] then "Schaff Trend BEGIN" else
if Schaff> Schaff[1] then "Schaff rising " +round(Schaff,2)
else "Schaff falling " +round(Schaff,2) ,
if Schaff> OB then GlobalColor("maxxed") else
if Schaff< OS and Schaff< Schaff[1] then GlobalColor("zero") else
if Schaff< OS and Schaff> Schaff[1] then GlobalColor("begin") else
if Schaff> Schaff[1] then GlobalColor("rising")
else GlobalColor("bear"));
AddCloud(if Schaff >= OB then Schaff else Double.NaN, OB,
GlobalColor("maxxed"), GlobalColor("maxxed"));
AddCloud(if Schaff <= OS then OS else Double.NaN, Schaff,
GlobalColor("zero"), GlobalColor("zero"));
# ########################################################
# TOS Schaff Cycle
input OB = 80 ;
input OS = 20 ;
# ########################################################
Plot Schaff = SchaffTrendCycle()."STC" ;
# ########################################################
AssignBackgroundColor(
if Schaff> OB then color.dark_green else
if Schaff< OS and Schaff>=Schaff[1] then CreateColor(50, 200, 255) else
if Schaff< OS then CreateColor (200, 125, 255) else
if Schaff> Schaff[1] then CreateColor(0, 165, 0)
else CreateColor(225, 0, 0));
# ########################################################
# TOS Schaff Cycle
input OB = 80 ;
input OS = 20 ;
# ########################################################
plot Schaff = SchaffTrendCycle()."STC" ;
# ########################################################
AddLabel(yes,
if Schaff> OB then "maxxed" else
if Schaff< OS and Schaff< Schaff[1] then "bottomed" else
if Schaff< OS and Schaff> Schaff[1] then "Trend BEGIN" else
if Schaff> Schaff[1] then "rising "
else "falling" );
# ########################################################
AssignBackgroundColor(
if Schaff> OB then color.dark_green else
if Schaff< OS and Schaff>=Schaff[1] then CreateColor(50, 200, 255) else
if Schaff< OS then CreateColor (200, 125, 255) else
if Schaff> Schaff[1] then CreateColor(0, 165, 0)
else CreateColor(225, 0, 0));
# ########################################################
@MerryDay how can i change the colors to different ones? for example wanting to change the bottom or anything below 80 to red instead of purple and vise versa
Watchlist column fields color can be assigned using ToS standard colors:AddLabel(yes,
if Schaff> OB then "maxxed" else
if Schaff< OS and Schaff< Schaff[1] then "bottomed" else
if Schaff< OS and Schaff> Schaff[1] then "Trend BEGIN" else
if Schaff> Schaff[1] then "rising "
else "falling" );
# ########################################################
AssignBackgroundColor(
if Schaff> OB then color.dark_green else
if Schaff< OS and Schaff>=Schaff[1] then CreateColor(50, 200, 255) else
if Schaff< OS then CreateColor (200, 125, 255) else
if Schaff> Schaff[1] then CreateColor(0, 165, 0)
else CreateColor(225, 0, 0));
# Copyright 2018-present, Alex Orekhov (everget)
# Schaff Trend Cycle script may be freely distributed under the MIT license.
# Original Link: https://www.tradingview.com/script/UkWZRgLG-Schaff-Trend-Cycle/
# Schaff Trend Cycle converted to TOS by mbarcala
declare lower;
input fastLength = 20;
input slowLength = 50;
input cycleLength = 6;
input d1Length = 3;
input d2Length = 3;
def macd = ExpAverage(close, fastLength) - ExpAverage(close, slowLength);
def k = 100 * (MACD - lowest(MACD, cycleLength)) / (highest(MACD, cycleLength) - lowest(MACD, cycleLength));
def d = ExpAverage(k, d1Length);
def kd = 100 * (d - lowest(d, cycleLength)) / (highest(d, cycleLength) - lowest(d, cycleLength));
plot stc = ExpAverage(kd, d2Length);
stc.AssignValueColor(if stc > stc[1] then color.green else color.red);
plot cline = 50;
cline.SetDefaultColor(Color.GRAY);
cline.SetStyle(Curve.SHORT_DASH);
plot upper = 75;
upper.SetDefaultColor(Color.GRAY);
plot lower = 25;
lower.SetDefaultColor(Color.GRAY);
AddCloud(stc, upper, Color.GREEN, CreateColor(27,27,27));
AddCloud(lower, stc, Color.RED, CreateColor(27,27,27));
plot upperCr = if stc crosses below upper then upper else Double.NaN;
upperCr.SetPaintingStrategy(PaintingStrategy.POINTS);
upperCr.SetDefaultColor(Color.RED);
upperCr.SetLineWeight(5);
plot lowerCr = if stc crosses above lower then lower else Double.NaN;
lowerCr.SetPaintingStrategy(PaintingStrategy.POINTS);
lowerCr.SetDefaultColor(Color.GREEN);
lowerCr.SetLineWeight(5);
# TD Ameritrade IP Company, Inc. (c) 2015-2020
#SchaffTrendCycle
declare upper;
input fastLength = 9;
input slowLength = 18;
input KPeriod = 9;
input DPeriod = 3;
input over_bought = 80;
input over_sold = 20;
input neutral_zone = 50;
input averageType = AverageType.EXPONENTIAL;
def macd = MovingAverage(averageType, close, fastLength) - MovingAverage(averageType, close, slowLength);
def fastK1 = FastKCustom(macd, KPeriod);
def fastD1 = MovingAverage(averageType, fastK1, DPeriod);
def fastK2 = FastKCustom(fastD1, KPeriod);
def STC = MovingAverage(averageType, fastK2, DPeriod);
def OverBought = over_bought;
def OverSold = over_sold;
def Neutral = neutral_zone;
def arrow_plots = high - low;
def plothigh = high + arrow_plots * 0.50;
def plotlow = low - arrow_plots * 0.50;
plot arrowUP = if STC crosses above OverSold then plotlow else Double.NaN;
arrowUP.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
arrowUP.SetLineWeight(3);
arrowUP.SetDefaultColor(Color.ORANGE);
plot arrowdown = if STC crosses below OverBought then plothigh else Double.NaN;
arrowdown.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
arrowdown.SetLineWeight(3);
arrowdown.SetDefaultColor(Color.BLUE);
def cycleup = STC > Over_Sold;
def cycledown = STC < over_Bought;
AddLabel( cycleup, "Cycle Up", color.orange);
AddLabel( cycledown, "Cycle Down", color.blue);
Alert(arrowUP, "Buy Signal", Alert.BAR, Sound.Chimes);
Alert(arrowdown, "Sell Signal", Alert.BAR, Sound.Bell);
You can play with this script to make it do what your want:Hi There forum,
I need help/assistance with the addlabel code in the below script. Currently the addlabel does not change the way I expect/wish. When the STC falls below 80 from above the addlabel does not change to reflect the condition(i.e. Cycle Down), what it does is that it shows Cycle Up till it falls below 20, and then it shows two labels "Cycle Up" & "Cycle Down". My intent is to have a label that shows "Cycle Down" when the STC crosses below from above 80 and changes to "Cycle Up" when STC crosses above from below 20. Thanks in advance for your time.
-JP
This is another version of Schaff Trend Cycle, Enjoy
Link: https://www.tradingview.com/script/UkWZRgLG-Schaff-Trend-Cycle/
Photo
https%3A//i.imgur.com/gLlws6V.png[/img]']
Go here to see the Upper indicator@mbarcala - would you be able to post the code for the upper study?
Appears to be a Keltner channel.
Not sure about the turning points and blue bars. At first glance I thought these were triggered from the Schaff indicator below but they do not match.
Looking forward to seeing the code.
Many Thanks!
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
Start a new thread and receive assistance from our community.
useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.
We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.
If you are new, or just looking for guidance, here are some helpful links to get you started.