Keltner Zones

shtcoinr · study · 70 行 · 点赞 1,420 · TradingView 原页

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

Pine Script

//@version=3
study(title="Keltner Zones", shorttitle="KZ", overlay=true)
useTrueRange    = input(true)
length          = input(20, minval=1)
mult            = input(2.25)
src             = input(close, title="Source")
count           = input(title="Congestion Counter",defval=12)
bullish         = input(title="Lower Band", type=bool, defval=false)
bearish         = input(title="Upper Band", type=bool, defval=false)
neutral         = input(title="Congestion", type=bool, defval=true)
zones           = input(title="Paint Zones?", type=bool, defval=true)
 
 
//KELTNERCHANNEL
ma = ema(src, length)
range = useTrueRange ? tr : high - low
rangema = ema(range, length)
upper = ma + rangema * mult
lower = ma - rangema * mult
    
congestionUp = ma + rangema * (mult / 2)
congestionDown = ma - rangema * (mult / 2)
 
 
incrementer = high < congestionUp and low > congestionDown and neutral ? 1 : 0 
inc = 0
if(incrementer)
    inc := nz(inc[1], 0) + incrementer
else
    inc = 0
 
n1 = if (inc >= count)
    (high + low) / 2
 
n2 = if (inc >= count) and zones
    high + tr   
 
n3 = if (inc >= count) and zones   
    low - tr
    
up1 = if close > upper and high[1] > high and bearish
    (high + low) / 2
up2 = if close > upper and high[1] > high and bearish and zones
    high + tr
up3 = if close > upper and high[1] > high and bearish and zones
    low - tr
    
dn1 = if close < lower and low[1] > low and bullish
    (high + low) / 2
dn2 = if close < lower and low[1] > low and bullish and zones
    high + tr
dn3 = if close < lower and low[1] > low and bullish and zones
    low - tr    
 
 
um = plot(fixnan(up1),style=cross)
uz1 = plot(fixnan(up2),style=cross)
uz2 = plot(fixnan(up3),style=cross)
 
dm = plot(fixnan(dn1),style=cross)
dz1 = plot(fixnan(dn2),style=cross)
dz2 = plot(fixnan(dn3),style=cross)
 
nm = plot(fixnan(n1),style=cross)
nz1 = plot(fixnan(n2),style=cross)
nz2 = plot(fixnan(n3),style=cross)
 
fill(dz1,dz2,color=#8AC926)
fill(uz1,uz2,color=#FE4A49)
fill(nz1,nz2,color=#009FB7)

← 返回列表