cci 수정
This commit is contained in:
@@ -10,7 +10,11 @@ function sma(values: number[], period: number): number[] {
|
||||
return values.map((_, i) => {
|
||||
if (i < period - 1) return NaN;
|
||||
let sum = 0;
|
||||
for (let j = i - period + 1; j <= i; j++) sum += values[j];
|
||||
for (let j = i - period + 1; j <= i; j++) {
|
||||
const v = values[j];
|
||||
if (!Number.isFinite(v)) return NaN;
|
||||
sum += v;
|
||||
}
|
||||
return sum / period;
|
||||
});
|
||||
}
|
||||
@@ -252,7 +256,7 @@ export function calcRSI(
|
||||
/**
|
||||
* CCI + 신호선 (업비트·TradingView)
|
||||
* CCI = (src - SMA(src,N)) / (0.015 × MeanDeviation)
|
||||
* 신호선 = CCI의 SMA/EMA/WMA (기본 SMA 10)
|
||||
* src 기본 hlc3(고저종 평균), 신호선 = CCI의 SMA/EMA/WMA (기본 SMA 10)
|
||||
*/
|
||||
export function calcCCI(
|
||||
bars: OHLCVBar[],
|
||||
@@ -262,7 +266,7 @@ export function calcCCI(
|
||||
const maLen = Math.max(1, Number(params.maLength ?? 10) || 10);
|
||||
const rawMa = String(params.maType ?? 'SMA');
|
||||
const maType = rawMa === 'EMA' || rawMa === 'WMA' ? rawMa : (rawMa === 'None' ? 'None' : 'SMA');
|
||||
const srcKey = String(params.src ?? 'close');
|
||||
const srcKey = String(params.src ?? 'hlc3');
|
||||
const prices = bars.map(b => sourceAt(b, srcKey));
|
||||
|
||||
const cci = prices.map((_, i) => {
|
||||
|
||||
Reference in New Issue
Block a user