<<Also each of the terms in the sum should be the same
VWAP :
value1= P1*square(C-VWAP) + P2*square(c[2]-VWAP) + .....>>
this is not intutive to me... I would then be comparing the current
vwap to old prices..
I am thinking about how bollinger bands work here and applying same concept. I am quite familiar with properties of bollinger bands so this is natural for me. bollinger bands compare the price to the moving average value that occured at the same time that the price occured. this is kind of like 'matching' concept in accounting.
I do not know how to code it your way so will look for others for help. But this entire line of thinking is quite stimulating for new ideas.