本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=3
//Coded by: Dhilip
study(title="Auto Fibonacci Retracament Levels", shorttitle="Fibo", overlay=true)
FPeriod = input(100, title="Fibo Period")
plotF1382 = input(title="Plot 1.382 Level?", type=bool, defval=true)
plotF1618 = input(title="Plot 1.618 Level?", type=bool, defval=true)
plotF2618 = input(title="Plot 2.618 Level?", type=bool, defval=true)
plotF236 = input(title="Plot 0.236 Level?", type=bool, defval=true)
plotF382 = input(title="Plot 0.382 Level?", type=bool, defval=true)
plotF786 = input(title="Plot 0.786 Level?", type=bool, defval=true)
plotFE382 = input(title="Plot -0.382 Level?", type=bool, defval=true)
plotFE618 = input(title="Plot -0.618 Level?", type=bool, defval=true)
plotFE1618 = input(title="Plot -1.618 Level?", type=bool, defval=true)
Fhigh = security(tickerid, 'D', high[1])
Flow = security(tickerid, 'D', low[1])
F_Close = security(tickerid, 'D', close[1])
F_Open = security(tickerid, 'D', open[1])
FH=highestbars(high[1],FPeriod)
FL=lowestbars(low[1],FPeriod)
downfibo = FH < FL
FE382 = downfibo ? (Fhigh-Flow)*(-0.382)+Flow : Fhigh-(Fhigh-Flow)*(-0.382)
FE618 = downfibo ? (Fhigh-Flow)*(-0.618)+Flow : Fhigh-(Fhigh-Flow)*(-0.618)
FE1618 = downfibo ? (Fhigh-Flow)*(-1.618)+Flow : Fhigh-(Fhigh-Flow)*(-1.618)
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
F1382 = downfibo ? (Fhigh-Flow)*1.382+Flow : Fhigh-(Fhigh-Flow)*1.382
F1618 = downfibo ? (Fhigh-Flow)*1.618+Flow : Fhigh-(Fhigh-Flow)*1.618
F2618 = downfibo ? (Fhigh-Flow)*2.618+Flow : Fhigh-(Fhigh-Flow)*2.618
Fcolor = downfibo ? #b0b5b4 : #b0b5b4
Foffset = downfibo ? FH : FL
plot(plotFE382 and FE382 ? FE382 : na,color=Fcolor,linewidth=1,trackprice=true,show_last=1,title='-0.382',transp=0)
plot(plotFE618 and FE618 ? FE618 : na,color=Fcolor,linewidth=1,trackprice=true,show_last=1,title='-0.618',transp=0)
plot(plotFE1618 and FE1618 ? FE1618 : na,color=Fcolor,linewidth=1,trackprice=true,show_last=1,title='-1.618',transp=0)
plot(F0,color=Fcolor,linewidth=2,trackprice=true,show_last=1,title='0',transp=0)
plot(plotF236 and F236 ? F236 : na,color=Fcolor,linewidth=1,trackprice=true,show_last=1,title='0.236',transp=0)
plot(plotF382 and F382 ? F382 : na,color=Fcolor,linewidth=1,trackprice=true,show_last=1,title='0.382',transp=0)
plot(F500,color=Fcolor,linewidth=2,trackprice=true,show_last=1,title='0.5',transp=0)
plot(F618,color=Fcolor,linewidth=1,trackprice=true,show_last=1,title='0.618',transp=0)
plot(plotF786 and F786 ? F786 : na,color=Fcolor,linewidth=1,trackprice=true,show_last=1,title='0.786',transp=0)
plot(F1000,color=Fcolor,linewidth=2,trackprice=true,show_last=1,title='1',transp=0)
plot(plotF1382 and F1382 ? F1382 : na,color=Fcolor,linewidth=1,trackprice=true,show_last=1,title='1.382',transp=0)
plot(plotF1618 and F1618 ? F1618 : na,color=Fcolor,linewidth=1,trackprice=true,show_last=1,title='1.618',transp=0)
plot(plotF2618 and F2618 ? F2618 : na,color=Fcolor,linewidth=1,trackprice=true,show_last=1,title='2.618',transp=0)
plotshape(plotFE382 and FE382 ? FE382 : na,style=shape.labeldown,location=location.absolute,color=Fcolor,textcolor=black,show_last=1,text="-%38.2",offset = 15,transp=30)
plotshape(plotFE618 and FE618 ? FE618 : na,style=shape.labeldown,location=location.absolute,color=Fcolor,textcolor=black,show_last=1,text="-%61.8",offset = 15,transp=30)
plotshape(plotFE1618 and FE1618 ? FE1618 : na,style=shape.labeldown,location=location.absolute,color=Fcolor,textcolor=black,show_last=1,text="-%161.8",offset = 15,transp=30)
plotshape(F0,style=shape.labeldown,location=location.absolute,color=Fcolor,textcolor=black,show_last=1,text="%0",offset = 15,transp=30)
plotshape(plotF236 and F236 ? F236 : na,style=shape.labeldown,location=location.absolute,color=Fcolor,textcolor=black,show_last=1,text="%23.6",offset = 15,transp=30)
plotshape(plotF382 and F382 ? F382 : na,style=shape.labeldown,location=location.absolute,color=Fcolor,textcolor=black,show_last=1,text="%38.2",offset = 15,transp=30)
plotshape(F500,style=shape.labeldown,location=location.absolute,color=Fcolor,textcolor=black,show_last=1,text="%50",offset = 15,transp=30)
plotshape(F618,style=shape.labeldown,location=location.absolute,color=Fcolor,textcolor=black,show_last=1,text="%61.8",offset = 15,transp=30)
plotshape(plotF786 and F786 ? F786 : na,style=shape.labeldown,location=location.absolute,color=Fcolor,textcolor=black,show_last=1,text="%78.6",offset = 15,transp=30)
plotshape(F1000,style=shape.labeldown,location=location.absolute,color=Fcolor,textcolor=black,show_last=1,text="%100",offset = 15,transp=30)
plotshape(plotF1382 and F1382 ? F1382 : na,style=shape.labeldown,location=location.absolute,color=Fcolor,textcolor=black,show_last=1,text="%138.2",offset = 15,transp=30)
plotshape(plotF1618 and F1618 ? F1618 : na,style=shape.labeldown,location=location.absolute,color=Fcolor,textcolor=black,show_last=1,text="%161.8",offset = 15,transp=30)
plotshape(plotF2618 and F2618 ? F2618 : na,style=shape.labeldown,location=location.absolute,color=Fcolor,textcolor=black,show_last=1,text="%261.8",offset = 15,transp=30)
//plotshape(Flow,style=shape.labeldown,location=location.absolute,size= size.large,color=yellow,textcolor=black,show_last=1,text="Low",offset = FL,transp=0)
//plotshape(Fhigh,style=shape.labeldown,location=location.absolute,size= size.large,color=yellow,textcolor=black,show_last=1,text="High",offset = FH,transp=0)