• LIMITED TIME ONLY: Take $40 off VIP with code: BTD40.

Technical Rank (SCTR) Indicator for ThinkorSwim

Art

Member
I was looking at this SCTR indicator and it seems very interesting concept, here is more info https://www.investopedia.com/terms/s/stockcharts-technical-rank-sctr.asp https://school.stockcharts.com/doku.php?id=technical_indicators:sctr

Does anyone use something similar? What are your thoughts?

Code:
# SCTR
# DREWGRIFFITH15 (C) 2015

declare lower;

input SMA200 = 200;
input ROC125 = 125;
input SMA50 = 50;
input ROC20 = 20;
input PPO_HIST = 3;
input RSI = 14;
input LT_WEIGHT = .30;
input MD_WEIGHT = .15;
input SH_WEIGHT = .05;
input SR_LENGTH = 40;

# THIS STUDY IS A REPLICATION OF STOCKCHARTS TECHNICAL RANKING
# http://stockcharts.com/school/doku.php?id=chart_school:technical_indicators:sctr

#Long-Term Indicators (weighting)
#  * Percent above/below 200-day SMA (30%)
#  * 125-Day Rate-of-Change (30%)

def SM200 = SimpleMovingAvg(close, SMA200);
def LTSMA = ((close - SM200) / ((close + SM200) / 2));
def LTROC = RateOfChange(ROC125, close);
def LT = (LTSMA + LTROC) * LT_WEIGHT;

#Medium-Term Indicators (weighting)
#  * Percent above/below 50-day SMA  (15%)
#  * 20-day Rate-of-Change (15%)

def SM50 = SimpleMovingAvg(close, SMA50);
def MDSMA = ((close - SM50) / ((close + SM50) / 2));
def MDROC = RateOfChange(ROC20, close);
def MD = (MDSMA + MDROC) * MD_WEIGHT;

#Short-Term Indicators (weighting)
#  * 3-day slope of PPO-Histogram (5%)
#  * 14-day RSI (5%)

def EMA12 = MovAvgExponential(close, 12);
def EMA26 = MovAvgExponential(close, 26);
#def MACD = EMA12 - EMA26;
def PPO = (EMA12 - EMA26) / EMA26 * 100;
def PPOlinear = 6 * ( WMA(PPO, 3) -  Average(PPO, 3)) / (3 - 1);

# Mutliplier to get values between 0-100

def PPOdiff = PPOlinear - PPOlinear[1];
def NetChgAvg = SimpleMovingAvg(PPOdiff, 3);
def TotChgAvg = SimpleMovingAvg(AbsValue(PPOdiff), 3);
def ChgRatio = If(TotChgAvg != 0, (NetChgAvg / TotChgAvg), 0);

def SHPPO = Round(50 * (ChgRatio + 1), 3) / 100;
def SHRSI = reference RSI();
def SH = (SHPPO + SHRSI) * SH_WEIGHT;

def TR = Round(LT + MD + SH, NUMBEROFDIGITS = 1);

plot SCTR = if IsNaN(TR) then 0 else TR;

plot LONG_SR_HIGH = Round(Highest(SCTR, LENGTH = SR_LENGTH), NUMBEROFDIGITS = 1);

plot LONG_SR_LOW = Round(Lowest(SCTR, LENGTH = SR_LENGTH), NUMBEROFDIGITS = 1);

plot ZERO = 0;

SCTR.AssignValueColor(if SCTR >= ZERO then Color.GREEN else Color.RED);
SCTR.SetLineWeight(1);
SCTR.SetStyle(Curve.POINTS);

ZERO.AssignValueColor(if SCTR >= ZERO then Color.GREEN else Color.RED);
ZERO.SetLineWeight(3);
ZERO.SetStyle(Curve.POINTS);
ZERO.Hide();

LONG_SR_HIGH.SetDefaultColor(Color.CYAN);
#LONG_SR_HIGH.SetStyle(Curve.SHORT_DASH);
LONG_SR_HIGH.SetLineWeight(1);
LONG_SR_HIGH.Hide();

LONG_SR_LOW.SetDefaultColor(Color.CYAN);
#LONG_SR_LOW.SetStyle(Curve.SHORT_DASH);
LONG_SR_LOW.SetLineWeight(1);
LONG_SR_LOW.Hide();

### $$$ ###
 

Emrys

New member
I have been trying to use this script, but some stocks are showing more than 100.
The problem comes from at least these two lines:

Code:
def LTSMA = ((close - SM200) / ((close + SM200) / 2));

Code:
def MDSMA = ((close - SM50) / ((close + SM50) / 2));

If a close is 100 and SMA200 is 50, then LTSMA will be 50 / 75 = 0.667.
If a close is 150 and SMA200 is 50, then LTSMA will be 100 / 100 = 1.
If a close is 250 and SMA200 is 50, then LTSMA will be 200 / 150 =1.33
Same problem for MDSMA as it follows the same logic.

Thus, LTSMA and MDSMA can disproportionately add extra weighting to final scores when stock price skyrockets.
In other words, when stock price increases quickly, the score generated by this script can reach several hundreds.

According to a SctockCharts web page (https://school.stockcharts.com/doku.php?id=technical_indicators:sctr),
they convert scores to 0.00 - 99.99 ranking by comparing with each other.
I have not found a better way to convert the scores on TOS.
 
Last edited by a moderator:

JE $$

Member
I've been trying to put this in a watchlist column to simply display the value of the SCTR - all i can get is the lower indicator to appear when i use it as a study. if i past the script into the custom watchlist it says exactly one plot expected - i think its a simple fix but for the life of me cant get it to work - can anyone give some adivce?
 

Joshua

Active member
VIP
I've been trying to put this in a watchlist column to simply display the value of the SCTR - all i can get is the lower indicator to appear when i use it as a study. if i past the script into the custom watchlist it says exactly one plot expected - i think its a simple fix but for the life of me cant get it to work - can anyone give some adivce?
Change Plot to Def everywhere except for with SCTR, and delete all the stuff at the bottom related to the unused plots.
 

brandus01

New member
hi i am been trying to use this indicator in tradingview but I am getting this error "Add to Chart operation failed, reason: line 9: no viable alternative at character ';'" any one can you please help me it will make my life simpler
 

MerryDay

Administrative
Staff member
Staff
VIP
Lifetime
hi i am been trying to use this indicator in tradingview but I am getting this error "Add to Chart operation failed, reason: line 9: no viable alternative at character ';'" any one can you please help me it will make my life simpler
This is not a TradingView script.
If you are looking to get it converted to pinescript, you need to address your question over on Tradingview
 

Similar threads

Top