user2883072
user2883072

Reputation: 257

Previous week open and close in a pine script

new to pine. I can get the open/close of the previous trading day no problem as follows:

openprice = request.security(syminfo.tickerid, "D", open[1])

But what I want is the previous weeks open and close. So if today is Wednesday I'm looking for the close on the previous friday.

Upvotes: 2

Views: 776

Answers (1)

vitruvius
vitruvius

Reputation: 21332

The second parameter of the security() is tiemframe.

timeframe (simple string) Timeframe of the requested data. To use the chart's timeframe, use an empty string or the timeframe.period variable. Valid timeframe strings are documented in the User Manual's Timeframes page.

So, you can pass "W" for weekly data.

weekly_close = request.security(syminfo.tickerid, "W", close[1])

Upvotes: 2

Related Questions