Reputation: 28
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
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