feder
feder

Reputation: 2058

ta.barssince for multi-time frame analysis

I'm counting on an hourly time frame the bars since the last event a condition was met. Works nicely.

ta.barssince(cond == true)

I want to do the same in the same strategy for a multi-timeframe. e.g. on a daily TF. How do I get around the fact that ta.barssince does not offer this for another time-frame than the selected one?

The only thing I can think of is to multiply all the values I have by 24.

Any smart workarounds and better ideas than the 24x?

(in case you are curious what I try to achieve: I'm trying to locate pivot points in a multi-timeframe analysis. That is hourly and daily. Thus I can incorporate bearish divergence on all levels to avoid buying in too early.)

Upvotes: 1

Views: 1893

Answers (1)

Starr Lucky
Starr Lucky

Reputation: 1951

You can calculate barssince() expression in scope of another chart TF by using request.security() function:

//@version=5
strategy("My Strategy", overlay=false, margin_long=100, margin_short=100)

cond = ta.barssince(close>open)
plot(cond) // current TF
s = request.security(syminfo.tickerid, "60", cond) 
plot(s, color = color.red)   // 1H


Upvotes: 1

Related Questions