0

obv = cum(change(src) > 0 ? volume : change(src) < 0 ? -volume : 0*volume)

obv2 = cum(sign(change(src)) * volume )

obv and obv2 return different results

ta.obv(df['close'], df['volume']) returns the same result as obv2

I will also need the return value of obv calculation with talib

OBV calculation

Thanks in advance for your help.

Askeroglu
  • 1
  • 1

1 Answers1

0

I've added an OBV indicator to TradingView, opened it's sources and found

obv = ta.cum(math.sign(ta.change(src)) * volume)

Then I cloned the indicator and replaced this line with

obv = ta.cum(ta.change(src) > 0 ? volume : ta.change(src) < 0 ? -volume : 0*volume)

And added it as a second indicator. I've got a different results. But also I've got a warning:

line 9: The function 'ta.change' should be called on each calculation for consistency. It is recommended to extract the call from the ternary operator or from the scope

So, I replaced the line with

c = ta.change(src)
obv = ta.cum(c > 0 ? volume : c < 0 ? -volume : 0*volume)

And got exactly the same results as original OBV!
So your code for obv is incorrect and you shall google for explanation of this warning. For example: The function should be called on each calculation for consistency, console output?

truf
  • 2,843
  • 26
  • 39