1
votes

I'm trying this:

study("Hourly Returns")

close_prev = close[1]

return = return[1] + ( (close_prev - close) / close *100 )

plot(return)

But it displays nothing on the indicator.

The return[1] term is the problem, without that it shows the daily return but I'm trying to figure out how do a running total

2

2 Answers

2
votes

You can use two different approaches, one using any starting value like for example 100 and then calculate total return each hour by dividing present value by 100 or just use different formula. As I understand return[1] stands for previous return then:

presentReturn = (close - close_prev) / close_prev
return = presentReturn + return[1] * (1 + presentReturn)
0
votes

Maybe you can try using the mutable operator: ":=" instead of "=" and initialize it first with some value (like 0) Another option could be to use "cum" function: https://www.tradingview.com/study-script-reference/#fun_cum