RicardoSantos

[RS]Fractal Regression Channel V0

EXPERIMENTAL:
Fractals/fibs/linear regression
สคริปต์โอเพนซอร์ซ

ด้วยจิตวิญญาณของ TradingView อย่างแท้จริง ผู้เขียนสคริปต์นี้ได้เผยแพร่เป็นโอเพนซอร์ส เพื่อให้ผู้ค้าสามารถเข้าใจและตรวจสอบได้ ไชโยให้กับผู้เขียน! คุณสามารถใช้ได้ฟรี แต่การใช้รหัสนี้ซ้ำในสิ่งพิมพ์อยู่ภายใต้กฎระเบียบการใช้งาน คุณสามารถตั้งเป็นรายการโปรดเพื่อใช้บนชาร์ตได้

คำจำกัดสิทธิ์ความรับผิดชอบ

ข้อมูลและบทความไม่ได้มีวัตถุประสงค์เพื่อก่อให้เกิดกิจกรรมทางการเงิน, การลงทุน, การซื้อขาย, ข้อเสนอแนะ หรือคำแนะนำประเภทอื่น ๆ ที่ให้หรือรับรองโดย TradingView อ่านเพิ่มเติมที่ เงื่อนไขการใช้บริการ

ต้องการที่จะใช้สคริปต์นี้บนชาร์ตใช่ไหม?
//@version=2
study(title='[RS]Fractal Regression Channel V0', shorttitle='FRC', overlay=true)

f_falling_linear_regression(_src, _window)=>
    _h = highest(_src, _window)
    _h_fractal = _src[1] >= _h[1] and _src < _h
    _h0h = valuewhen(_h_fractal, _src[1], 0)
    _h1h = valuewhen(_h_fractal, _src[1], 1)
    _h0n = valuewhen(_h_fractal, n[1], 0)
    _h1n = valuewhen(_h_fractal, n[1], 1)
    _price_range = _h0h < _h1h ? _h0h-_h1h : _price_range[1]
    _bar_range = _h0h < _h1h ? _h0n-_h1n : _bar_range[1]
    _step = _price_range/_bar_range
    _return_regression = _h0h+(_step*(n-_h0n))
    [_h0h, _step, _return_regression]

f_rising_linear_regression(_src, _window)=>
    _l = lowest(_src, _window)
    _l_fractal = _src[1] <= _l[1] and _src > _l
    _l0l = valuewhen(_l_fractal, _src[1], 0)
    _l1l = valuewhen(_l_fractal, _src[1], 1)
    _l0n = valuewhen(_l_fractal, n[1], 0)
    _l1n = valuewhen(_l_fractal, n[1], 1)
    _price_range = _l0l > _l1l ? _l0l-_l1l : _price_range[1]
    _bar_range = _l0l > _l1l ? _l0n-_l1n : _bar_range[1]
    _step = _price_range/_bar_range
    _return_regression = _l0l+(_step*(n-_l0n))
    [_l0l, _step, _return_regression]

window = input(3)
grid_size = input(1)
[h_value, h_step, h_regression] = f_falling_linear_regression(high, window)
[l_value, l_step, l_regression] = f_rising_linear_regression(low, window)

avg_h_step = cum(h_step)/(n+1)
avg_l_step = cum(l_step)/(n+1)


h_base = na(h_base[1]) ? high : high >= h_base[1] ? high : h_base[1]+avg_h_step//high >= h_base[1] ? high : high >= h_regression ? h_base[1]-avg_h_step : h_regression
l_base = na(l_base[1]) ? low : low <= l_base[1] ? low : l_base[1]+avg_l_step//low <= l_base[1] ? low : low <= l_regression ? l_base[1]+avg_l_step : l_regression

direction = na(direction[1]) ? 1 : direction[1] < 0 and rising(l_base, 1) and not falling(h_base,1) ? 1 : direction[1] > 0 and falling(h_base, 1) and not rising(l_base,1) ? -1 : direction[1]
base0 = direction > 0 ? l_base : h_base
base = change(direction)!=0 ? na : base0
grid_block = direction > 0 ? (avg_l_step*grid_size) : (avg_h_step*grid_size)

plot(title='-1.618(-34)', series=base + grid_block*-34, style=linebr , color=direction>0?blue:fuchsia, linewidth=1)
plot(title='-0.618(-13)', series=base + grid_block*-13, style=linebr , color=direction>0?blue:fuchsia, linewidth=1)
plot(title='0(0)', series=base, style=linebr, color=black, linewidth=3)
plot(title='0.236(5)', series=base + grid_block*5, style=linebr , color=direction>0?green:maroon, linewidth=2)
plot(title='0.382(8)', series=base + grid_block*8, style=linebr , color=direction>0?green:maroon, linewidth=2)
plot(title='0.618(13)', series=base + grid_block*13, style=linebr , color=direction>0?lime:red, linewidth=1)
plot(title='1(21)', series=base + grid_block*21, style=linebr , color=direction>0?black:black, linewidth=1)
plot(title='1.618(34)', series=base + grid_block*34, style=linebr , color=direction>0?olive:orange, linewidth=1)
plot(title='2.618(55)', series=base + grid_block*55, style=linebr , color=direction>0?olive:orange, linewidth=1)
plot(title='4.272(89)', series=base + grid_block*89, style=linebr , color=direction>0?blue:fuchsia, linewidth=1)
plot(title='6.827(144)', series=base + grid_block*144, style=linebr , color=direction>0?navy:aqua, linewidth=1)