@Test public void parabolicSar00404IsCalculatedCorrectly() { final ParabolicStopAndReverse<DatedCandleStick<M1>> cut = new ParabolicStopAndReverse<>(new Ratio(0.04), new Ratio(0.4)); for (int i = 0; i < 94; i++) { cut.indicate(testData.get(i).marketData); } for (int i = 94; i < testData.size(); i++) { final TestData datum = testData.get(i); assertThat(cut.indicate(datum.marketData).get()).isEqualTo(datum.psar00404); } }
@Override public Optional<Price> indicate(final C marketPrice) { if (currentPeriode == 0) { this.trend = UP; this.extremePoint = marketPrice.getHigh().asDouble(); this.sar = marketPrice.getLow().asDouble(); this.accelerationFactor = increasment; } final double delta = abs(extremePoint - sar) * accelerationFactor; sar = trend == UP ? sar + delta : sar - delta; if (shouldTurn(marketPrice)) { turnSAR(marketPrice); } else { updateValues(marketPrice); } if (currentPeriode < SETUP_PERIODS) { currentPeriode++; return Optional.empty(); } else { return Optional.of(new Price(sar)); } }
ParabolicStopAndReverse implements Indicator<Price, C> { @Override public Optional<Price> indicate(final C marketPrice) { if (currentPeriode == 0) { this.trend = UP; this.extremePoint = marketPrice.getHigh().asDouble(); this.sar = marketPrice.getLow().asDouble(); this.accelerationFactor = increasment; } final double delta = abs(extremePoint - sar) * accelerationFactor; sar = trend == UP ? sar + delta : sar - delta; if (shouldTurn(marketPrice)) { turnSAR(marketPrice); } else { updateValues(marketPrice); } if (currentPeriode < SETUP_PERIODS) { currentPeriode++; return Optional.empty(); } else { return Optional.of(new Price(sar)); } } }
ParabolicStopAndReverse implements Indicator<Price, C> { @Override public Optional<Price> indicate(final C marketPrice) { if (currentPeriode == 0) { this.trend = UP; this.extremePoint = marketPrice.getHigh().asDouble(); this.sar = marketPrice.getLow().asDouble(); this.accelerationFactor = increasment; } final double delta = abs(extremePoint - sar) * accelerationFactor; sar = trend == UP ? sar + delta : sar - delta; if (shouldTurn(marketPrice)) { turnSAR(marketPrice); } else { updateValues(marketPrice); } if (currentPeriode < SETUP_PERIODS) { currentPeriode++; return Optional.empty(); } else { return Optional.of(new Price(sar)); } } ParabolicStopAndReverse(final Ratio accelerationFactorIncreasment, final Ratio maximalAcceleration); }
ParabolicStopAndReverse implements Indicator<Price, C> { @Override public Optional<Price> indicate(final C marketPrice) { if (currentPeriode == 0) { this.trend = UP; this.extremePoint = marketPrice.getHigh().asDouble(); this.sar = marketPrice.getLow().asDouble(); this.accelerationFactor = increasment; } final double delta = abs(extremePoint - sar) * accelerationFactor; sar = trend == UP ? sar + delta : sar - delta; if (shouldTurn(marketPrice)) { turnSAR(marketPrice); } else { updateValues(marketPrice); } if (currentPeriode < SETUP_PERIODS) { currentPeriode++; return Optional.empty(); } else { return Optional.of(new Price(sar)); } } ParabolicStopAndReverse(final Ratio accelerationFactorIncreasment, final Ratio maximalAcceleration); @Override Optional<Price> indicate(final C marketPrice); }
ParabolicStopAndReverse implements Indicator<Price, C> { @Override public Optional<Price> indicate(final C marketPrice) { if (currentPeriode == 0) { this.trend = UP; this.extremePoint = marketPrice.getHigh().asDouble(); this.sar = marketPrice.getLow().asDouble(); this.accelerationFactor = increasment; } final double delta = abs(extremePoint - sar) * accelerationFactor; sar = trend == UP ? sar + delta : sar - delta; if (shouldTurn(marketPrice)) { turnSAR(marketPrice); } else { updateValues(marketPrice); } if (currentPeriode < SETUP_PERIODS) { currentPeriode++; return Optional.empty(); } else { return Optional.of(new Price(sar)); } } ParabolicStopAndReverse(final Ratio accelerationFactorIncreasment, final Ratio maximalAcceleration); @Override Optional<Price> indicate(final C marketPrice);  }