Trend Score Indicator for ThinkorSwim

BenTen

Administrative
Staff member
Staff
VIP
Lifetime
A simple indicator that tries to identify the current trend.
  • Red = bearish
  • Green = bullish
  • White = neutral
If you don't like either the paintbars or the lower study (histogram), you can always get rid of it by placing "#" in front of the function or delete it entirely from the code.

iKQqRdc.png

DjWo62Z.png


Code:
# Simple Trend Score
# Assembled by BenTen at useThinkScript.com
# Converted from https://www.tradingview.com/script/ViXoUfeL/

declare lower;

def TrendScore = if(close >= close[11], 1, -1) + if(close >= close[12], 1, -1) + if(close >= close[13], 1, -1) + if(close >= close[14], 1, -1) + if(close >= close[15], 1, -1) + if(close >= close[16], 1, -1) + if(close >= close[17], 1, -1) + if(close >= close[18], 1, -1) + if(close >= close[19], 1, -1) + if(close >= close[20], 1, -1);

def col1= TrendScore>5;
def col2= TrendScore<-5;

plot histogram = TrendScore;
histogram.assignValueColor(if col1 then Color.Green else if Col2 then Color.Red else Color.White);

assignPriceColor(if col1 then Color.Green else if Col2 then Color.Red else Color.White);
 

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

@BenTen Here is the study from post #1 updated to use fold rather than hard code multiple tests of different periods. The results are the same

Code:
# Simple Trend Score
# Assembled by BenTen at useThinkScript.com
# Modified by tomsk, 1.23.2020
# Converted from https://www.tradingview.com/script/ViXoUfeL/

declare lower;

def TrendScore = fold i = 11 to 21
                 with p
                 do p + if close >= GetValue(close, i) then 1 else if close < GetValue(close, i) then -1 else 0;
def col1 = TrendScore >  5;
def col2 = TrendScore < -5;

plot histogram = TrendScore;
histogram.assignValueColor(if col1 then Color.Green else if Col2 then Color.Red else Color.White);

assignPriceColor(if col1 then Color.Green else if Col2 then Color.Red else Color.White);
# End Simple Trend Score
 
@BenTen When I first looked at your code structure, it seemed that fold could do the same job and so I had a go with that. Initially I ran into boundary conditions and was unable to get the exact same value as yours. I reached out to some external resources, had a second pair of eyes look at this, made the corrections, tested it for correlated values with your version and they all match up now. A good learning experience that's for sure
 
Last edited:
@tomsk Well done. I’m not familiar with fold but your code was a good introduction for me. :D
 
Fold is actually quite a difficult concept to clear, at least for me. It does take quite a bit of experience and practice. I have written maybe about a dozen or so simple fold studies and still have a long way to go. There was actually a real good tutorial on fold() that ThinkScripter wrote years ago. I emailed him about 2 years ago and he mentioned he had since then taken it down from that site. Meanwhile we do what we can.
 
Any way we can get a mutli time frame version? Thanks for the script.

(imo for better use on TOS mobile just tap plot settings and change draw as to histogram.)
 
@BenTen Here is the study from post #1 updated to use fold rather than hard code multiple tests of different periods. The results are the same

Code:
# Simple Trend Score
# Assembled by BenTen at useThinkScript.com
# Modified by tomsk, 1.23.2020
# Converted from https://www.tradingview.com/script/ViXoUfeL/

declare lower;

def TrendScore = fold i = 11 to 21
                 with p
                 do p + if close >= GetValue(close, i) then 1 else if close < GetValue(close, i) then -1 else 0;
def col1 = TrendScore >  5;
def col2 = TrendScore < -5;

plot histogram = TrendScore;
histogram.assignValueColor(if col1 then Color.Green else if Col2 then Color.Red else Color.White);

assignPriceColor(if col1 then Color.Green else if Col2 then Color.Red else Color.White);
# End Simple Trend Score
Hi @tomsk thanks for all the good posts and I always learn something after reading them. I have a Swing HL study modified by you from Robert Payne's script that I am using. Is there a way to limit the arrows showing up everywhere on different time frames and cluttering the chart? Ideally, limit the arrows to the last 6? I am showing a chart here, thanks so much. Happy 4th July!
 
Hi @tomsk thanks for all the good posts and I always learn something after reading them. I have a Swing HL study modified by you from Robert Payne's script that I am using. Is there a way to limit the arrows showing up everywhere on different time frames and cluttering the chart? Ideally, limit the arrows to the last 6? I am showing a chart here, thanks so much. Happy 4th July!
Can you share you charts above? I like it and would like to try out the setup. Thanks.
 
Hello Ben, is there a way to turn this into a watchlist/scanner? Like if a stock turns from white to green on a daily chart then it shows up in the scanner? Thanks
 
@ownensan02 It 'should' work. Load the script into your watch list.
Ruby:
#Change this:
assignPriceColor(if col1 then Color.Green else if Col2 then Color.Red else Color.White);

#To this:
assignBackgroundColor(if col1 then Color.Green else if Col2 then Color.Red else Color.White);
I didn't test it. Let us know
 
@ownensan02 It 'should' work. Load the script into your watch list.
Ruby:
#Change this:
assignPriceColor(if col1 then Color.Green else if Col2 then Color.Red else Color.White);

#To this:
assignBackgroundColor(if col1 then Color.Green else if Col2 then Color.Red else Color.White);
I didn't test it. Let us know
Hello MerryDay, thank you for taking the time to do this. It seems its getting stuck on the "col1", "Col2", "col1" and "Col2"
 
Trend Score Indicator Watch List
GGCQ8No.png

Ruby:
# Simple Trend Score
# Assembled by BenTen at useThinkScript.com
# Converted from https://www.tradingview.com/script/ViXoUfeL/

declare lower;

plot TrendScore = if(close >= close[11], 1, -1) + if(close >= close[12], 1, -1) + if(close >= close[13], 1, -1) + if(close >= close[14], 1, -1) + if(close >= close[15], 1, -1) + if(close >= close[16], 1, -1) + if(close >= close[17], 1, -1) + if(close >= close[18], 1, -1) + if(close >= close[19], 1, -1) + if(close >= close[20], 1, -1);

def col1= TrendScore>5;
def col2= TrendScore<-5;

assignbackgroundColor(if col1 then Color.Green else if Col2 then Color.Red else Color.White);
Shared Link: http://tos.mx/3gYQnk9
Easiest way to load shared links

@owensan02 The script works in the watch list w/o errors. So I am thinking it is user error. Try loading the shared link if you are still having trouble.
 
Trend Score Indicator Watch List
GGCQ8No.png

Ruby:
# Simple Trend Score
# Assembled by BenTen at useThinkScript.com
# Converted from https://www.tradingview.com/script/ViXoUfeL/

declare lower;

plot TrendScore = if(close >= close[11], 1, -1) + if(close >= close[12], 1, -1) + if(close >= close[13], 1, -1) + if(close >= close[14], 1, -1) + if(close >= close[15], 1, -1) + if(close >= close[16], 1, -1) + if(close >= close[17], 1, -1) + if(close >= close[18], 1, -1) + if(close >= close[19], 1, -1) + if(close >= close[20], 1, -1);

def col1= TrendScore>5;
def col2= TrendScore<-5;

assignbackgroundColor(if col1 then Color.Green else if Col2 then Color.Red else Color.White);
Shared Link: http://tos.mx/3gYQnk9
Easiest way to load shared links

@owensan02 The script works in the watch list w/o errors. So I am thinking it is user error. Try loading the shared link if you are still having trouble.
Ok perfect, thank you so much!
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
476 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