CCI x CHOP x ADX x OBV x StochRSI Momentum (with EMA)

readCrypto · study · 103 行 · 点赞 265 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

//@version=6
indicator(title="CCI x CHOP x ADX x OBV x StochRSI Momentum (with EMA)", shorttitle="CCAOS", format=format.price, precision=2, timeframe="", timeframe_gaps=true)
 
// --- Inputs ---
// CCI 설정
cciLength = input.int(14, title="CCI Length", minval=1, group="CCI Settings", display = display.none)
src = input(hlc3, title="CCI Source", group="CCI Settings", display = display.none)
 
// CCI-based EMA 설정 (추가됨)
cciEmaLength = input.int(9, title="CCI-based EMA Length", minval=1, group="CCI Settings", display = display.none)
 
// CHOP 설정
chopLength = input.int(14, title="CHOP Length", minval=1, group="CHOP Settings", display = display.none)
 
// ADX 설정
adxLength = input.int(9, title="ADX Smoothing Length", minval=1, group="ADX Settings", display = display.none)
diLength = input.int(9, title="DI Length", minval=1, group="ADX Settings", display = display.none)
 
// OBV 설정
obvEmaLength = input.int(9, title="OBV EMA Length", minval=1, group="OBV Settings", display = display.none)
 
// StochRSI 설정
rsiLength = input.int(14, title="RSI Length", minval=1, group="StochRSI Settings", display = display.none)
stochLength = input.int(7, title="Stoch Length", minval=1, group="StochRSI Settings", display = display.none)
kSmooth = input.int(3, title="K Smoothing", minval=1, group="StochRSI Settings", display = display.none)
dSmooth = input.int(3, title="D Smoothing", minval=1, group="StochRSI Settings", display = display.none)
 
// 임계값 설정
cciUpper = input.int(100, title="CCI Upper Threshold", group="Thresholds", display = display.none)
cciLower = input.int(-100, title="CCI Lower Threshold", group="Thresholds", display = display.none)
chopTrendThresh = input.float(45.0, title="CHOP Trend Threshold (Strong < )", group="Thresholds", display = display.none)
chopChoppyThresh = input.float(61.8, title="CHOP Choppy Threshold (Consolidation > )", group="Thresholds", display = display.none)
adxTrendThresh = input.float(15.0, title="ADX Trend Minimum Strength (> )", group="Thresholds", display = display.none)
 
// --- Calculations ---
// 1. CCI & CCI-based EMA 계산
ma = ta.sma(src, cciLength)
cci = (src - ma) / (0.015 * ta.dev(src, cciLength))
cciEma = ta.ema(cci, cciEmaLength) // CCI 값을 평활화한 EMA선
 
// 2. CHOP 계산
ci = 100 * math.log10(math.sum(ta.atr(1), chopLength) / (ta.highest(chopLength) - ta.lowest(chopLength))) / math.log10(chopLength)
 
// 3. ADX 계산
up = ta.change(high)
down = -ta.change(low)
plusDM = na(up) ? na : (up > down and up > 0 ? up : 0.0)
minusDM = na(down) ? na : (down > up and down > 0 ? down : 0.0)
trur = ta.rma(ta.tr, diLength)
plus = fixnan(100 * ta.rma(plusDM, diLength) / trur)
minus = fixnan(100 * ta.rma(minusDM, diLength) / trur)
sum = plus + minus
adx = 100 * ta.rma(math.abs(plus - minus) / (sum == 0 ? 1 : sum), adxLength)
 
// 4. OBV 계산
hasVol = ta.cum(nz(volume)) > 0
volSrc = hasVol ? nz(volume) : (high - low)
obv = ta.cum(math.sign(ta.change(ohlc4)) * volSrc)
obvEma = ta.ema(obv, obvEmaLength)
 
// 5. StochRSI 계산
rsiValue = ta.rsi(ohlc4, rsiLength)
k = ta.sma(ta.stoch(rsiValue, rsiValue, rsiValue, stochLength), kSmooth)
d = ta.sma(k, dSmooth)
stochRsi = (k + d) * 0.5
 
// --- Market State 판별 (5중 복합 필터) ---
isTrendUp   = (ci < chopTrendThresh) and (adx > adxTrendThresh) and (obv > obvEma) and (stochRsi > 50)
isTrendDown = (ci < chopTrendThresh) and (adx > adxTrendThresh) and (obv < obvEma) and (stochRsi < 50)
isChoppy    = (ci > chopChoppyThresh) or (adx < adxTrendThresh)
 
// --- 색상 동적 제어 로직 ---
col = if cci >= cciUpper
    isTrendUp ? color.rgb(0, 230, 118) : (isChoppy ? color.rgb(255, 179, 0) : color.rgb(41, 98, 255))
else if cci <= cciLower
    isTrendDown ? color.rgb(255, 82, 82) : (isChoppy ? color.rgb(255, 179, 0) : color.rgb(41, 98, 255))
else
    color.new(#787B86,50)
 
// --- Plots ---
// CCI 메인 선
p2=plot(cci, "Filtered CCI", color=col, linewidth=1)
 
// CCI-based EMA 선 (노란색 평활선 추가)
p1=plot(cciEma, "CCI-based EMA", color=color.new(color.orange,10), linewidth=1, style=plot.style_line, display = display.none)
 
//cciEma1 = ta.ema(cciEma, 7) // CCI 값을 평활화한 EMA선
//p2=plot(cciEma1, "CCI-based EMA 1", color=color.new(color.blue,10), linewidth=1, style=plot.style_line, display = display.none)
 
fill(p1, p2, color=cci>cciEma?color.new(color.green,85) : cci<cciEma?color.new(color.blue,85) : color.new(color.black,100), title="CCIEma Fill")
 
//cciEma50 = ta.ema(cci, 50) // CCI 값을 평활화한 EMA선
//plot(cciEma50, "CCI-based EMA 50", color=color.new(color.black,50), linewidth=1, style=plot.style_line, display = display.none)
 
 
// 기준 밴드
band1 = hline(cciUpper, "Upper Band", color=color.rgb(120, 123, 134), linestyle=hline.style_solid)
hline(0, "Middle Band", color=color.new(color.rgb(120, 123, 134), 50))
band0 = hline(cciLower, "Lower Band", color=color.rgb(120, 123, 134), linestyle=hline.style_solid)
fill(band1, band0, color=color.rgb(33, 150, 243, 95), title="CCI Background", display = display.none)
 
// 배경색
bgcolor(isTrendUp ? color.new(color.green, 90) : (isTrendDown ? color.new(color.red, 90) : (isChoppy ? color.new(color.orange, 90) : na)), title="Market State Background")

← 返回列表