Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

time - 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?

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
//@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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...