OBV Column Script

Hi Everyone I am new to Optuma and very much to scripting and have been struggling with this for a while now so hope someone can help.

I would like to have a column script to show me the increase or decrease in percentage of the OBV over the last 5 bars.

I have the below so far and although working to a degree it very often returns a positive percentage when it fact it should be negative. I don’t appear to be able to get around it. I will put some examples below the script. Thanks for the help in advance. BNL was an increase but showing a decrease and the opposite for SMR

// Calculate the current OBV
CurrentOBV = OBV(); // Get the current On-Balance Volume

// Calculate the OBV from 5 bars ago
PreviousOBV = OFFSET(OBV(), OFFSET=5); // Get the OBV value from 5 bars ago

// Calculate the percentage increase in OBV
PercentageIncrease = ((CurrentOBV - PreviousOBV) / PreviousOBV) * 100; // Calculate the percentage increase

// Output the result
PercentageIncrease; // Show the final percentage increase

Its because of the negative OBV.
Using round numbers from BNL here:
~ -129,000,000 - (-125,000,000) = 4,000,000 (An increas of 4,000,000)
4,000,000/-129,000,000 = - 3.1%.

If you take the absolute (ABS()) of previous OBV it should sort you out and prevent negatives from messing with the sign.

so

PercentageIncrease = ((CurrentOBV - PreviousOBV) / ABS(PreviousOBV)) * 100;