SHOW:
|
|
- or go back to the newest paste.
1 | ### Expected Move Labels ### | |
2 | # This script will add expected move labels, # | |
3 | # in dollars, to charts. IT IS INTENDED TO BE# | |
4 | # USED ONLY ON CHARTS WITH DAILY BARS. The # | |
5 | # math will not work one charts with other # | |
6 | # settings. # | |
7 | ||
8 | ### Settings for coloring ### | |
9 | ||
10 | input dayCountDanger = 1; #hint: Out of the last two days, this number of violations of the expected move will turn the label red. | |
11 | input weekCountDanger = 5; #hint: Out of the last ten days, this number of violations of the expected move will turn the label red. | |
12 | input weekCountWarning = 2; #hint: Out of the last ten days, this number of violations of the expected move will turn the label yellow. | |
13 | input monthCountDanger = 11; #hint: Out of the last twenty two days, this number of violations of the expected move will turn the label red. | |
14 | input monthCountWarning = 5; #hint: Out of the last twenty two days, this number of violations of the expected move will turn the label yellow. | |
15 | input violationMetric = close; # hint: The metric that will count as a violation against the expected move. | |
16 | ||
17 | ### Calculate the expected move ### | |
18 | def IVBase = imp_volatility(); | |
19 | def ExMoveBase = close * IVBase; | |
20 | def ExMoveOneDay = close * IVBase * Sqrt(1/365); | |
21 | def ExMoveOneWeek = close * IVBase * Sqrt(7/365); | |
22 | def ExMoveOneMonth = close * IVBase * Sqrt(30/365); | |
23 | ||
24 | ### Determine violations ### | |
25 | def dayCount = fold i = 1 to 5 with countA = 0 | |
26 | do | |
27 | if violationMetric[i] > (violationMetric + ExMoveOneDay) or violationMetric[i] < (violationMetric - ExMoveOneDay) then | |
28 | countA + 1 | |
29 | else | |
30 | countA; | |
31 | def weekCount = fold n = 1 to 10 with countB = 0 | |
32 | do | |
33 | if violationMetric[n] > (violationMetric + ExMoveOneWeek) or violationMetric[n] < (violationMetric - ExMoveOneWeek) then | |
34 | countB + 1 | |
35 | else | |
36 | countB; | |
37 | def monthCount = fold m = 1 to 22 with countC = 0 | |
38 | do | |
39 | if violationMetric[m] > (violationMetric + ExMoveOneMonth) or violationMetric[m] < (violationMetric - ExMoveOneMonth) then | |
40 | countC + 1 | |
41 | else | |
42 | countC; | |
43 | ||
44 | ### Add labels to chart ### | |
45 | AddLabel(yes, "Expected Moves at 68% confidence", Color.WHITE); | |
46 | AddLabel(yes, "1 Day: +/-" + AsDollars(ExMoveOneDay) + "(" + dayCount + ")", if dayCount > 1 then Color.RED else if dayCount == 1 then Color.YELLOW else Color.GREEN); | |
47 | AddLabel(yes, "1 Week: +/-" + AsDollars(ExMoveOneWeek) + "(" + weekCount + ")", if weekCount >= 5 then Color.RED else if weekCount > 2 and weekCount < 5 then Color.YELLOW else Color.GREEN); | |
48 | AddLabel(yes, "1 Month: +/-" + AsDollars(ExMoveOneMonth) + "(" + monthCount + ")", if monthCount >= 11 then Color.RED else if monthCount > 5 and monthCount < 11 then Color.YELLOW else Color.GREEN); |