jpjunho
jpjunho

Reputation: 28

Using ta.change on a lower time frame

I'm creating an indicator for a daily chart, and I want to know the price change of the last 2 hours. I tried using the following code, but it's giving incorrect values. Should I be doing something different?

request.security(syminfo.tickerid, '60', ta.change(close, 2))

Upvotes: 0

Views: 4269

Answers (2)

RaNCeR91
RaNCeR91

Reputation: 1

max change ratıo for 2 period math.max(ta.change(close), 2)

Upvotes: 0

bbnm
bbnm

Reputation: 1094

Like this?

close1 = request.security(syminfo.tickerid, '60', close)
close2 = request.security(syminfo.tickerid, '60', close[1])

priceChange = close1 - close2
priceChangeInPercent = ((close1 - close2) / close2) * 100

I mainly use ta.change() as a bool condition, never used it to calculate the difference.

Upvotes: 2

Related Questions