Exemple #1
0
        public StopAdjustment CalculateStopLoss(
            double entryPrice,
            double latestPrice,
            StopRulesCollection stopRules)
        {
            var profit           = latestPrice - entryPrice;
            var profitPercentage = profit / entryPrice * 100;
            var rule             = stopRules.RuleForPercentage(profitPercentage);

            var adjustment = new StopAdjustment();

            // TODO: Check for null rule
            var stopType = _factory.Create(rule.StopType);

            var stopPrice = stopType.GetStopValue(rule, profitPercentage);

            //if (profitPercentage <= stopLossPercentage)
            //    return latestPrice - latestPrice * stopLossPercentage / 100;

            //// For values between 7 and 10% profit, "float" the stop
            //if (profitPercentage <= StartLockingPercentage)
            //    return entryPrice;

            adjustment.SubmitOrder = stopPrice != null;
            adjustment.OrderType   = stopType.OrderType;
            adjustment.StopPrice   = stopPrice;
            return(adjustment);
        }
        private bool ProfitIncreasedSufficiently(StopAdjustment result)
        {
            if (!CurrentStopLoss.HasValue ||
                result.StopPrice.Price > CurrentStopLoss.Value + ProfitChangeTriggerThreshold)
            {
                return(true);
            }

            return(false);
        }