forked from JeanTann3n/tos-option-volume
-
Notifications
You must be signed in to change notification settings - Fork 0
/
OptionPutVol.ts
164 lines (123 loc) · 5 KB
/
OptionPutVol.ts
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# Options Put Volume
# Initial script by JeanTann3en
# Refactored and optimized by Wahakalaka
# This thinkscript will pull option put volume for the underlying symbol and then overlay it on a histogram, for the configured dates.
script agg_vol {
input exp = "200417";
input start_price = 200;
input end_price = 250;
input type = "P";
plot agg_put_vol = fold strike = start_price to end_price with v do v +
if isNan(volume(Concat(".", Concat(GetSymbol(), Concat(exp, Concat(type, strike)))))) then 0
else volume(Concat(".", Concat(GetSymbol(), Concat(exp, Concat(type, strike)))));
}
declare lower;
input date_strike_ranges = no;
input strike_start = 180;
input strike_end = 300;
input date01 = "200409";
input date02 = "200413";
input date03 = "200415";
input date04 = "200417";
input date05 = "200424";
input date06 = "200501";
input date07 = "200515";
input date08 = "200619";
input strike_start_01 = 180;
input strike_end_01 = 300;
input strike_start_02 = 180;
input strike_end_02 = 300;
input strike_start_03 = 180;
input strike_end_03 = 300;
input strike_start_04 = 180;
input strike_end_04 = 300;
input strike_start_05 = 180;
input strike_end_05 = 300;
input strike_start_06 = 180;
input strike_end_06 = 300;
input strike_start_07 = 180;
input strike_end_07 = 300;
input strike_start_08 = 180;
input strike_end_08 = 300;
plot put_vol_01;
if date_strike_ranges{
put_vol_01 = agg_vol(date01, strike_start_01, strike_end_01, "P");
} else {
put_vol_01 = agg_vol(date01, strike_start, strike_end, "P");
}
plot put_vol_02;
if date_strike_ranges{
put_vol_02 = agg_vol(date02, strike_start_02, strike_end_02, "P");
} else {
put_vol_02 = agg_vol(date02, strike_start, strike_end, "P");
}
plot put_vol_03;
if date_strike_ranges{
put_vol_03 = agg_vol(date03, strike_start_03, strike_end_03, "P");
} else {
put_vol_03 = agg_vol(date03, strike_start, strike_end, "P");
}
plot put_vol_04;
if date_strike_ranges{
put_vol_04 = agg_vol(date04, strike_start_04, strike_end_04, "P");
} else {
put_vol_04 = agg_vol(date04, strike_start, strike_end, "P");
}
plot put_vol_05;
if date_strike_ranges{
put_vol_05 = agg_vol(date05, strike_start_05, strike_end_05, "P");
} else {
put_vol_05 = agg_vol(date05, strike_start, strike_end, "P");
}
plot put_vol_06;
if date_strike_ranges{
put_vol_06 = agg_vol(date06, strike_start_06, strike_end_06, "P");
} else {
put_vol_06 = agg_vol(date06, strike_start, strike_end, "P");
}
plot put_vol_07;
if date_strike_ranges{
put_vol_07 = agg_vol(date07, strike_start_07, strike_end_07, "P");
} else {
put_vol_07 = agg_vol(date07, strike_start, strike_end, "P");
}
plot put_vol_08;
if date_strike_ranges{
put_vol_08 = agg_vol(date08, strike_start_08, strike_end_08, "P");
} else {
put_vol_08 = agg_vol(date08, strike_start, strike_end, "P");
}
# Data is visualized with an overlayed histogram.
# Because alpha values cannot be passed to CreateColor, please remember to set white to 99 alpha under RGB.
put_vol_01.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
put_vol_02.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
put_vol_03.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
put_vol_04.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
put_vol_05.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
put_vol_06.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
put_vol_07.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
put_vol_08.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
put_vol_01.SetDefaultColor(Color.WHITE);
put_vol_02.SetDefaultColor(CreateColor(35,158,201));
put_vol_03.SetDefaultColor(CreateColor(88,255,21));
put_vol_04.SetDefaultColor(CreateColor(255,95,95));
put_vol_05.SetDefaultColor(CreateColor(213,195,0));
put_vol_06.SetDefaultColor(CreateColor(210,24,248));
put_vol_07.SetDefaultColor(CreateColor(81,93,255));
put_vol_08.SetDefaultColor(CreateColor(255,134,230));
addLabel(1, date01, Color.WHITE);
addLabel(date_strike_ranges, strike_start_01 + "-" + strike_end_01, Color.WHITE);
addLabel(1, date02, CreateColor(35,158,201));
addLabel(date_strike_ranges, strike_start_02 + "-" + strike_end_02, CreateColor(35,158,201));
addLabel(1, date03, CreateColor(88,255,21));
addLabel(date_strike_ranges, strike_start_03 + "-" + strike_end_03, CreateColor(88,255,21));
addLabel(1, date04, CreateColor(255,95,95));
addLabel(date_strike_ranges, strike_start_04 + "-" + strike_end_04, CreateColor(255,95,95));
addLabel(1, date05, CreateColor(213,195,0));
addLabel(date_strike_ranges, strike_start_05 + "-" + strike_end_05, CreateColor(213,195,0));
addLabel(1, date06, CreateColor(210,24,248));
addLabel(date_strike_ranges, strike_start_06 + "-" + strike_end_06, CreateColor(210,24,248));
addLabel(1, date07, CreateColor(81,93,255));
addLabel(date_strike_ranges, strike_start_07 + "-" + strike_end_07, CreateColor(81,93,255));
addLabel(1, date08, CreateColor(255,134,230));
addLabel(date_strike_ranges, strike_start_08 + "-" + strike_end_08, CreateColor(255,134,230));