보조지표 소수점 추가, cci 수정
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
package com.goldenchart.service;
|
||||
|
||||
import org.ta4j.core.BarSeries;
|
||||
import org.ta4j.core.Indicator;
|
||||
import org.ta4j.core.indicators.CachedIndicator;
|
||||
import org.ta4j.core.indicators.averages.SMAIndicator;
|
||||
import org.ta4j.core.indicators.statistics.MeanDeviationIndicator;
|
||||
import org.ta4j.core.num.Num;
|
||||
|
||||
/**
|
||||
* TradingView/업비트 CCI — 임의 가격 소스에 대해
|
||||
* (src - SMA) / (0.015 × MeanDeviation) 계산.
|
||||
*/
|
||||
public class CciOnSourceIndicator extends CachedIndicator<Num> {
|
||||
|
||||
private final Indicator<Num> price;
|
||||
private final SMAIndicator sma;
|
||||
private final MeanDeviationIndicator meanDeviation;
|
||||
private final Num factor;
|
||||
private final int barCount;
|
||||
|
||||
public CciOnSourceIndicator(Indicator<Num> price, int barCount) {
|
||||
super(price);
|
||||
this.price = price;
|
||||
this.barCount = barCount;
|
||||
this.factor = getBarSeries().numFactory().numOf(0.015);
|
||||
this.sma = new SMAIndicator(price, barCount);
|
||||
this.meanDeviation = new MeanDeviationIndicator(price, barCount);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Num calculate(int index) {
|
||||
final Num meanDeviation = this.meanDeviation.getValue(index);
|
||||
if (meanDeviation.isZero()) {
|
||||
return getBarSeries().numFactory().zero();
|
||||
}
|
||||
return price.getValue(index).minus(sma.getValue(index))
|
||||
.dividedBy(meanDeviation.multipliedBy(factor));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCountOfUnstableBars() {
|
||||
return barCount - 1;
|
||||
}
|
||||
}
|
||||
@@ -396,10 +396,10 @@ public class IndicatorService {
|
||||
*/
|
||||
private Map<String, List<PlotPoint>> calcCCI(BarSeries s, Map<String, Object> p) {
|
||||
int len = intP(p, "length", 13);
|
||||
int maLen = intP(p, "maLength", 20);
|
||||
int maLen = intP(p, "maLength", 10);
|
||||
String maType = p.getOrDefault("maType", "SMA").toString();
|
||||
|
||||
CCIIndicator cci = new CCIIndicator(s, len);
|
||||
CciOnSourceIndicator cci = new CciOnSourceIndicator(src(s, p), len);
|
||||
|
||||
Indicator<Num> maInd = switch (maType) {
|
||||
case "EMA" -> new EMAIndicator(cci, maLen);
|
||||
|
||||
@@ -599,10 +599,11 @@ public class StrategyDslToTa4jAdapter {
|
||||
// CCI — 기간 접미사(CCI_VALUE_13) 또는 기본 CCI_VALUE
|
||||
if (field.startsWith("CCI_VALUE_")) {
|
||||
int period = parseTrailingInt(field, "CCI_VALUE_", intP(p, "length", 13));
|
||||
return new CCIIndicator(s, period);
|
||||
return new CciOnSourceIndicator(resolvePriceSource(s, p), period);
|
||||
}
|
||||
if (field.equals("CCI_VALUE") || indType.equals("CCI"))
|
||||
return new CCIIndicator(s, periodOverride > 0 ? periodOverride : intP(p, "length", 13));
|
||||
return new CciOnSourceIndicator(resolvePriceSource(s, p),
|
||||
periodOverride > 0 ? periodOverride : intP(p, "length", 13));
|
||||
// RSI — 기간 접미사(RSI_VALUE_9) 또는 기본 RSI_VALUE
|
||||
if (field.startsWith("RSI_VALUE_")) {
|
||||
int period = parseTrailingInt(field, "RSI_VALUE_", intP(p, "length", 14));
|
||||
@@ -865,6 +866,17 @@ public class StrategyDslToTa4jAdapter {
|
||||
|
||||
// ── TRIX 헬퍼 ─────────────────────────────────────────────────────────────
|
||||
|
||||
private Indicator<Num> resolvePriceSource(BarSeries s, Map<String, Object> p) {
|
||||
return switch (p.getOrDefault("src", "close").toString()) {
|
||||
case "open" -> new OpenPriceIndicator(s);
|
||||
case "high" -> new HighPriceIndicator(s);
|
||||
case "low" -> new LowPriceIndicator(s);
|
||||
case "hl2" -> new MedianPriceIndicator(s);
|
||||
case "hlc3" -> new TypicalPriceIndicator(s);
|
||||
default -> new ClosePriceIndicator(s);
|
||||
};
|
||||
}
|
||||
|
||||
private EMAIndicator tripleEma(ClosePriceIndicator close, int len) {
|
||||
return new EMAIndicator(new EMAIndicator(new EMAIndicator(close, len), len), len);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user