Vendrel
Vendrel

Reputation: 987

Request.security() helps to focus on a specific timeframe. How to do it alternatively to prevent 'overuse'? V5

I have boolean variables containing a huge amount of opens and closes and highs and lows (and they may still counting). I could apply a request.security() enclosure for each of them (skipping the security attribute, of course) but;

Is there a way to specify the timeframe for the whole boolean expression? E.g. (sort of)

SomethingHappened = (high > close) and (low < high) <= always in 1-min timeframe

instead of

SomethingHappened = request.security("","1",high) > request.security("","1",close) and
                    request.security("","1",low) < request.security("","1",high) 

Upvotes: 0

Views: 4285

Answers (1)

beeholder
beeholder

Reputation: 1699

You can pass any variable or function (with some exceptions) to request.security(), not just built-ins. You can pass your SomethingHappened variable directly to the request.security() and it will return you the result of the calculation from the 1m timeframe:

//@version=5
indicator("My script")
SomethingHappened = (high > close) and (low < high)// <= always in 1-min timeframe
s1 = request.security(syminfo.tickerid, "1", SomethingHappened)
plot(s1 ? 1 : 0)

Note that while requesting data from lower timeframes, some data is inevitably lost (because one bar of the main timeframe can only have one value, while the request.security() provides several for each bar). If your main chart timeframe is 10, and you request data from 1, only one in each 10 minutes will be represented on the main chart.

Upvotes: 2

Related Questions