CCI Cycle

DreamsDefined · study · 43 行 · 点赞 1,800 · TradingView 原页

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

Pine Script

//@version=3
 
study(title="CCI Cycle", shorttitle="CCI Cycle", overlay=false)
 
// ------------------------------- Inputs ------------------------------- //
src = input(close, title="Source")
length=input(10)
useCurrentRes = input(true, title="Use Current Chart Resolution?")
resCustom = input("240", title="Use Different Timeframe? Uncheck Box Above")
 
res = useCurrentRes ? period : resCustom
 
// ------------------------------- CCI ------------------------------- //
ma = sma(src, length)
cci = (src - ma) / (0.015 * dev(src, length))
ccis = security(tickerid, res, rma(2*ema(cci, length/2)-ema(cci, length), round(sqrt(length))))
 
// ------------------------------- Cycle ------------------------------- //
ccic(length) => 
    factor=input(0.5)  
    m = ccis
    v1 = lowest(m, length)
    v2 = highest(m, length) - v1    
    f1 = 0.0
    f1 := (v2 > 0 ? ((m - v1) / v2) * 100 : nz(f1[1])) 
    pf = 0.0
    pf := (na(pf[1]) ? f1 : pf[1] + (factor * (f1 - pf[1]))) 
    v3 = lowest(pf, length) 
    v4 = highest(pf, length) - v3     
    f2 = 0.0
    f2  := (v4 > 0 ? ((pf - v3) / v4) * 100 : nz(f2[1])) 
    pff = 0.0
    pff := (na(pff[1]) ? f2 : pff[1] + (factor * (f2 - pff[1])))
    pff
 
CCIC = security(tickerid, res, ccic(length))
 
// ------------------------------- Plotting ------------------------------- //
 
plot(CCIC,color=red, title="CCI Cycle")
ul=plot(25)
ll=plot(75) 
fill(ul,ll,color=red)

← 返回列表