Moving Average Inventory Method with Transaction Revoke option.
Example 1. Calculating the Mean value of the currency
Transaction type Quantity Cost/unit Total Cost
buy 1500 5 2500
buy 2 500 10 5000
total 1 1000 7.5 7500
sell 1 400 7.5 3000
total2 600 7.5 4500
buy3 1000 10 10000
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
buy1 100 5 500
buy2 100 10 1000
buy3 200 8 1600
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:
Canceled Transaction=>>>buy3 200 8 1600
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:

buy4 300 10 3000
Total 200 10.875 2175 10.875 compared to 7.75

Is it possible to keep the cost/unit constant even after we revoke a transaction or is it impossible.If it changes that means that if I have made a buying transaction at 9.0625 and than I cancel a buying transaction of a cost/unit lower than 9.0625 than the cost/unit will rise and as such I have made a buying transaction than has made me loose money.

How can I solve this matter. I am new at these accounting stuff I have been searching for this matter for the past 2 weeks though. Please give me a detailed explanation.

Thank you for taking the time to read my problem. Much appreciated.
Best regards.
xmarks.