Trend Score Indicator for ThinkorSwim

BenTen

BenTen

Administrative
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.




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);
 
T

Tanp82

New member
2019 Donor
Real nice @BenTen I love simple, added labels and commented out the plot and color bars. Thank You for posting.
did you turn this one into labels? if so can you share it please? thanks
 
T

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
 
BenTen

BenTen

Administrative
Staff
VIP
@tomsk Thank you, Tom. That’s another way to do it. 👍🏻
 
T

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:
BenTen

BenTen

Administrative
Staff
VIP
@tomsk Well done. I’m not familiar with fold but your code was a good introduction for me. :D
 
T

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.
 
M

mini

Member
@mc01439 Hi, what indicator is the red zone and the green zone? Do you mind to share the link of the entire chart?
 
mc01439

mc01439

Well-known member
2019 Donor
VIP
@mc01439 Hi, what indicator is the red zone and the green zone? Do you mind to share the link of the entire chart?
@mini - That was a test chart - will go back and see if I can locate.
 
J

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.)
 

Similar threads

Top