Exemple #1
0
        public void RecalculateTrade(Trade trade, IBrokersCandlesService candleService, IMarketDetailsService marketsService, IBroker broker)
        {
            // Update price per pip
            if (trade.EntryQuantity != null && trade.EntryDateTime != null)
            {
                trade.PricePerPip = candleService.GetGBPPerPip(marketsService, broker, trade.Market,
                                                               trade.EntryQuantity.Value, trade.EntryDateTime.Value, true);
            }

            // Update risk
            if (trade.InitialStopInPips == null || trade.PricePerPip == null)
            {
                trade.RiskPercentOfBalance = null;
                trade.RiskAmount           = null;
                trade.RiskPercentOfBalance = null;
            }
            else
            {
                trade.RiskAmount = trade.PricePerPip.Value * trade.InitialStopInPips.Value;

                var balance = GetBalance(trade.StartDateTime);
                if (balance != 0.0M)
                {
                    var startTime = trade.OrderDateTime ?? trade.EntryDateTime;
                    trade.RiskPercentOfBalance = (trade.RiskAmount * 100M) / GetBalance(startTime);
                }
                else
                {
                    trade.RiskPercentOfBalance = null;
                }
            }
        }
 private void UpdateTradePricePerPip(Trade trade, IBroker broker)
 {
     // Update price/pip
     if (trade.EntryQuantity != null && trade.EntryDateTime != null)
     {
         if (broker != null)
         {
             trade.PricePerPip = _candlesService.GetGBPPerPip(_marketsService, broker, trade.Market,
                                                              trade.EntryQuantity.Value, trade.EntryDateTime.Value, true);
         }
         else
         {
             trade.PricePerPip = null;
         }
     }
 }