Commit 9022386
Fix STC dividing by a near-zero denominator, producing -Inf/huge swings
STC = 100*(MACD-%K)/(%D-%K) divided by a denominator that's frequently
near zero (%K and %D are both stochastic-smoothed values of the same
MACD series and track each other closely), so real-world input could
yield -Inf or swings like 1435/-710 for an indicator documented to
oscillate 0-100.
The standard Schaff Trend Cycle algorithm instead applies the
rolling-min/max stochastic normalization *twice* -- once to MACD to
get %K1/%D1, then again to %D1 to get %K2/%D2 -- with STC = %D2. Both
stages stay bounded in [0, 100] by construction, since they're each a
range-normalized percentage smoothed by an SMA, not a division against
another stochastic-smoothed value.
TestStcFull's fixture was too short for the new, larger warm-up (two
stochastic passes need more lead-in than one), so it now generates its
own longer synthetic series instead of testdata/stochastic.csv.
Fixes #425
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>1 parent 6653727 commit 9022386
2 files changed
Lines changed: 30 additions & 52 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
37 | | - | |
| 36 | + | |
| 37 | + | |
38 | 38 | | |
39 | | - | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
40 | 47 | | |
41 | 48 | | |
42 | 49 | | |
| |||
96 | 103 | | |
97 | 104 | | |
98 | 105 | | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
108 | 112 | | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
| 113 | + | |
| 114 | + | |
118 | 115 | | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
| 116 | + | |
135 | 117 | | |
136 | 118 | | |
137 | 119 | | |
138 | 120 | | |
139 | | - | |
| 121 | + | |
140 | 122 | | |
141 | 123 | | |
142 | 124 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
54 | 59 | | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
59 | 63 | | |
60 | 64 | | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | 65 | | |
70 | | - | |
| 66 | + | |
71 | 67 | | |
72 | 68 | | |
73 | 69 | | |
74 | | - | |
| 70 | + | |
75 | 71 | | |
76 | 72 | | |
77 | 73 | | |
| |||
0 commit comments