0

I've this issue in my script code. The abc indicator each bar is a sum of value of abc on previous bar + the value of formula volume*(close - close[1])/close[1]

I don't undrstand why plotting abc I've alway zero value

//@version=5
indicator("myscript")
var abc = 0.0

abc := abc + volume*(close - close[1])/close[1]    
plot(abc, title="abc")

Any ideas and explanation for this behaviours?

Michel_T.
  • 2,741
  • 5
  • 21
  • 31
Gulymin
  • 11
  • 1
  • Might be helpful to tag this question with a language. – CollinD Aug 30 '22 at 22:20
  • I suppose volume might be zero and that results in abc equals zero. Check it out on another symbol. – Michel_T. Aug 31 '22 at 00:26
  • Volume is not zero.br/ abc := volume*(close - close[1])/close[1] done a correct plot abc := abc + volume*(close - close[1])/close[1] return always zero – Gulymin Aug 31 '22 at 01:54

1 Answers1

0

If you're on the first bar, close[1] is NaN. Summing NaN abc value with non-NaN values on the next bars will result in NaN anyway.

Start calculation from the bar_index 2 or use nz() function to replace NaN with zeros.


//@version=5
indicator("myscript")
var abc = 0.0

abc := abc + nz(volume*(close - close[1])/close[1])    
plot(abc, title="abc")

Starr Lucky
  • 1,578
  • 1
  • 7
  • 8