17 using System.Collections.Generic;
25 internal sealed
class ReturnsPerTradeReportElement : ChartReportElement
48 public override string Render()
50 var backtestPercentagePerTrade =
new List<double>();
51 if (_backtest?.TotalPerformance?.ClosedTrades !=
null)
55 if (trade.EntryPrice == 0m)
57 Log.
Error($
"ReturnsPerTradeReportElement.Render(): Encountered entry price of 0 in trade with entry time: {trade.EntryTime:yyyy-MM-dd HH:mm:ss} - Exit time: {trade.ExitTime:yyyy-MM-dd HH::mm:ss}");
61 var sideMultiplier = trade.Direction ==
TradeDirection.Long ? 1 : -1;
62 backtestPercentagePerTrade.Add(sideMultiplier * (Convert.ToDouble(trade.ExitPrice) - Convert.ToDouble(trade.EntryPrice)) / Convert.ToDouble(trade.EntryPrice));
72 base64 = Charting.GetReturnsPerTrade(backtestPercentagePerTrade.ToPython());