I proposed you an algorithm that we used tons of times, and it is working very well.
Of course you must init the vars' values.
The very first "actual" value should match the ADC read.
If you own an Excel-like tool, try that function on the cells.
I wasn't suggesting the algorithm doesn't work. Just that it seemed like the variable was uninitialized in the sample you attached.
I'll give your suggestion a try.