//@version=4
study("Rumpy's D/W Autofibs", shorttitle="RUMPYS_DW_AUTOFIBS", overlay=true)
dispdfibs = input(true, title="Display Daily Fibs?")
dispwfibs = input(true, title="Display Weekly Fibs?")
dhigh = security(syminfo.tickerid, "D", high)
dlow = security(syminfo.tickerid, "D", low)
whigh = security(syminfo.tickerid, "W", high)
wlow = security(syminfo.tickerid, "W", low)
newdint = dayofweek != dayofweek[1]
newwint = dayofweek == dayofweek.monday and dayofweek[1] == dayofweek.sunday
dh= 0.0
dh := newdint ? dhigh : dh[1]
dl = 0.0
dl := newdint ? dlow : dl[1]
wh = 0.0
wh := newwint ? whigh : wh[1]
wl = 0.0
wl := newwint ? wlow : wl[1]
//-------------------
d_diff = dh - dl
w_diff = wh - wl
d_236 = d_diff * 0.236
d_382 = d_diff * 0.382
d_500 = d_diff * 0.5
d_618 = d_diff * 0.618
d_786 = d_diff * 0.786
d_1272 = d_diff * 1.272
d_1414 = d_diff * 1.414
d_1618 = d_diff * 1.618
d_2000 = d_diff * 2.000
// Daily internal fibs
dfib1 = plot(dl != dl[1] ? na : dispdfibs ? dl : na, style=plot.style_linebr, color=color.red, linewidth=2, title="Daily Bottom")
dfib2 = plot(dl != dl[1] ? na : dispdfibs ? dl + d_236 : na, style=plot.style_linebr, color=color.gray, linewidth=1, title="Daily .236")
dfib3 = plot(dl != dl[1] ? na : dispdfibs ? dl + d_382 : na, style=plot.style_linebr, color=color.gray, linewidth=1, title="Daily .382")
dfib4 = plot(dl != dl[1] ? na : dispdfibs ? dl + d_500 : na, style=plot.style_linebr, color=color.yellow, linewidth=1, title="Daily .5")
dfib5 = plot(dl != dl[1] ? na : dispdfibs ? dl + d_618 : na, style=plot.style_linebr, color=color.gray, linewidth=1, title="Daily .618")
dfib6 = plot(dl != dl[1] ? na : dispdfibs ? dl + d_786 : na, style=plot.style_linebr, color=color.gray, linewidth=1, title="Daily .786")
dfib7 = plot(dl != dl[1] ? na : dispdfibs ? dh : na, style=plot.style_linebr, color=color.lime, linewidth=2, title="Daily Top")
//--------------------
// Daily upper fibs
dfib8 = plot(dl != dl[1] ? na : dispdfibs ? dl + d_1272 : na, style=plot.style_linebr, color=color.gray, linewidth=1, title="Daily Upper 1.272")
dfib9 = plot(dl != dl[1] ? na : dispdfibs ? dl + d_1414 : na, style=plot.style_linebr, color=color.gray, linewidth=1, title="Daily Upper 1.414")
dfib10 = plot(dl != dl[1] ? na : dispdfibs ? dl + d_1618 : na, style=plot.style_linebr, color=color.gray, linewidth=1, title="Daily Upper 1.618")
dfib11 = plot(dl != dl[1] ? na : dispdfibs ? dl + d_2000 : na, style=plot.style_linebr, color=color.teal, linewidth=2, title="Daily Upper 2.0")
//--------------------
// Daily lower fibs
dfib12 = plot(dl != dl[1] ? na : dispdfibs ? dh - d_1272 : na, style=plot.style_linebr, color=color.gray, linewidth=1, title="Daily Lower 1.272")
dfib13 = plot(dl != dl[1] ? na : dispdfibs ? dh - d_1414 : na, style=plot.style_linebr, color=color.gray, linewidth=1, title="Daily Lower 1.414")
dfib14 = plot(dl != dl[1] ? na : dispdfibs ? dh - d_1618 : na, style=plot.style_linebr, color=color.gray, linewidth=1, title="Daily Lower 1.618")
dfib15 = plot(dl != dl[1] ? na : dispdfibs ? dh - d_2000 : na, style=plot.style_linebr, color=color.orange, linewidth=2, title="Daily Lower 2.0")
//--------------------
w_236 = w_diff * 0.236
w_382 = w_diff * 0.382
w_500 = w_diff * 0.5
w_618 = w_diff * 0.618
w_786 = w_diff * 0.786
w_1272 = w_diff * 1.272
w_1414 = w_diff * 1.414
w_1618 = w_diff * 1.618
w_2000 = w_diff * 2.000
// Weekly internal fibs
wfib1 = plot(wl != wl[1] ? na : dispwfibs ? wl : na, style=plot.style_linebr, color=color.red, linewidth=4, title="Weekly Bottom")
wfib2 = plot(wl != wl[1] ? na : dispwfibs ? wl + w_236 : na, style=plot.style_linebr, color=color.gray, linewidth=2, title="Weekly .236")
wfib3 = plot(wl != wl[1] ? na : dispwfibs ? wl + w_382 : na, style=plot.style_linebr, color=color.gray, linewidth=2, title="Weekly .382")
wfib4 = plot(wl != wl[1] ? na : dispwfibs ? wl + w_500 : na, style=plot.style_linebr, color=color.yellow, linewidth=2, title="Weekly .5")
wfib5 = plot(wl != wl[1] ? na : dispwfibs ? wl + w_618 : na, style=plot.style_linebr, color=color.gray, linewidth=2, title="Weekly .618")
wfib6 = plot(wl != wl[1] ? na : dispwfibs ? wl + w_786 : na, style=plot.style_linebr, color=color.gray, linewidth=2, title="Weekly .786")
wfib7 = plot(wl != wl[1] ? na : dispwfibs ? wh : na, style=plot.style_linebr, color=color.lime, linewidth=4, title="Weekly Top")
//--------------------
// Weekly upper fibs
wfib8 = plot(wl != wl[1] ? na : dispwfibs ? wl + w_1272 : na, style=plot.style_linebr, color=color.gray, linewidth=2, title="Weekly Upper 1.272")
wfib9 = plot(wl != wl[1] ? na : dispwfibs ? wl + w_1414 : na, style=plot.style_linebr, color=color.gray, linewidth=2, title="Weekly Upper 1.414")
wfib10 = plot(wl != wl[1] ? na : dispwfibs ? wl + w_1618 : na, style=plot.style_linebr, color=color.gray, linewidth=2, title="Weekly Upper 1.618")
wfib11 = plot(wl != wl[1] ? na : dispwfibs ? wl + w_2000 : na, style=plot.style_linebr, color=color.teal, linewidth=4, title="Weekly Upper 2.0")
//--------------------
// Weekly lower fibs
wfib12 = plot(wl != wl[1] ? na : dispwfibs ? wh - w_1272 : na, style=plot.style_linebr, color=color.gray, linewidth=2, title="Weekly Lower 1.272")
wfib13 = plot(wl != wl[1] ? na : dispwfibs ? wh - w_1414 : na, style=plot.style_linebr, color=color.gray, linewidth=2, title="Weekly Lower 1.414")
wfib14 = plot(wl != wl[1] ? na : dispwfibs ? wh - w_1618 : na, style=plot.style_linebr, color=color.gray, linewidth=2, title="Weekly Lower 1.618")
wfib15 = plot(wl != wl[1] ? na : dispwfibs ? wh - w_2000 : na, style=plot.style_linebr, color=color.orange, linewidth=4, title="Weekly Lower 2.0")
//--------------------