Ejemplo n.º 1
0
        private void CalculateResult()
        {
            StopSize        = Math.Abs(OpenLevel - StopLevel);
            RiskRewardRatio = Math.Abs(Target - StrategyEntryLevel) / StopSize;

            CloseLevel.IfExistsThen(x =>
            {
                ResultInR    = Option.Some(Math.Abs(x - OpenLevel) / StopSize);
                PointsProfit = Direction == TradeDirection.Long
                    ? Option.Some(x - OpenLevel)
                    : Option.Some(OpenLevel - x);
            });

            MaximumAdverseExcursionPoints.IfExistsThen(x =>
            {
                MaximumAdverseExcursionPercentageOfStop = Option.Some(x / StopSize);
            });

            MaximumFavourableExcursionPoints.IfExistsThen(x =>
            {
                PointsProfit.IfExistsThen(y =>
                {
                    if (y > 0)
                    {
                        PointsProfitPercentageOfMaximumFavourableExcursion = Option.Some(y / x);
                        UnrealisedProfitPoints = Option.Some(x - y);
                    }
                    else
                    {
                        UnrealisedProfitPoints = Option.Some(x);
                    }

                    UnrealisedProfitPoints.IfExistsThen(z =>
                    {
                        UnrealisedProfitCash = Option.Some(z * Size);
                    });
                });
            });

            PointsProfit.IfExistsThen(x => { CashProfit = Option.Some(Size * x); });
        }
Ejemplo n.º 2
0
        public Trade(double strategyEntry, double stop, double target, double openLevel, Optional <double> closeLevel, DateTime openTime,
                     Optional <DateTime> closeTime, double size)
        {
            Direction = target > stop ? TradeDirection.Long : TradeDirection.Short;

            StrategyEntryLevel = strategyEntry;
            StopLevel          = stop;
            StopSize           = Math.Abs(openLevel - stop);
            Target             = target;
            OpenLevel          = openLevel;
            CloseLevel         = closeLevel;
            OpenTime           = openTime;
            CloseTime          = closeTime;
            Size            = size;
            RiskRewardRatio = Math.Abs(Target - OpenLevel) / StopSize;
            EntrySlippage   = Direction == TradeDirection.Long
                ? strategyEntry - openLevel
                : openLevel - strategyEntry;

            CloseLevel.IfExistsThen(x =>
            {
                ResultInR = Option.Some(Math.Abs(x - OpenLevel) / StopSize);
                if (Direction == TradeDirection.Long)
                {
                    PointsProfit = Option.Some(x - openLevel);
                }
                else
                {
                    PointsProfit = Option.Some(openLevel - x);
                }
            });

            PointsProfit.IfExistsThen(x => { CashProfit = Size * x; });

            OpenFibLevel   = FibonacciLevel.FivePointNine;
            TargetFibLevel = FibonacciLevel.OneHundredAndTwentySevenPointOne;
        }