RicardoSantos

[RS]Simple ZigZag V2

EXPERIMENTAL: Method to improve the zigzag, best method so far...
開源腳本

本著真正的TradingView精神,該腳本的作者將其開源發布,以便交易者可以理解和驗證它。為作者喝彩吧!您可以免費使用它,但在出版物中重複使用此代碼受網站規則的約束。 您可以收藏它以在圖表上使用。

免責聲明

這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。

想在圖表上使用此腳本?
study("[RS]Simple ZigZag V2", overlay=true)
TF = input('240')

f_zigzag(_TF)=>
    _hh = security(tickerid, _TF, high)
    _ll = security(tickerid, _TF, low)
    _output = high >= _hh ? high : low <= _ll ? low : na
f_tops(_TF)=>
    _hh = security(tickerid, _TF, high)
    _ll = security(tickerid, _TF, low)
    _output = high >= _hh ? high : na
f_bots(_TF)=>
    _hh = security(tickerid, _TF, high)
    _ll = security(tickerid, _TF, low)
    _output = low <= _ll ? low : na

tops = f_tops(TF)
bots = f_bots(TF)
zigzag = f_zigzag(TF)

plot(tops, color=gray, linewidth=2)
plot(bots, color=gray, linewidth=2)
plot(zigzag, color=black, linewidth=3)

f_fix_zigzag(_zigzag)=>
    _hh = _zigzag ? close : high >= nz(_hh[1]) ? highest(2) : nz(_hh[1])
    _ll = _zigzag ? close : low <= nz(_ll[1]) ? lowest(2) : nz(_ll[1])
    _isBhigh = valuewhen(_zigzag, _zigzag >= high, 1)
    _isChigh = valuewhen(_zigzag, _zigzag >= high, 0)
    _isBlow = valuewhen(_zigzag, _zigzag <= low, 1)
    _isClow = valuewhen(_zigzag, _zigzag <= low, 0)
    _output = _zigzag and _isBhigh and _isChigh ? _ll[1] :_zigzag[1] and _isBhigh[1] and _isChigh[1] ? _hh :
        _zigzag and _isBlow and _isClow ? _hh[1] : _zigzag[1] and _isBlow[1] and _isClow[1] ? _ll : _zigzag

fix_zz = f_fix_zigzag(zigzag)
plot(fix_zz, color=aqua, linewidth=2)

last_zz_a = valuewhen(zigzag, zigzag, 2)
last_zz_b = valuewhen(zigzag, zigzag, 1)
last_zz_c = valuewhen(zigzag, zigzag, 0)

ab_dif = abs(last_zz_a-last_zz_b)
bc_dif = abs(last_zz_b-last_zz_c)

fib1 = last_zz_c >= high ? last_zz_c - ab_dif : last_zz_c <= low ? last_zz_c + ab_dif : nz(fib1[1])
fib2 = last_zz_c >= high ? last_zz_c - bc_dif : last_zz_c <= low ? last_zz_c + bc_dif : nz(fib2[1])
plot(fib1, color=gray, style=cross, linewidth=1)
plot(fib2, color=silver, style=cross, linewidth=1)