public void WriteTrades(TransactionPairs transactionPairs, TradeStats stats, bool combo) { if (transactionPairs != null && transactionPairs.Count > 0) { int year = 0; double currentBalance = stats.BeginningBalance; double yearBalance = stats.BeginningBalance; double ytdProfitLoss = 0; WriteTradeHeader(); List <string> tableData = new List <string>(); for (int i = 0; i < transactionPairs.Count; i++) { if (transactionPairs[i].EntryTime.Year != year) { tableData.Add(WriteTradeTitles(year, combo)); yearBalance += ytdProfitLoss; ytdProfitLoss = 0; year = transactionPairs[i].EntryTime.Year; } double profitLoss = transactionPairs.CalcProfitLoss(i); string tableRow = "<tr>"; tableRow += "<td class=\"leftcol\">" + i + "</td>"; tableRow += "<td class=\"data\">" + transactionPairs[i].EntryTime + "</td>"; tableRow += "<td class=\"data\">" + transactionPairs[i].ExitTime + "</td>"; tableRow += "<td class=\"data\">" + transactionPairs[i].EntryPrice.ToString(",0.000") + "</td>"; tableRow += "<td class=\"data\">" + transactionPairs[i].EntryBar + "</td>"; tableRow += "<td class=\"data\">" + transactionPairs[i].ExitPrice.ToString(",0.000") + "</td>"; tableRow += "<td class=\"data\">" + transactionPairs[i].ExitBar + "</td>"; tableRow += "<td class=\"data\">" + ((transactionPairs[i].Direction > 0)?"Long":"Short") + " " + Math.Round(Math.Abs(transactionPairs[i].Direction), 2) + "</td>"; tableRow += "<td class=\"data\">" + Math.Round(transactionPairs.CalcMaxAdverse(i), 2) + "</td>"; tableRow += "<td class=\"data\">" + Math.Round(transactionPairs.CalcMaxFavorable(i), 2) + "</td>"; tableRow += "<td class=\"data\">" + Math.Round(profitLoss, 2) + "</td>"; double monthlyReturn = ((currentBalance + profitLoss) / currentBalance) - 1; tableRow += "<td class=\"data\">" + Math.Round(monthlyReturn * 100, 2) + "%</td>"; ytdProfitLoss += profitLoss; double ytdReturn = ((yearBalance + ytdProfitLoss) / yearBalance) - 1; tableRow += "<td class=\"data\">" + Math.Round(ytdReturn * 100, 2) + "%</td>"; currentBalance += profitLoss; tableRow += "<td class=\"data\">" + Math.Round(currentBalance, 2) + "</td>"; tableRow += "</tr>"; tableData.Add(tableRow); } tableData.Add(WriteTradeTitles(year, combo)); for (int i = 0; i < tableData.Count; i++) { fwriter.WriteLine(tableData[i]); } WriteTradeFooter(); } }