private void CalcCurrentPrice(ISecurityRt rtSec, out double curQty, out double curPrice) { curQty = 0; curPrice = 0; if (rtSec != null) { var orders = rtSec.Orders.OrderBy(ord => ord.Date); foreach (var order in orders) { if (order.IsExecuted) { int bs = (order.IsBuy ? 1 : -1); double qty = order.Quantity * bs; double price = order.Price; double newQty = curQty + qty; bool isGrowPos = Math.Abs(newQty) > Math.Abs(curQty); if (isGrowPos) { curPrice = newQty == 0 ? 0 : (curQty*curPrice + qty*price)/newQty; } curQty = newQty; } } } curPrice = curQty == 0 ? 0 : curPrice; }