0

I am calculating the percentage change between the open and current close. I want this reset to 0 start of each day. Bellow is my current code.

symbol_a = input.symbol("CME_MINI:ES1!", "Symbol 1")

daily_open_a = request.security(symbol_a, 'D', open)
current_close_a = request.security(symbol_a, '', close)

symbol_a_roc = if daily_open_a > daily_open_a[1] or daily_open_a < daily_open_a[1]
    0.00

else
    (current_close_a-daily_open_a)/daily_open_a

plot(symbol_a_roc)
Jack Mahon
  • 27
  • 6

1 Answers1

1

You can detect a new day with :

var symbol_a_roc = 0.0

if dayofmonth(time) != dayofmonth(time[1])
    symbol_a_roc := 0.0
else
    symbol_a_roc := (current_close_a-daily_open_a)/daily_open_a
G.Lebret
  • 2,826
  • 2
  • 16
  • 27