Esempio n. 1
0
        public override double Execute(ISecurity source, int barNum)
        {
            var barDate  = source.Bars[barNum].Date;
            var startDay = barDate.Date.Add(SessionStart);

            if (startDay > barDate)
            {
                startDay = startDay.AddDays(-1);
            }

            var endDay = startDay.AddDays(1);

            if (startDay > m_oldStartDate)
            {
                m_oldStartDate   = startDay;
                m_oldStartBarNum = barNum;
            }
            Func <IPosition, int, double> getProfitFunc;

            switch (ProfitKind)
            {
            case ProfitKind.Unfixed:
                getProfitFunc = ProfitExtensions.GetProfit;
                break;

            case ProfitKind.Fixed:
                getProfitFunc = ProfitExtensions.GetAccumulatedProfit;
                break;

            default:
                throw new InvalidEnumArgumentException(nameof(ProfitKind), (int)ProfitKind, ProfitKind.GetType());
            }
            var profit = CalcProfit(source, barNum, getProfitFunc, startDay, endDay, m_oldStartBarNum);

            return(profit);
        }
Esempio n. 2
0
        public override double Execute(ISecurity source, int barNum)
        {
            switch (ProfitKind)
            {
            case ProfitKind.Unfixed:
                return(source.GetProfit(barNum));

            case ProfitKind.Fixed:
                return(source.GetAccumulatedProfit(barNum));

            default:
                throw new InvalidEnumArgumentException(nameof(ProfitKind), (int)ProfitKind, ProfitKind.GetType());
            }
        }