Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

question from:https://stackoverflow.com/questions/65867916/only-last-week-value-pine-script

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.5k views
Welcome To Ask or Share your Answers For Others

1 Answer

//@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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...