Data101
Data101

Reputation: 63

Only last week value pine script

I am trying to get only last week high/low values,NOT all weeks values

t = input(title = "study", defval="W", options=["D","W"])
shigh = security(tickerid, t, high[1], barmerge.gaps_off, barmerge.lookahead_on)
slow = security(tickerid, t, low[1], barmerge.gaps_off, barmerge.lookahead_on)
r = shigh-slow
center=(sclose)
h1=sclose + r*(1.1/12)
c5=sopen != sopen[1] ? na : red
plot(h5, title="H5",color=c5, linewidth=2)

As you can see in the chart are displayed all weeks since creation...I want only last week!not to show all of them into the chart.

Can someone show me how its done?

Upvotes: 0

Views: 1056

Answers (1)

Bjorn Mistiaen
Bjorn Mistiaen

Reputation: 6865

//@version=4
study("My Script", overlay=true)

t = input(title = "study", defval="W", options=["D","W"])

[sopen, shigh, slow, sclose] = security(syminfo.tickerid, t, [open[1], high[1],low[1],close[1]], barmerge.gaps_off, barmerge.lookahead_on)

r       = shigh-slow
center  = (sclose)
h5      = sclose + r*(1.1/12)
c5      = sopen != sopen[1] ? na : color.red

plot(h5, title="H5",color=c5, linewidth=2)

Update: only show current week.

//@version=4
study("My Script", overlay=true)

t = input(title = "study", defval="W", options=["D","W"])

thisweek = year(timenow) == year(time) and weekofyear(timenow) == weekofyear(time)

[sopen, shigh, slow, sclose] = security(syminfo.tickerid, t, [open[1], high[1],low[1],close[1]], barmerge.gaps_off, barmerge.lookahead_on)

r       = shigh-slow
center  = (sclose)
h5      = sclose + r*(1.1/12)
c5      = sopen != sopen[1] ? na : color.red

plot(thisweek ? h5 : na, title="H5",color=c5, linewidth=2)

Upvotes: 1

Related Questions