Schaff Trend Cycle Scan, Watchlist, Label for ThinkOrSwim

borntostun

New member
Lifetime
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!
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Here is another example, a poster requested a Schaff watchlist
7Azu4F4.png

Qk15YPk.png

Chart & Labels
Ruby:
# 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"));
# ########################################################
Watchlist #1:
Ruby:
# 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));
# ########################################################
Watchlist #2
Ruby:
# 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));
# ########################################################
 
@borntostun

Color ranges wouldn't really be appropriate. One of the attributes of the Schaff Cycle is that it is either Up or Down, doesn't spend much time in-between...

So, I was not able to code 'exactly' what you requested due to the above. But you will find a Schaff Cycle watch list in the below link. Should be enough for you to work with to get the end product that you are looking for.
https://usethinkscript.com/threads/adding-color-to-plots-and-labels.6845/#post-66596
HTH
 
Last edited:
Thanks VERY much. Worked great, but how do I go about getting that second Schaff WL column that you provided in your example . . . the one with the descriptive labels? Thanks!
 
I didn't think you would be interested in that; I only created it to display the definition of the colors.
I will add the 2nd Schaff watch list to the below link but Caution: the TOS platform will only display 1,100 - 1,500 Custom Watch list Fields
and then it will vomit the dreaded 'custom expression subscription limit exceeded' throughout all watch lists.
https://usethinkscript.com/threads/adding-color-to-plots-and-labels.6845/#post-66596
 
@Thomas I look for dip trades on the daily and 4hr charts. When I come up w/ a likely candidate, I use the Schaff to time my entry on the lower aggregations.
 
I was really wishing for a watch list column for Schaff, and was so happy to find what I thought was it in #post-66596 -- it looks exactly what I was looking for, but... I've never created a watch list column and I'm having trouble. I can't figure out which part of the code I should be using. I either get error messages, or when I finally seem to get it right, the watch list column gets stuck on "loading" -- can you show me how the code should look? Thanks so much!
 
@NatalieHollis
There was a major update to the platform over the weekend. Weekend maintenance tends to make watchlists perform poorly
The watchlist columns are working fine for me. If you are still having issues come Monday morning, you could try loading them using shared links.

To load these shared links, follow these instructions --> Easiest way to load shared links
Shared Link Schaff Trend Cycle WatchList #1 = http://tos.mx/izV9n5i
Shared Link Schaff Trend Cycle WatchList #2 = http://tos.mx/w4GZ9nI
Screenshot (29).png
 
@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
To Change the colors in a chart:
1. Click on the Edit Setting Gear​
2. Scroll to the bottom​
3. Change Global Colors​
Screenshot (260).png
 
Modify Color In A Watchlist Column:
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));
Watchlist column fields color can be assigned using ToS standard colors:
https://tlc.thinkorswim.com/center/reference/thinkScript/Constants/Color
Or color can be created with the CreateColor function: CreateColor (200, 125, 255) .
Screenshot (261).png


The choices are endless.
Try changing each color in your watchlist, you will quickly figure out which line does what.
 
@MerryDay Im trying to color the Schaff green if its above 75 and red if its below 25, anything in the middle has no color, Im having trouble getting it this way any way you could help me?
 
This is another version of Schaff Trend Cycle, Enjoy
Link: https://www.tradingview.com/script/UkWZRgLG-Schaff-Trend-Cycle/

Go here to see the Upper indicator
https://usethinkscript.com/threads/break-keltner-bands-bkb-for-thinkorswim.11220/
The blue bars indicate the time the price is crossing the 20ema and the points just indicate the direction of the price up or down.

Photo
13611[/ATTACH]']
gLlws6V.png


script
Code:
# 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);
 

Attachments

  • gLlws6V.png
    gLlws6V.png
    201.6 KB · Views: 110
Last edited by a moderator:
@JP782 this is DOA, It's already exists, TOS default. Look for SchaffTrendCycle, if you are interested in custom parameters, you can change the input.
 
@SuryaKiranC, great - thanks I found SchaffTrendCycle under Studies -> Add Study -> Lower Studies (Other).
How would I use this study in a scan? I am looking to scan for stocks where the SchaffTrendCycle flagged a buy signal on the previous bar.
 
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

Code:
# 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);
 
Last edited by a moderator:
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
You can play with this script to make it do what your want:
https://usethinkscript.com/threads/...hlist-label-for-thinkorswim.10310/#post-96009
 
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]']
gLlws6V.png

@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!
 
@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!
Go here to see the Upper indicator
https://usethinkscript.com/threads/break-keltner-bands-bkb-for-thinkorswim.11220/

The blue bars indicate the time the price is crossing the 20ema and the points just indicate the direction of the price up or down.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
445 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

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.

How do I get started?

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.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top