|
47 | 47 | public class ParabolicSarIndicator extends RecursiveCachedIndicator<Num> { |
48 | 48 |
|
49 | 49 | private final LowPriceIndicator lowPriceIndicator; |
| 50 | + private final LowestValueIndicator lowestValueIndicator; |
50 | 51 | private final HighPriceIndicator highPriceIndicator; |
| 52 | + private final HighestValueIndicator highestValueIndicator; |
51 | 53 |
|
52 | 54 | private final Num maxAcceleration; |
53 | 55 | private final Num accelerationStart; |
@@ -99,7 +101,9 @@ public ParabolicSarIndicator(BarSeries series, Num aF, Num maxA) { |
99 | 101 | public ParabolicSarIndicator(BarSeries series, Num aF, Num maxA, Num increment) { |
100 | 102 | super(series); |
101 | 103 | this.lowPriceIndicator = new LowPriceIndicator(series); |
| 104 | + this.lowestValueIndicator = new LowestValueIndicator(lowPriceIndicator, 2); |
102 | 105 | this.highPriceIndicator = new HighPriceIndicator(series); |
| 106 | + this.highestValueIndicator = new HighestValueIndicator(highPriceIndicator, 2); |
103 | 107 | this.maxAcceleration = maxA; |
104 | 108 | this.accelerationStart = aF; |
105 | 109 | this.accelerationIncrement = increment; |
@@ -149,13 +153,13 @@ private Num calculateInternal(int index) { |
149 | 153 | isUpTrendMap.put(index, is_up_trend); |
150 | 154 |
|
151 | 155 | if (is_up_trend) { // up trend |
152 | | - sar = new LowestValueIndicator(lowPriceIndicator, 2).getValue(index - 1); // put the lowest low value of |
| 156 | + sar = lowestValueIndicator.getValue(index - 1); // put the lowest low value of |
153 | 157 | // two |
154 | | - lastExtreme.put(index, new HighestValueIndicator(highPriceIndicator, 2).getValue(index - 1)); |
| 158 | + lastExtreme.put(index, highestValueIndicator.getValue(index - 1)); |
155 | 159 | } else { // down trend |
156 | | - sar = new HighestValueIndicator(highPriceIndicator, 2).getValue(index - 1); // put the highest high |
| 160 | + sar = highestValueIndicator.getValue(index - 1); // put the highest high |
157 | 161 | // value of |
158 | | - lastExtreme.put(index, new LowestValueIndicator(lowPriceIndicator, 2).getValue(index - 1)); |
| 162 | + lastExtreme.put(index, lowestValueIndicator.getValue(index - 1)); |
159 | 163 | } |
160 | 164 | return sar; |
161 | 165 | } |
@@ -206,12 +210,12 @@ private Num calculateInternal(int index) { |
206 | 210 | } |
207 | 211 |
|
208 | 212 | if (is_up_trend) { |
209 | | - Num lowestPriceOfTwoPreviousBars = new LowestValueIndicator(lowPriceIndicator, 2).getValue(index - 1); |
| 213 | + Num lowestPriceOfTwoPreviousBars = lowestValueIndicator.getValue(index - 1); |
210 | 214 | if (sar.isGreaterThan(lowestPriceOfTwoPreviousBars)) { |
211 | 215 | sar = lowestPriceOfTwoPreviousBars; |
212 | 216 | } |
213 | 217 | } else { |
214 | | - Num highestPriceOfTwoPreviousBars = new HighestValueIndicator(highPriceIndicator, 2).getValue(index - 1); |
| 218 | + Num highestPriceOfTwoPreviousBars = highestValueIndicator.getValue(index - 1); |
215 | 219 | if (sar.isLessThan(highestPriceOfTwoPreviousBars)) { |
216 | 220 | sar = highestPriceOfTwoPreviousBars; |
217 | 221 | } |
|
0 commit comments