use of org.ta4j.core.Decimal in project ta4j by ta4j.
the class ROCVIndicator method calculate.
@Override
protected Decimal calculate(int index) {
int nIndex = Math.max(index - timeFrame, 0);
Decimal nPeriodsAgoValue = series.getBar(nIndex).getVolume();
Decimal currentValue = series.getBar(index).getVolume();
return currentValue.minus(nPeriodsAgoValue).dividedBy(nPeriodsAgoValue).multipliedBy(Decimal.HUNDRED);
}
use of org.ta4j.core.Decimal in project ta4j by ta4j.
the class DeMarkReversalIndicator method calculateResistance.
private Decimal calculateResistance(Decimal x, int index) {
List<Integer> barsOfPreviousPeriod = pivotPointIndicator.getBarsOfPreviousPeriod(index);
if (barsOfPreviousPeriod.isEmpty()) {
return Decimal.NaN;
}
Bar bar = getTimeSeries().getBar(barsOfPreviousPeriod.get(0));
Decimal low = bar.getMinPrice();
for (int i : barsOfPreviousPeriod) {
low = getTimeSeries().getBar(i).getMinPrice().min(low);
}
return x.dividedBy(Decimal.TWO).minus(low);
}
use of org.ta4j.core.Decimal in project ta4j by ta4j.
the class InSlopeRule method isSatisfied.
@Override
public boolean isSatisfied(int index, TradingRecord tradingRecord) {
DifferenceIndicator diff = new DifferenceIndicator(ref, prev);
Decimal val = diff.getValue(index);
boolean minSlopeSatisfied = minSlope.isNaN() || val.isGreaterThanOrEqual(minSlope);
boolean maxSlopeSatisfied = maxSlope.isNaN() || val.isLessThanOrEqual(maxSlope);
boolean isNaN = minSlope.isNaN() && maxSlope.isNaN();
final boolean satisfied = minSlopeSatisfied && maxSlopeSatisfied && !isNaN;
traceIsSatisfied(index, satisfied);
return satisfied;
}
use of org.ta4j.core.Decimal in project ta4j by ta4j.
the class IsHighestRule method isSatisfied.
@Override
public boolean isSatisfied(int index, TradingRecord tradingRecord) {
HighestValueIndicator highest = new HighestValueIndicator(ref, timeFrame);
Decimal highestVal = highest.getValue(index);
Decimal refVal = ref.getValue(index);
final boolean satisfied = !refVal.isNaN() && !highestVal.isNaN() && refVal.equals(highestVal);
traceIsSatisfied(index, satisfied);
return satisfied;
}
use of org.ta4j.core.Decimal in project ta4j by ta4j.
the class StopGainRule method isSatisfied.
@Override
public boolean isSatisfied(int index, TradingRecord tradingRecord) {
boolean satisfied = false;
// No trading history or no trade opened, no gain
if (tradingRecord != null) {
Trade currentTrade = tradingRecord.getCurrentTrade();
if (currentTrade.isOpened()) {
Decimal entryPrice = currentTrade.getEntry().getPrice();
Decimal currentPrice = closePrice.getValue(index);
Decimal threshold = entryPrice.multipliedBy(gainRatioThreshold);
if (currentTrade.getEntry().isBuy()) {
satisfied = currentPrice.isGreaterThanOrEqual(threshold);
} else {
satisfied = currentPrice.isLessThanOrEqual(threshold);
}
}
}
traceIsSatisfied(index, satisfied);
return satisfied;
}
Aggregations