forked from hwrdprkns/ThinkOrSwim
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSCTR.txt
More file actions
75 lines (57 loc) · 2.17 KB
/
SCTR.txt
File metadata and controls
75 lines (57 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# SCTR
# Drew Griffith
#hint: This study is a replication of StockCharts SCTR. http://stockcharts.com/school/doku.php?id=chart_school:technical_indicators:sctr
declare upper;
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;
#Long-Term Indicators (weighting)
# * Percent above/below 200-day SMA (30%)
# * 125-Day Rate-of-Change (30%)
#def SM200 = SimpleMovingAvg(close, SMA200);
def SM200 = movavgExponential(close, 300); # adjustment from standard
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) OR isInfinite(TR) then 0 else TR;
plot ZERO = 0;
SCTR.AssignValueColor(if SCTR >= ZERO then Color.GREEN else Color.RED);
SCTR.SetLineWeight(1);
SCTR.SetStyle(Curve.POINTS);
SCTR.Hide();
ZERO.AssignValueColor(if SCTR >= ZERO then Color.GREEN else Color.RED);
ZERO.SetLineWeight(3);
ZERO.SetStyle(Curve.POINTS);
ZERO.Hide();
# Add label
AddLabel(SCTR, "SCTR = " + SCTR, if SCTR >= ZERO then Color.GREEN else if SCTR < ZERO then Color.RED else Color.GRAY);