Пример #1
0
        public double Execute(IPosition pos, int barNum)
        {
            if (pos == null)
            {
                return(0);
            }
            double stop;
            var    curProfit  = pos.OpenMFE(barNum);
            var    entryPrice = pos.EntryPrice;

            if (UseCalcPrice)
            {
                var ep1  = entryPrice;
                var ep2  = CalcEntryPrice.EntryPrice(pos, barNum);
                var diff = (ep1 - ep2) * (pos.IsLong ? 1 : -1);
                curProfit += diff;
                entryPrice = ep2;
            }
            if (curProfit > TrailEnable)
            {
                double shift = curProfit - TrailLoss;
                stop = entryPrice + (pos.IsLong ? shift : -shift);
            }
            else
            {
                double shift = -StopLoss;
                stop = entryPrice + (pos.IsLong ? shift : -shift);
            }

            return(stop);
        }
Пример #2
0
        public double Execute(IPosition pos, int barNum)
        {
            if (pos == null)
            {
                return(0);
            }
            double stop;
            var    curProfit  = pos.OpenMFE(barNum);
            var    entryPrice = pos.EntryPrice;

            if (UseCalcPrice)
            {
                var ep2  = CalcEntryPrice.EntryPrice(pos, barNum);
                var diff = (entryPrice - ep2) * (pos.IsLong ? 1 : -1);
                curProfit += diff;
                entryPrice = ep2;
            }
            curProfit *= 100 / entryPrice * pos.Security.Margin;

            if (curProfit > TrailEnable)
            {
                double shift = (curProfit - TrailLoss) / 100;
                stop = entryPrice * (1 + (pos.IsLong ? shift : -shift));
            }
            else
            {
                double shift = (0 - StopLoss) / 100;
                stop = entryPrice * (1 + (pos.IsLong ? shift : -shift));
            }
            return(stop);
        }
Пример #3
0
        public double Execute(IPosition pos, int barNum)
        {
            if (pos == null)
            {
                return(0);
            }
            double stop;
            var    curProfit  = pos.OpenMFE(barNum);
            var    entryPrice = pos.EntryPrice;

            if (UseCalcPrice)
            {
                var ep2  = CalcEntryPrice.EntryPrice(pos, barNum);
                var diff = (entryPrice - ep2) * (pos.IsLong ? 1 : -1);
                curProfit += diff;
                entryPrice = ep2;
            }
            curProfit *= 100 / entryPrice * pos.Security.Margin;

            if (curProfit > TrailEnable)
            {
                double shift = (curProfit - TrailLoss) / 100;
                stop = entryPrice * (1 + (pos.IsLong ? shift : -shift));
            }
            else
            {
                double shift = (0 - StopLoss) / 100;
                stop = entryPrice * (1 + (pos.IsLong ? shift : -shift));
            }
            var lastStop = pos.GetStop(barNum);

            // ReSharper disable CompareOfFloatsByEqualityOperator
            if (lastStop == 0)
            // ReSharper restore CompareOfFloatsByEqualityOperator
            {
                return(stop);
            }
            return(pos.IsLong ? Math.Max(stop, lastStop) : Math.Min(stop, lastStop));
        }