-
Notifications
You must be signed in to change notification settings - Fork 26
/
FGMR.txt
106 lines (85 loc) · 2.88 KB
/
FGMR.txt
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#
# $SPX Fear & Greed Mean Reversion Study (FGMR)
#
# This script adapted from posts from @kerberos007
# https://twitter.com/kerberos007
#
# Want the latest version of this script?
# https://github.com/korygill/technical-analysis
#
# Use on thinkorswim and thinkscript
# author @korygill
#
script GetBollingerBandPercent
{
input price = close;
input upper = 2;
input lower = -2;
input averageType = AverageType.SIMPLE;
input displace = 0;
input length = 20;
def upperBand = BollingerBands(price, displace, length, lower, upper, averageType).UpperBand;
def lowerBand = BollingerBands(price, displace, length, lower, upper, averageType).LowerBand;
plot BBPercent = (price - lowerBand) / (upperBand - lowerBand) * 100;
}
declare lower;
input averageType = AverageType.Simple;
input price = close;
input displace = 0;
input length = 20;
input StdDev_DnBuy = -2.0;
input StdDev_UpBuy = 2.0;
input StdDev_DnSell = -1.0;
input StdDev_UpSell = 1.0;
plot PercentBBuy = GetBollingerBandPercent(price, StdDev_UpBuy, StdDev_DnBuy);
plot PercentBSell = GetBollingerBandPercent(price, StdDev_UpSell, StdDev_DnSell);
plot ZeroLine = 0;
plot HalfLine = 50;
plot UnitLine = 100;
def vixPrice = close("VIX");
def vixPercentBBuy = GetBollingerBandPercent(vixPrice, StdDev_UpBuy, StdDev_DnBuy);
def vixPercentBSell = GetBollingerBandPercent(vixPrice, StdDev_UpSell, StdDev_DnSell);
def opacity = 25;
def linewidth = 1;
PercentBBuy.SetDefaultColor(Color.GREEN);#(GetColor(3));
PercentBBuy.AssignValueColor(CreateColor(
0,
255, #255-Max(0,Min(100-opacity,PercentBBuy))*2.55,
0));
PercentBBuy.SetPaintingStrategy(PaintingStrategy.LINE);
PercentBBuy.SetLineWeight(linewidth);
PercentBSell.SetDefaultColor(Color.RED);#(GetColor(7));
PercentBSell.AssignValueColor(CreateColor(
255, #Max(opacity,Min(100,PercentBSell))*2.55,
0,
0));
PercentBSell.SetPaintingStrategy(PaintingStrategy.LINE);
PercentBSell.SetLineWeight(linewidth);
ZeroLine.SetDefaultColor(Color.GREEN);
HalfLine.SetDefaultColor(GetColor(8));
UnitLine.SetDefaultColor(Color.RED);
# LONG
AddVerticalLine(
Crosses(PercentBBuy, ZeroLine, CrossingDirection.ABOVE),
"+++ Go Long +++", Color.GREEN, curve.SHORT_DASH
);
AddVerticalLine(
Crosses(PercentBSell, UnitLine, CrossingDirection.ABOVE),
"+++ Cover Long +++", Color.RED, curve.SHORT_DASH
);
# SHORT
AddVerticalLine(
Crosses(PercentBBuy, UnitLine, CrossingDirection.BELOW),
"--- (Go Short) ---", Color.YELLOW, curve.SHORT_DASH
);
AddVerticalLine(
Crosses(PercentBSell, ZeroLine, CrossingDirection.BELOW),
"--- (Cover Short) ---", Color.MAGENTA, curve.SHORT_DASH
);
#AddVerticalLine(
# GetDayofWeek(GetYYYYMMDD()) == 5,
# "Friday", Color.LIGHT_GRAY, curve.MEDIUM_DASH
#);
AddLabel(yes, GetSymbol(), COLOR.CYAN);
AddLabel(yes, "Long=Green cross > 0, Cover=Red cross > 100", COLOR.GREEN);
AddLabel(yes, "Short=Red cross < 100, Cover=Green cross < 0", COLOR.RED);