Trend Score Indicator for ThinkorSwim

BenTen

Administrative
Staff member
Staff
VIP
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);
 

tomsk

Well-known member
VIP
@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
 

tomsk

Well-known member
VIP
@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-known member
VIP
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.
 

jezzer47

Member
2019 Donor
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.)
 

Jonas99

Active member
VIP
@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!
 

ktp

New member
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.
 

owensan02

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

MerryDay

Administrative
Staff member
Staff
VIP
@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
 

owensan02

New member
@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"
 

MerryDay

Administrative
Staff member
Staff
VIP
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.
 

owensan02

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

Top