use of org.ta4j.core.Decimal in project ta4j by ta4j.
the class IsLowestRule method isSatisfied.
@Override
public boolean isSatisfied(int index, TradingRecord tradingRecord) {
LowestValueIndicator lowest = new LowestValueIndicator(ref, timeFrame);
Decimal lowestVal = lowest.getValue(index);
Decimal refVal = ref.getValue(index);
final boolean satisfied = !refVal.isNaN() && !lowestVal.isNaN() && refVal.equals(lowestVal);
traceIsSatisfied(index, satisfied);
return satisfied;
}
use of org.ta4j.core.Decimal in project ta4j by ta4j.
the class FibonacciReversalIndicator method calculate.
@Override
protected Decimal calculate(int index) {
List<Integer> barsOfPreviousPeriod = pivotPointIndicator.getBarsOfPreviousPeriod(index);
if (barsOfPreviousPeriod.isEmpty())
return Decimal.NaN;
Bar bar = getTimeSeries().getBar(barsOfPreviousPeriod.get(0));
Decimal high = bar.getMaxPrice();
Decimal low = bar.getMinPrice();
for (int i : barsOfPreviousPeriod) {
high = (getTimeSeries().getBar(i).getMaxPrice()).max(high);
low = (getTimeSeries().getBar(i).getMinPrice()).min(low);
}
if (fibReversalTyp == FibReversalTyp.RESISTANCE) {
return pivotPointIndicator.getValue(index).plus(fibonacciFactor.multipliedBy(high.minus(low)));
}
return pivotPointIndicator.getValue(index).minus(fibonacciFactor.multipliedBy(high.minus(low)));
}
use of org.ta4j.core.Decimal in project ta4j by ta4j.
the class StandardReversalIndicator method calculateR2.
private Decimal calculateR2(List<Integer> barsOfPreviousPeriod, int index) {
Bar bar = getTimeSeries().getBar(barsOfPreviousPeriod.get(0));
Decimal low = bar.getMinPrice();
Decimal high = bar.getMaxPrice();
for (int i : barsOfPreviousPeriod) {
low = (getTimeSeries().getBar(i).getMinPrice()).min(low);
high = (getTimeSeries().getBar(i).getMaxPrice()).max(high);
}
return pivotPointIndicator.getValue(index).plus((high.minus(low)));
}
use of org.ta4j.core.Decimal in project ta4j by ta4j.
the class StandardReversalIndicator method calculateS2.
private Decimal calculateS2(List<Integer> barsOfPreviousPeriod, int index) {
Bar bar = getTimeSeries().getBar(barsOfPreviousPeriod.get(0));
Decimal high = bar.getMaxPrice();
Decimal low = bar.getMinPrice();
for (int i : barsOfPreviousPeriod) {
high = (getTimeSeries().getBar(i).getMaxPrice()).max(high);
low = (getTimeSeries().getBar(i).getMinPrice()).min(low);
}
return pivotPointIndicator.getValue(index).minus((high.minus(low)));
}
use of org.ta4j.core.Decimal in project ta4j by ta4j.
the class CorrelationCoefficientIndicator method calculate.
@Override
protected Decimal calculate(int index) {
Decimal cov = covariance.getValue(index);
Decimal var1 = variance1.getValue(index);
Decimal var2 = variance2.getValue(index);
Decimal var1_2_sqrt = Decimal.valueOf(Math.sqrt(var1.multipliedBy(var2).doubleValue()));
return cov.dividedBy(var1_2_sqrt);
}
Aggregations