RicardoSantos

[RS]Simple ZigZag V2

EXPERIMENTAL: Method to improve the zigzag, best method so far...
Script open-source

Nello spirito di condivisione promosso da TradingView, l'autore (al quale vanno i nostri ringraziamenti) ha deciso di pubblicare questo script in modalità open-source, così che chiunque possa comprenderlo e testarlo. Puoi utilizzarlo gratuitamente, ma il riutilizzo del codice è subordinato al rispetto del Regolamento. Per aggiungerlo al grafico, mettilo tra i preferiti.

Declinazione di responsabilità

Le informazioni ed i contenuti pubblicati non costituiscono in alcun modo una sollecitazione ad investire o ad operare nei mercati finanziari. Non sono inoltre fornite o supportate da TradingView. Maggiori dettagli nelle Condizioni d'uso.

Vuoi usare questo script sui tuoi grafici?
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)