Ejemplo n.º 1
0
        public double Execute(ISecurity sec, int barNum)
        {
            List <double> positionProfits = PreparePositionProfits();

            int len = m_context.BarsCount;

            for (int j = positionProfits.Count; j < len; j++)
            {
                positionProfits.Add(Constants.NaN);
            }

            {
                int barsCount = m_context.BarsCount;
                if (!m_context.IsLastBarUsed)
                {
                    barsCount--;
                }
                if (barNum < barsCount - 1)
                {
                    return(positionProfits[barNum]);
                }
            }

            if (sec == null)
            {
                return(Constants.NaN);
            }

            double           cache, pnl;
            IDataBar         bar       = sec.Bars[barNum];
            PositionsManager posMan    = PositionsManager.GetManager(m_context);
            double           rawProfit = posMan.GetTotalProfit(sec, barNum, m_algo, bar.Close, out cache, out pnl);

            if (m_context.IsFixedBarsCount)
            {
                // В этом режиме сдвигаю все значения влево
                // Если мы уже набрали в буфер необходимое число баров
                if (len <= positionProfits.Count)
                {
                    for (int j = 0; j < positionProfits.Count - 1; j++)
                    {
                        positionProfits[j] = positionProfits[j + 1];
                    }
                }
            }

            // Пересчитываю прибыль в привычные денежные единицы
            rawProfit *= ScaleMultiplier;
            positionProfits[barNum] = rawProfit; // заполняю индекс barNumber

            m_profit.Value = rawProfit;
            if (PrintProfitInLog)
            {
                m_context.Log(MsgId + ": " + m_profit.Value, MessageType.Info, PrintProfitInLog);
            }

            return(rawProfit);
        }