RicardoSantos

Function Bezier Curve

EXPERIMENTAL:
Function for drawing Bezier Curves.
the 4 points should act as a deformable rectangle:
B------C
|...........|
A.........D

percent of time is a value 0->1 representing the percentage of time traveled.
Open-source Skript

Ganz im Spirit von TradingView hat der Autor dieses Skripts es als Open-Source veröffentlicht, damit Trader es besser verstehen und überprüfen können. Herzlichen Glückwunsch an den Autor! Sie können es kostenlos verwenden, aber die Wiederverwendung dieses Codes in einer Veröffentlichung unterliegt den Hausregeln. Sie können es als Favoriten auswählen, um es in einem Chart zu verwenden.

Haftungsausschluss

Die Informationen und Veröffentlichungen sind nicht als Finanz-, Anlage-, Handels- oder andere Arten von Ratschlägen oder Empfehlungen gedacht, die von TradingView bereitgestellt oder gebilligt werden, und stellen diese nicht dar. Lesen Sie mehr in den Nutzungsbedingungen.

Möchten Sie dieses Skript auf einem Chart verwenden?
study("Function Bezier Curve", overlay=true)
useHA = input(false, title='Use Heikken Ashi Candles')
useAltTF = input(true, title='Use Alt Timeframe')
tf = input('D', title='Alt Timeframe')
zigzag() =>
    _isUp = close >= open
    _isDown = close <= open
    _direction = _isUp[1] and _isDown ? -1 : _isDown[1] and _isUp ? 1 : nz(_direction[1])
    _zigzag = _isUp[1] and _isDown and _direction[1] != -1 ? highest(2) : _isDown[1] and _isUp and _direction[1] != 1 ? lowest(2) : na

_ticker = useHA ? heikenashi(tickerid) : tickerid
sz = useAltTF ? (change(time(tf)) != 0 ? security(_ticker, tf, zigzag()) : na) : zigzag()

plot(sz, title='zigzag', color=black, linewidth=2)


pb = valuewhen(sz, sz, 2) 
pc = valuewhen(sz, sz, 1) 
pd = valuewhen(sz, sz, 0)
tb = valuewhen(sz, n, 2) 
tc = valuewhen(sz, n, 1) 
td = valuewhen(sz, n, 0)

//  ||  Function for drawing Bezier Curves:
//  ||  y = price scale
//  ||  (percentage of time, start point, start control point, end control point, end point)
f_CalculateBezierPoint(_percent, _p0_y, _p1_y, _p2_y, _p3_y)=>
    _u = 1 - _percent
    _tt = pow(_percent, 2)
    _uu = _u * _u
    _uuu = _uu * _u
    _ttt = _tt * _percent
    _p_y1 = _uuu * _p0_y //first term
    _p_y2 = _p_y1 + 3 * _uu * _percent * _p1_y //second term
    _p_y3 = _p_y2 + 3 * _u * _tt * _p2_y //third term
    _p_y4 = _p_y3 + _ttt * _p3_y //fourth term
    _return = _p_y4

//  Input Variables:
perc = (n-td)/(td-tc)
p0_start = pd
p0_control = pd > pc ? pd+(pd-pc) : pd-(pd-pc)
p1_control = pd > pc ? pc+(pd-pc)*-2 : pc-(pd-pc)*2
p1_end = pc
//  Output Variables:
lin_y = f_CalculateBezierPoint(perc, p0_start, p0_control, p1_control, p1_end)
lin_y0 = lin_y - (pd-pc)*0.618
lin_y1 = lin_y + (pd-pc)*0.618
//  Output:
p0 = plot(change(pd)!=0?na:lin_y, style=linebr, color=navy)
p1 = plot(change(pd)!=0?na:lin_y0, style=linebr, color=navy)
p2 = plot(change(pd)!=0?na:lin_y1, style=linebr, color=navy)
fill(p0, p1, color=black, transp=25)
fill(p0, p2, color=black, transp=50)