On Balance Volume Script

Hi all, I’m new to scripting and have been working through the training which is great.

If I was to do OBV manually (I know there is the OBV function, but I wish to change some of the internal variables) with scripting what would the code be? I can’t work out how to get it to accumulate, ie adds to the previous value.

Here is my attempt:

VAR1 = CLOSE() - OFFSET(CLOSE(), OFFSET=1);
VAR2= IF(VAR1 > 0,1,-1);
VAR3 = VAR2 * VOL();

VAR3 + OFFSET(VAR3, OFFSET=1)

I know it should be Offset=1 + Offset=2 + Offset=3 + …Offset=8425… but this doesnt work in practice as every instument has a different start date.

It would be great if someone can paste the OBV script here.

Many thanks,

Hi Liam,

That’s a pretty good way of doing it. The Accumulate function is ACC() so your last line would be ACC(V3).

Put it in a Show View tool and it will match the OBV tool, allowing you to tweak it as required.

Note the you can use CLOSE(1) for the previous close instead of using the OFFSET function, or you could remove VAR1 altogether and use the CHANGE() function in VAR2:

VAR2 = IF(CHANGE()> 0,1,-1);

Great, many thanks.