RicardoSantos

[RS]Tapestry Weaver V0

EXPERIMENTAL:Time, Fibs and Linear regression
Remove from Favorite Scripts Add to Favorite Scripts
//@version=2
study(title='[RS]Tapestry Weaver V0', shorttitle='TW', 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]

f_neg_na(_src)=>_return=change(_src)<0?na:_src
f_pos_na(_src)=>_return=change(_src)>0?na:_src
f_lr_rising(_n_start, _l, _h, _step)=>_return = na(_return[1]) ? 0 : n < _n_start ? _l : _return[1] > _h ? _l : _return[1]+_step
f_lr_falling(_n_start, _l, _h, _step)=>_return = na(_return[1]) ? 0 : n < _n_start ? _h : _return[1] < _l ? _h : _return[1]+_step

window = input(title='Lookback Window:', type=integer, defval=3)
grid_size = input(title='Grid Multiplier', type=float, defval=1)
USE_ALT_MAX = input(title='Box Maximum, (<0 = uses price High Appex):', type=float, defval=-1)
USE_ALT_MIN = input(title='Box Minimum, (<0 = uses price Low Appex):', type=float, defval=-1)
[_, l_step, _] = f_rising_linear_regression(low, window)
[_, h_step, _] = f_falling_linear_regression(high, window)
la_step = cum(l_step)/(n+1)
ha_step = cum(h_step)/(n+1)
high_extreme = USE_ALT_MAX >= 0 ? USE_ALT_MAX : na(high_extreme[1]) ? high : high >= high_extreme[1] ? high : high_extreme[1]
low_extreme = USE_ALT_MIN >= 0 ? USE_ALT_MIN : na(low_extreme[1]) ? low : low <= low_extreme[1] ? low : low_extreme[1]

r00 = f_neg_na(f_lr_rising(1, low_extreme, high_extreme, la_step))
r01 = f_neg_na(f_lr_rising(2, low_extreme, high_extreme, la_step))
r02 = f_neg_na(f_lr_rising(3, low_extreme, high_extreme, la_step))
r03 = f_neg_na(f_lr_rising(5, low_extreme, high_extreme, la_step))
r04 = f_neg_na(f_lr_rising(8, low_extreme, high_extreme, la_step))
r05 = f_neg_na(f_lr_rising(13, low_extreme, high_extreme, la_step))
r06 = f_neg_na(f_lr_rising(21, low_extreme, high_extreme, la_step))
r07 = f_neg_na(f_lr_rising(34, low_extreme, high_extreme, la_step))
r08 = f_neg_na(f_lr_rising(55, low_extreme, high_extreme, la_step))
r09 = f_neg_na(f_lr_rising(89, low_extreme, high_extreme, la_step))
r10 = f_neg_na(f_lr_rising(144, low_extreme, high_extreme, la_step))
r11 = f_neg_na(f_lr_rising(233, low_extreme, high_extreme, la_step))
r12 = f_neg_na(f_lr_rising(377, low_extreme, high_extreme, la_step))
r13 = f_neg_na(f_lr_rising(610, low_extreme, high_extreme, la_step))
r14 = f_neg_na(f_lr_rising(987, low_extreme, high_extreme, la_step))

f00 = f_pos_na(f_lr_falling(1, low_extreme, high_extreme, ha_step))
f01 = f_pos_na(f_lr_falling(2, low_extreme, high_extreme, ha_step))
f02 = f_pos_na(f_lr_falling(3, low_extreme, high_extreme, ha_step))
f03 = f_pos_na(f_lr_falling(5, low_extreme, high_extreme, ha_step))
f04 = f_pos_na(f_lr_falling(8, low_extreme, high_extreme, ha_step))
f05 = f_pos_na(f_lr_falling(13, low_extreme, high_extreme, ha_step))
f06 = f_pos_na(f_lr_falling(21, low_extreme, high_extreme, ha_step))
f07 = f_pos_na(f_lr_falling(34, low_extreme, high_extreme, ha_step))
f08 = f_pos_na(f_lr_falling(55, low_extreme, high_extreme, ha_step))
f09 = f_pos_na(f_lr_falling(89, low_extreme, high_extreme, ha_step))
f10 = f_pos_na(f_lr_falling(144, low_extreme, high_extreme, ha_step))
f11 = f_pos_na(f_lr_falling(233, low_extreme, high_extreme, ha_step))
f12 = f_pos_na(f_lr_falling(377, low_extreme, high_extreme, ha_step))
f13 = f_pos_na(f_lr_falling(610, low_extreme, high_extreme, ha_step))
f14 = f_pos_na(f_lr_falling(987, low_extreme, high_extreme, ha_step))

plot(title='+1', series=r00, style=linebr, color=black)
plot(title='+2', series=r01, style=linebr, color=black)
plot(title='+3', series=r02, style=linebr, color=black)
plot(title='+5', series=r03, style=linebr, color=black)
plot(title='+8', series=r04, style=linebr, color=black)
plot(title='+13', series=r05, style=linebr, color=black)
plot(title='+21', series=r06, style=linebr, color=black)
plot(title='+34', series=r07, style=linebr, color=black)
plot(title='+55', series=r08, style=linebr, color=black)
plot(title='+89', series=r09, style=linebr, color=black)
plot(title='+144', series=r10, style=linebr, color=black)
plot(title='+233', series=r11, style=linebr, color=black)
plot(title='+377', series=r12, style=linebr, color=black)
plot(title='+610', series=r13, style=linebr, color=black)
plot(title='+987', series=r14, style=linebr, color=black)

plot(title='-1', series=f00, style=linebr, color=black)
plot(title='-2', series=f01, style=linebr, color=black)
plot(title='-3', series=f02, style=linebr, color=black)
plot(title='-5', series=f03, style=linebr, color=black)
plot(title='-8', series=f04, style=linebr, color=black)
plot(title='-13', series=f05, style=linebr, color=black)
plot(title='-21', series=f06, style=linebr, color=black)
plot(title='-34', series=f07, style=linebr, color=black)
plot(title='-55', series=f08, style=linebr, color=black)
plot(title='-89', series=f09, style=linebr, color=black)
plot(title='-144', series=f10, style=linebr, color=black)
plot(title='-233', series=f11, style=linebr, color=black)
plot(title='-377', series=f12, style=linebr, color=black)
plot(title='-610', series=f13, style=linebr, color=black)
plot(title='-987', series=f14, style=linebr, color=black)
Alphaoptions
a year ago
Richardo - another great job. Did you notice in the tapestry there is a repeating un-plotted diagonal line pattern in the middle of each "diamond" shape? For example a look at 1996 and move upward along price to about 2002. The price pattern appears to be moving along a line that appear to be about halfway diagonally (thought the "middle" portion of the diamond). Once you see this one you can see it in many parts of the tapestry - some upsloping and some down sloping. In some places it would seem to just be a point of pause on the way up/down but either eay there might (or might not) be value in adding a plot to what you have created? Without changing anything about the current plot, would you be able to add this diagonal plot line (perhaps a different color to differentiate) and even if possible up sloping as green and down sloping as red as a suggestion? The combination of the existing plot and this add-on modification would seem to capture the fib-relationship you have plotted and perhaps and inter-relationship between the plots? Maybe if it does not add value there van be an option to turn it on/off?
Reply
Kangaroo
a year ago
really cool stuff, thanks for publishing :)
Reply
Ideas Scripts Chart
United States
United Kingdom
India
España
Italia
Brasil
Россия
Türkiye
日本
한국
Home Stock Screener Economic Calendar How It Works Chart Features House Rules Moderators For the WEB Widgets Stock Charting Library Priority Support Feature Request Blog & News FAQ Help & Wiki Twitter
Private Messages Chat Ideas Published Followers Following Priority Support Public Profile Profile Settings Billing Sign Out