Fib Levels

ar_volumetrader · study · 68 行 · 点赞 932 · TradingView 原页

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

Pine Script

//@version=4
study("Fib Levels", overlay=true)
 
High = security(syminfo.ticker, "D", high[0], barmerge.gaps_off, barmerge.lookahead_on)
Low = security(syminfo.ticker, "D", low[0], barmerge.gaps_off, barmerge.lookahead_on)
Close = security(syminfo.ticker, "D", close[0], barmerge.gaps_off, barmerge.lookahead_on)
Open = security(syminfo.ticker, "D", open[0], barmerge.gaps_off, barmerge.lookahead_on)
start = security(syminfo.ticker, "D", time, barmerge.gaps_off, barmerge.lookahead_on)
last = security(syminfo.ticker, "D", valuewhen(barstate.islast, time, 0), barmerge.gaps_off, barmerge.lookahead_on)
newDay = change(start)
 
F1 = 0.0
F7 = 0.0
F2 = 0.0
F3 = 0.0
F4 = 0.0
F5 = 0.0
F6 = 0.0
F8 = 0.0
F9 = 0.0
F10 = 0.0
 
lastDay = start >= last
 
if Close >= Open
    F1 := High
    F7 := Low
    F2 := High - 0.236 * abs(High - Low)
    F3 := High - 0.382 * abs(High - Low)
    F4 := High - 0.5 * abs(High - Low)
    F5 := High - 0.618 * abs(High - Low)
    F6 := High - 0.786 * abs(High - Low)
    F8 := High - 1.386 * abs(High - Low)
    F9 := High - 1.618 * abs(High - Low)
    F10 := High - 2 * abs(High - Low)
else
    F1 := Low
    F7 := High
    F2 := Low + 0.236 * abs(High - Low)
    F3 := Low + 0.382 * abs(High - Low)
    F4 := Low + 0.5 * abs(High - Low)
    F5 := Low + 0.618 * abs(High - Low)
    F6 := Low + 0.786 * abs(High - Low)
    F8 := Low + 1.386 * abs(High - Low)
    F9 := Low + 1.618 * abs(High - Low)
    F10 := Low + 2 * abs(High - Low)
 
plotshape(F1, color=na, text="0.0", textcolor=#808080, transp=0, location=location.absolute, show_last=1, editable=0, offset=1)
plotshape(F2, color=na, text="0.236", textcolor=#a61c00, transp=0, location=location.absolute, show_last=1, editable=0, offset=1)
plotshape(F3, color=na, text="0.382", textcolor=#95cc28, transp=0, location=location.absolute, show_last=1, editable=0, offset=1)
plotshape(F4, color=na, text="0.5", textcolor=#28cc28, transp=0, location=location.absolute, show_last=1, editable=0, offset=1)
plotshape(F5, color=na, text="0.618", textcolor=#28cc95, transp=0, location=location.absolute, show_last=1, editable=0, offset=1)
plotshape(F6, color=na, text="0.786", textcolor=#2895cc, transp=0, location=location.absolute, show_last=1, editable=0, offset=1)
plotshape(F7, color=na, text="1.0", textcolor=#808080, transp=0, location=location.absolute, show_last=1, editable=0, offset=1)
plotshape(F8, color=na, text="1.386", textcolor=#82CA89, transp=0, location=location.absolute, show_last=1, editable=0, offset=1)
plotshape(F9, color=na, text="1.618", textcolor=#F32C42, transp=0, location=location.absolute, show_last=1, editable=0, offset=1)
plotshape(F10, color=na, text="2.0", textcolor=#2796ED, transp=0, location=location.absolute, show_last=1, editable=0, offset=1)
 
plot(lastDay ? F1 : na, title="0.0", color=#808080, transp=0, linewidth=1, trackprice=1)
plot(lastDay ? F2 : na, title="0.236", color=#a61c00, transp=0, linewidth=1, trackprice=1)
plot(lastDay ? F3 : na, title="0.382", color=#95cc28, transp=0, linewidth=1, trackprice=1)
plot(lastDay ? F4 : na, title="0.5", color=#28cc28, transp=0, linewidth=1, trackprice=1)
plot(lastDay ? F5 : na, title="0.618", color=#28cc95, transp=0, linewidth=1, trackprice=1)
plot(lastDay ? F6 : na, title="0.786", color=#2895cc, transp=0, linewidth=1, trackprice=1)
plot(lastDay ? F7 : na, title="1.0", color=#808080, transp=0, linewidth=1, trackprice=1)
plot(lastDay ? F8 : na, title="1.386", color=#82CA89, transp=0, linewidth=1, trackprice=1)
plot(lastDay ? F9 : na, title="1.618", color=#F32C42, transp=0, linewidth=1, trackprice=1)
plot(lastDay ? F10 : na, title="2.0", color=#2796ED, transp=0, linewidth=1, trackprice=1)

← 返回列表