Trend Score Indicator for ThinkorSwim

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

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

Similar threads

Top