Basic Scoring System

msloane23423

New member
Hi all, blown away by this resource and that there are so many pieces of code. Great work all. I am a relatively simple trader and like everyone else I use a few key metrics to determine trends in the market on both minute scale and longer scale.

What I am trying to do is extremely simple for any basic level coder so looking for some help.

I am looking to create a lower chart, that encapsulates one line, which represents a summation of many evaluations, one based on momentum, one based on price.

For example, if the prices is ABOVE the SMA 20, that would be 1. If the SMA 20 is greater than the last bar, that would be 1. Together this would score as 2.

How do i code that in thinkscript? If i get that snippet i can fold in the rest of my metrics... thank you all.

My guess on how to do thois was to declare lower, then declare variables for each metric.... var 1= PRice vs SMA20, var 2 = SMAvsXBarsAgo, etc...

then at the end plot the summation of all of those variables...

THank you...
 

BenTen

Administrative
Staff
VIP
Here is a really basic example.

Plot 1 every time the close is greater than 20 SMA.

Code:
declare lower;

input price = close;
input length = 20;
input displace= 0;

def SMA = Average(price[-displace], length);

plot score1 = if close > SMA then 1 else 0;
 

msloane23423

New member
What i tried to do now was add price vs the SMA 50... but instead of plotting the one line, i want to evaluate the if statement to be a 1 or 0.

then take all these if evaluations that are defined and add up those variables for the value to be plotted.

Code:
declare lower;

##SMA20PriceVariables
input price20 = close;
input length20 = 20;
input displace20 = 0;

##SMA50PriceVariables
input price50 = close;
input length50 = 50;
input displace50 = 0;

def SMAPrice20 = Average(price20[-displace20], length20);
def SMAPrice50 = Average(price50[-displace50], length50);

def  ScoreSMAPrice20 = if close > SMAPrice20 then 1 else 0;
def  ScoreSMAPrice50 = if close > SMAPrice50 then 1 else 0;

plot = SUM(ScoreSMAPrice20+ScoreSMAPrice50)
 

msloane23423

New member
Ok i figured this part out...

Here is my cleaned up elemental code...

I will now use displace to look back X bars right so I can compare one moment in time to another?

Code:
declare lower;

##SMA20PriceVariables
input price20 = close;
input length20 = 20;
input displace20 = 0;

##SMA50PriceVariables
input price50 = close;
input length50 = 50;
input displace50 = 0;

def SMAPrice20 = Average(price20[-displace20], length20);
def SMAPrice50 = Average(price50[-displace50], length50);

def  ScoreSMAPrice20 = if close > SMAPrice20 then 1 else 0;
def  ScoreSMAPrice50 = if close > SMAPrice50 then 1 else 0;

plot FinalScore =  (ScoreSMAPrice20+ScoreSMAPrice50);
 

XeoNoX

Well-known member
VIP
Can also use the sum feature, heres an example:

Code:
#defining places in which we have greater than [x] SDev of volume
def SCAN = RelativeVolumeStDev(50).RelVol >= 3;

#scanning to see where we have greater than 3 SDev+ volume, on 3 out of the past 5 days
plot FinalScore = Sum(SCAN, 5) >= 3;

keywords: adding summing summed added tally tallying
 
Last edited:

codydog

Active member
Back in the day, I used to add 'em up, as you're suggesting and ended up with >800 lines of script, then color coded, as in assignpricecolor, then whittled 'em back down to see what worked for me and what didnt. Its really a good exercise to find out what works, whats touted and what is simple a waste.
 

msloane23423

New member
Thanks for everyone's input.. @codydog, I agree 100%. There is so much noise you need to focus on basics which is what I ended up doing with my entire strategy. This code is extremely basic but it does, based on what I am looking at, distill everything and tell me which way the wind is blowing. Not sure if this will be of any use to anyone here but I actually used it today and actually it DID keep me from making some dumb trades. Basically when the line is trending at 6 (max value based on variables) and riding upper boundary you know it's bull trend but when it starts to waffle a bit its losing steam, so that prevented me from taking longs. YMMV and I plan to add more to this as time goes on but its been a good exercise overall. The next thing I want to add is distance from the closest outer Bollinger band as I have noticed failed reversals as the band widens and price does not.

Code:
declare lower;

##SMA20PriceVariables
input price20 = close;
input length20 = 20;
input displace20 = 1;

##SMA50PriceVariables
input price50 = close;
input length50 = 50;
input displace50 = 1;

def SMAPrice20 = Average(price20, length20);
def SMAPrice50 = Average(price50, length50);

def SMAMomo20 = Average(price20[+displace20], length20);
def SMAMomo50 = Average(price50[+displace50], length50);

##Price Evaluations
def ScoreSMAPrice20 = if close > SMAPrice20 then 1 else 0;
def ScoreSMAPrice50 = if close > SMAPrice50 then 1 else 0;
def ScoreVWAPPrice = if close >vwap(period = AggregationPeriod.DAY) then 1 else 0;

##MomentumEvaluations
def ScoreRSIMomo = if RSI() > 50 then 1 else 0;
def ScoreSMAMomo20 = if SMAPrice20 > SMAMomo20 then 1 else 0;
def ScoreSMAMomo50 = if SMAPrice50 > SMAMomo50 then 1 else 0;

plot TotalScore =
(
+ScoreSMAPrice20
+ScoreSMAPrice50
+ScoreVWAPPrice
+ScoreRSIMomo
+ScoreSMAMomo20
+ScoreSMAMomo50
);

plot neutraline = 3;
 

MerryDay

Well-known member
VIP
@msloane23423 scoring systems sometimes benefit from weighted scores, for instance, some would consider a falling RSI or falling CCI a showstopper so might give it a 2 or even a 3. Just a thought...
 
Last edited:

Similar threads

Top