Moving Average Inventory Method with Transaction Revoke option.
Example 1. Calculating the Mean value of the currency
Transaction type Quantity Cost/unit Total Cost
total 1 1000 7.5 7500
sell 1 400 7.5 3000
total2 600 7.5 4500
total3 1600 9.0625 14500
now suppose because of a human error I decide to cancel the \$400 I sold. By this equation I would be at:
total after cancel 2000 8.75 17500
So the average cost/unit (mean/average don't really know how to call it) changes.
I would like to keep it at 9.0625 even after I cancel the sell transaction
Is it possible, am I making some wrong calculation?

I would only like to keep this value so that the clerk can see it for future transactions and know that
he has to make a buying transaction with a cost/unit lower than this or a selling transaction with a cost/unit above this.
This has to work even if I cancel a buying transaction.

Example 2.
Say that we have fixed this issue from above exaple. We have another problem but this time I think only when canceling a buying transaction.
Transaction type Quantity Cost/unit Total Cost
total 1 400 7.75 3100
sell 1 300 7.75 2325
total 2 100 7.75 775

the problem works fine unitll now. But lates we discover that Transaction (buy3) was a mistake
So we decide to revoke it. This brings out total under zero:
total after cancel==>>> total C -100 8.25 -825

now the cost/unit changes. The money is under zero. And if I make a buying transaction after this the cost/unit skyrockets: