RicardoSantos

[RS]Fractal Regression Channel V0

EXPERIMENTAL:
Fractals/fibs/linear regression
오픈 소스 스크립트

이 스크립트의 오써는 참된 트레이딩뷰의 스피릿으로 이 스크립트를 오픈소스로 퍼블리쉬하여 트레이더들로 하여금 이해 및 검증할 수 있도록 하였습니다. 오써를 응원합니다! 스크립트를 무료로 쓸 수 있지만, 다른 퍼블리케이션에서 이 코드를 재사용하는 것은 하우스룰을 따릅니다. 님은 즐겨찾기로 이 스크립트를 차트에서 쓸 수 있습니다.

면책사항

이 정보와 게시물은 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)