Discussing the article: "The Avellaneda-Stoikov Model: Inventory-Aware Quoting for Two-Sided Strategies"

 

Check out the new article: The Avellaneda-Stoikov Model: Inventory-Aware Quoting for Two-Sided Strategies.

This article builds the Avellaneda–Stoikov formulas in MQL5, feeds them with rolling estimates of mid-price volatility and a proxy for order-flow intensity, and plots the reservation price with bid and ask in real time. A bar-by-bar simulation contrasts adaptive and fixed quoting under the same fill rules. The result is a tested class, an indicator, and a backtest to improve inventory control in two‑sided strategies.

A market maker quotes two prices at once. It offers to buy at the bid and to sell at the ask, and it earns the spread between them. The job carries two risks that pull against each other. The first is inventory risk: if the bid keeps getting hit, you accumulate a long position, and a market that then trends against you turns that position into a real loss. The second is adverse selection: when the market moves fast, your resting quotes get picked off by traders who know more than your stale prices do.

Fixed, symmetric quotes ignore both problems. A grid that places a buy limit and a sell limit the same distance from the mid, over and over, has no memory of how much inventory it is holding and no sense of how volatile the market has become. In a quiet range, the grid works. In a trend it loads up on one side and gets run over.

Marco Avellaneda and Sasha Stoikov solved this in their 2008 paper High-frequency trading in a limit order book. They derived, in closed form, exactly where to place the bid and the ask so that the two risks stay balanced: the fair price shifts against your inventory to encourage you back to flat, and the spread widens with volatility and thins with liquidity. The result is two short formulas that any developer can compute on every tick.

This article implements the formulas as a small, testable MQL5 library. It connects them to live volatility and order-flow estimates, plots the resulting quotes on the chart, and runs a controlled simulation against fixed quotes on real historical data. The reader who follows along gets a reusable model class, a visual indicator, and a backtest script that measures the difference.

Author: Hammad Dilber