cci 수정
This commit is contained in:
@@ -7,12 +7,34 @@ import org.ta4j.core.indicators.averages.SMAIndicator;
|
||||
import org.ta4j.core.indicators.statistics.MeanDeviationIndicator;
|
||||
import org.ta4j.core.num.Num;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* TradingView/업비트 CCI — 임의 가격 소스에 대해
|
||||
* (src - SMA) / (0.015 × MeanDeviation) 계산.
|
||||
*/
|
||||
public class CciOnSourceIndicator extends CachedIndicator<Num> {
|
||||
|
||||
/** 업비트·TradingView 기본: hlc3(고저종), 기간 13, 신호 SMA 10 */
|
||||
public static Map<String, Object> normalizeParams(Map<String, Object> p) {
|
||||
Map<String, Object> out = new HashMap<>(p);
|
||||
String maType = String.valueOf(p.getOrDefault("maType", "SMA"));
|
||||
int length = intParam(p, "length", 13);
|
||||
int maLength = intParam(p, "maLength", 10);
|
||||
String src = String.valueOf(p.getOrDefault("src", "hlc3"));
|
||||
if ("close".equals(src) && length == 13 && maLength == 10 && "SMA".equals(maType)) {
|
||||
src = "hlc3";
|
||||
}
|
||||
out.put("src", src);
|
||||
return out;
|
||||
}
|
||||
|
||||
private static int intParam(Map<String, Object> p, String k, int def) {
|
||||
Object v = p.get(k);
|
||||
return v == null ? def : ((Number) v).intValue();
|
||||
}
|
||||
|
||||
private final Indicator<Num> price;
|
||||
private final SMAIndicator sma;
|
||||
private final MeanDeviationIndicator meanDeviation;
|
||||
|
||||
@@ -398,8 +398,9 @@ public class IndicatorService {
|
||||
int len = intP(p, "length", 13);
|
||||
int maLen = intP(p, "maLength", 10);
|
||||
String maType = p.getOrDefault("maType", "SMA").toString();
|
||||
Map<String, Object> norm = CciOnSourceIndicator.normalizeParams(p);
|
||||
|
||||
CciOnSourceIndicator cci = new CciOnSourceIndicator(src(s, p), len);
|
||||
CciOnSourceIndicator cci = new CciOnSourceIndicator(src(s, norm), len);
|
||||
|
||||
Indicator<Num> maInd = switch (maType) {
|
||||
case "EMA" -> new EMAIndicator(cci, maLen);
|
||||
|
||||
@@ -599,10 +599,10 @@ 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 CciOnSourceIndicator(resolvePriceSource(s, p), period);
|
||||
return new CciOnSourceIndicator(resolvePriceSource(s, CciOnSourceIndicator.normalizeParams(p)), period);
|
||||
}
|
||||
if (field.equals("CCI_VALUE") || indType.equals("CCI"))
|
||||
return new CciOnSourceIndicator(resolvePriceSource(s, p),
|
||||
return new CciOnSourceIndicator(resolvePriceSource(s, CciOnSourceIndicator.normalizeParams(p)),
|
||||
periodOverride > 0 ? periodOverride : intP(p, "length", 13));
|
||||
// RSI — 기간 접미사(RSI_VALUE_9) 또는 기본 RSI_VALUE
|
||||
if (field.startsWith("RSI_VALUE_")) {
|
||||
|
||||
Reference in New Issue
Block a user