本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © eykpunter
//@version=4
study(title="Keltner Center Of Gravity Channel", shorttitle="Keltcog", overlay=true)
per=input(title="#lookback", type=input.integer, defval=21)
dis=atr(per) //Kelner channels have lines spaced by average true range
horizontal=false //Initialize horizontal boolean. New values only calculated when the COG (Center of Gravity) changes
donhigh=highest(high,per) //COG calculated using values of Donchian channel
donlow=lowest(low,per)
donrange=donhigh-donlow
coglow=donlow+donrange*0.382 //Actually a Center Low fibonacci line in my donchian fibonacci channel
coghigh=donlow+donrange*0.618 //center high fibonacci
innerhigh=coghigh //initialize first Keltner line above COG
outerhigh=coghigh //initialize second Keltner line abvoe COG
innerlow=coglow //initialize first Keltner below COG
outerlow=coglow //initialize second Kelner below COG
horizontal:=coglow==coglow[1]?true:false //set horizontal COG changes result in Keltner changes, otherwize Keltner is horizontal
innerhigh:=horizontal?innerhigh[1]:coghigh+0.5*dis //set innerhigh using horizontal as criterium
outerhigh:=horizontal?outerhigh[1]:coghigh+2.5*dis //set outerhigh using horizontal
innerlow:=horizontal?innerlow[1]:coglow-0.5*dis //set innerlow using horizontal
outerlow:=horizontal?outerlow[1]:coglow-2.5*dis //set outerlow using horizontal
//define plots
pohi=plot(outerhigh, title="outerhigh", color=color.new(color.purple, 30))
pihi=plot(innerhigh, title="innerhigh", color=color.new(color.blue, 30))
pchi=plot(coghigh,title="coghigh", color=color.new(color.gray, 20))
pclo=plot(coglow, title="coglow", color=color.new(color.gray, 20))
pilo=plot(innerlow, title="innerlow", color=color.new(color.red, 30))
polo=plot(outerlow, title="outerlow", color=color.new(color.purple, 30))
//define fills
fill(pohi,pihi, title="uptrend area", color=color.new(color.blue, 70))
fill(pchi,pclo,title="center area", color=color.new(color.gray, 60))
fill(pilo,polo, title="downtrend area", color=color.new(color.red, 70))