I am wondering about the OBV() logic in AB. Is it this?

```
if Close > Close[-1]: temp = +volume
if Close < Close[-1]: temp = -volume
if Close == Close: temp = 0
cumsum(temp)
```

Thanks,

John

I am wondering about the OBV() logic in AB. Is it this?

```
if Close > Close[-1]: temp = +volume
if Close < Close[-1]: temp = -volume
if Close == Close: temp = 0
cumsum(temp)
```

Thanks,

John

It is one line

```
function cOBV() {
// https://forum.amibroker.com/t/obv-logic-in-ab/23785
return Cum(sign(ROC(C,1))*V)+V[0];
}
Plot( cOBV(), "cOBV", colorOrange, styleLine );
Plot( OBV(), "OBV", colorRed, styleLine );
```

Thanks. The core logic is as I understand it should be, but why include the volume of the first bar?

Because ROC is NULL on first element.

I actually forgot to add Nz().

So here is update

```
function cOBV() {
// https://forum.amibroker.com/t/obv-logic-in-ab/23785
rc = Nz(ROC(C,1));
return Cum(sign(rc)*V) + V[0];
}
Plot( cOBV(), "cOBV", colorOrange, styleLine );
Plot( OBV(), "OBV", colorRed, styleLine );
```

3 Likes

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.