Code:
        IPosition[] GetClosedPositions(ISecurity source, int barNum)
        {
            var last = source.Positions.GetLastPositionClosed(barNum);
            if (m_lastCache == null || last != m_lastClosed)
            {
                m_lastClosed = last;
                m_lastCache = source.Positions.GetClosedForBar(barNum).OrderByDescending(pos => pos.ExitBar.Date).ToArray();
            }
            return m_lastCache;
        }