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.
Script open-source

Dans le véritable esprit de TradingView, l'auteur de ce script l'a publié en open-source, afin que les traders puissent le comprendre et le vérifier. Bravo à l'auteur! Vous pouvez l'utiliser gratuitement, mais la réutilisation de ce code dans une publication est régie par le règlement. Vous pouvez le mettre en favori pour l'utiliser sur un graphique.

Clause de non-responsabilité

Les informations et les publications ne sont pas destinées à être, et ne constituent pas, des conseils ou des recommandations en matière de finance, d'investissement, de trading ou d'autres types de conseils fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.

Vous voulez utiliser ce script sur un graphique ?
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)