I'm trying to make an indicator that identifies the High/Low range of every Sunday/Monday and plots horizontal lines from those high/low price points for the entire week.
I've come up with something that works, but I know it's not the right way to go about this. However, here's what I want the end result to look like: S/M High/Low Example
I've modified someone else's code that plots the high/low of every Sun/Mon and I've duplicated the "plot" and added an offset to paste it over every day of the week. I know this isn't the right way to go about it, as I would rather plot a single solid line for every week. Here is my code. Any help is highly appreciated.
Code:
//@version=2
//title
study(title="SM_Range", shorttitle="SM_Range", overlay=true)
wid = input(1, minval=1, title="Line Width")
tra = input(0, minval=0, title="Line Opacity")
sty = linebr
clr = black
mon = 0
tue = 0
wed = 0
thu = 0
fri = 0
// holds the daily price levels
highPrice = security(tickerid, 'D', high)
lowPrice = security(tickerid, 'D', low)
//adjust lines "offset" per timeframe
if (period == "5")
tue := 289
wed := 578
thu := 867
fri := 1156
if (period == "15")
tue := 96
wed := 192
thu := 288
fri := 384
if (period == "30")
mon := 0
tue := 48
wed := 96
thu := 144
fri := 192
if (period == "60")
tue := 24
wed := 48
thu := 72
fri := 96
if (period == "120")
tue := 11
wed := 22
thu := 33
fri := 44
//function which is called by plot to establish day of the week is monday return true or false
isMonday() => dayofweek(time('D')) == sunday ? 1 : 0
// Monday Plot
mh = plot(isMonday() and highPrice ? highPrice: na, title="Monday High", style=sty, offset=mon, linewidth=wid, color=clr, transp=tra)
ml = plot(isMonday() and lowPrice ? lowPrice : na, title="Monday Low", style=sty, offset=mon, linewidth=wid, color=clr, transp=tra)
fill(mh, ml, color=blue)
// Tuesday Plot
th = plot(isMonday() and highPrice ? highPrice: na, title="Monday High", style=sty, offset=tue, linewidth=wid, color=clr, transp=tra)
tl = plot(isMonday() and lowPrice ? lowPrice : na, title="Monday Low", style=sty, offset=tue, linewidth=wid, color=clr, transp=tra)
//fill(th, tl, color=orange)
// Wednesday Plot
wh = plot(isMonday() and highPrice ? highPrice: na, title="Monday High", style=sty, offset=wed, linewidth=wid, color=clr, transp=tra)
wl = plot(isMonday() and lowPrice ? lowPrice : na, title="Monday Low", style=sty, offset=wed, linewidth=wid, color=clr, transp=tra)
//fill(wh, wl, color=orange)
// Thursday Plot
thh = plot(isMonday() and highPrice ? highPrice: na, title="Monday High", style=sty, offset=thu, linewidth=wid, color=clr, transp=tra)
thl = plot(isMonday() and lowPrice ? lowPrice : na, title="Monday Low", style=sty, offset=thu, linewidth=wid, color=clr, transp=tra)
//fill(thh, thl, color=orange)
// Friday Plot
fh = plot(isMonday() and highPrice ? highPrice: na, title="Monday High", style=sty, offset=fri, linewidth=wid, color=clr, transp=tra)
fl = plot(isMonday() and lowPrice ? lowPrice : na, title="Monday Low", style=sty, offset=fri, linewidth=wid, color=clr, transp=tra)
//fill(fh, fl, color=red)
question from:
https://stackoverflow.com/questions/65875691/pinescript-plotting-sunday-monday-high-low-for-duration-of-whole-week