所以我试图找出我要去哪里。现在,我只想计算在定义的时间段内价格超过或低于斐波那契线(F0)的次数,但由于某种原因,它没有在斐波那契线附近计算蜡烛。我需要更改什么?
//@version=4
study("Crossing Count",overlay=true)
//crossValue=input(7000,"Value to count crossings of")
theSrc=input(close,"Count crossing of...")
FPeriod = input(90, title="Fibo Period")
CPeriod = input(365, title="Cross Period")
plotF1618 = input(title="Plot 1.618 Level?", defval=true)
Fhigh=highest(close, FPeriod)[1]
Flow=lowest(close, FPeriod)[1]
FH=highestbars(high,FPeriod)[1]
FL=lowestbars(low,FPeriod)[1]
downfibo = FH < FL
F0 = downfibo ? Flow : Fhigh
F236 = downfibo ? (Fhigh-Flow)*0.236+Flow : Fhigh-(Fhigh-Flow)*0.236
F382 = downfibo ? (Fhigh-Flow)*0.382+Flow : Fhigh-(Fhigh-Flow)*0.382
F500 = downfibo ? (Fhigh-Flow)*0.500+Flow : Fhigh-(Fhigh-Flow)*0.500
F618 = downfibo ? (Fhigh-Flow)*0.618+Flow : Fhigh-(Fhigh-Flow)*0.618
F786 = downfibo ? (Fhigh-Flow)*0.786+Flow : Fhigh-(Fhigh-Flow)*0.786
F1000 = downfibo ? (Fhigh-Flow)*1.000+Flow : Fhigh-(Fhigh-Flow)*1.000
F1618 = downfibo ? (Fhigh-Flow)*1.618+Flow : Fhigh-(Fhigh-Flow)*1.618
F1272 = downfibo ? (Fhigh-Flow)*1.272+Flow : Fhigh-(Fhigh-Flow)*1.272
F1414 = downfibo ? (Fhigh-Flow)*1.414+Flow : Fhigh-(Fhigh-Flow)*1.414
Fcolor = downfibo ? #00CC00 : #E41019
Foffset = downfibo ? FH : FL
plot(F0,color=#B2B5BE,linewidth=3,trackprice=true,show_last=1,title='0',transp=0)
plot(F236,color=#FF5252,linewidth=2,trackprice=true,show_last=1,title='0.236',transp=0) //red
plot(F382,color=#FFEB3B,linewidth=2,trackprice=true,show_last=1,title='0.382',transp=0)
plot(F500,color=#4CAF50,linewidth=2,trackprice=true,show_last=1,title='0.5',transp=0)
plot(F618,color=#00BCD4,linewidth=2,trackprice=true,show_last=1,title='0.618',transp=0)
plot(F786,color=#2196F3,linewidth=2,trackprice=true,show_last=1,title='0.786',transp=0)
plot(F1000,color=#B2B5BE,linewidth=2,trackprice=true,show_last=1,title='1',transp=0)
plot(F1272,color=#FFEB3B,linewidth=2,trackprice=true,show_last=1,title='1.272',transp=0)
plot(F1414,color=#FF5252,linewidth=2,trackprice=true,show_last=1,title='1.414',transp=0) //red
plot(plotF1618 and F1618 ? F1618 : na,color=#9C27B0,linewidth=2,trackprice=true,show_last=1,title='1.618',transp=0)
plotshape(Flow,style=shape.labelup,location=location.belowbar,size= size.tiny,color=#FF5252,textcolor=#000000,show_last=1,text="Low",offset = FL,transp=0)
plotshape(Fhigh,style=shape.labeldown,location=location.abovebar,size= size.tiny,color=#FF5252,textcolor=#000000,show_last=1,text="High",offset = FH,transp=0)
okToGo=(CPeriod)
crossValue=F236
var theCount=0
crossing=(high>=crossValue and low<=crossValue) or (high<=crossValue and low>=crossValue)
theCount:=nz(theCount[1],0)+(crossing?1:0)
if crossing
label.new(bar_index,crossValue,tostring(theCount),yloc=yloc.price,style=theSrc>crossValue?label.style_label_down:label.style_label_up,size=size.tiny)
您在crossing
中的条件基于F236
,而不是F0
,这就是为什么不一致的原因。这些条件也不同于使用cross
函数(该函数用于测试两个序列之间的杂交)。
附带说明,也可以通过使用以下更简单的形式来计算十字架:
counts = cum(crossing ? 1 : 0)
根据您的情况,请提供:
crossing = (high>=F0 and low<=F0) or (high<=F0 and low>=F0)
theCount = cum(crossing?1:0)
或以下代码,如果您想改为使用cross
函数:
crossing = cross(high,F0) or cross(low,F0)
theCount = cum(crossing?1:0)