So I have an equation that calculates the price of an item based on how many items are currently in the market. Pretty much what it does is take the current quantity of outstanding items (items bought - items sold) and multiplies it by a value I put in the equation. Here's a simplified way to picture it:

Price = [Number of Outstanding Items] * 5

What's happening is that there is a delay when calculating the price. For example, let's say there are 100 items outstanding. Price would be at $500. Then someone buys an at that price, price should go to $505 right after that purchase. But it doesn't. It stays at $500 until one more trade happens. If someone buys one more, then it finally goes to $505, but since there are 102 items outstanding now the price should be at $510.

I don't understand why it has this delay. For some reason it is waiting for one additional trade to process before calculating the price. If I send through a blank trade not buying or selling anything, then the price updates to what it should be, but whenever another real trade happens it delays again and waits to update the price until the next trade after that (real or blank).

Does anyone know why this is happening and how I can fix it?