I have a WPF C# Application which is accessing data through a SQL-LINQ connection and putting it on a Datagrid. I have added a Running Pips column and have been trying to figure out how in to get this column populated correctly. I have found several methods through searching the web, but none of these are appropriate for my particular setup. Most of the time I end up in an endless loop. I would like the Running Pips column to be cumulative and the order of the calculation to start from the earliest ‘Close Time’.
Close Time Profit Running Profit
10.09.11 $10 $10
10.10.11 $20 $30
10.11.11 $15 $45
Here is a summary of the code. I hope someone can suggest how to fix this code with any relevant information needed to aid me in implementing this:
public void RefreshClose() {
if (CloseTradeCollection == null) return;
var i = 0;
if (StaticTool.SelectedAccount == null) {
ExistCloseTrade = false;
CloseTradeCollection.Clear();
return;
}
Account = StaticTool.SelectedAccount;
foreach (var trade in GetClosedTradesFromDb()) {
if (CloseTradeCollection.Count <= i) {
ExistCloseTrade = true;
var tradeDetails = new Trade {
Id = trade.id,
Ticket = trade.ticket,
OpenTime = trade.opentime,
CloseTime = trade.closetime,
Symbol = trade.symbol,
OpenPrice = trade.openprice,
ClosePrice = trade.closeprice,
Profit = trade.profit,
Comment = trade.comment.Trim(),
};
tradeDetails.History = tradeDetails.CloseTime - tradeDetails.OpenTime;
CloseTradeCollection.Add(tradeDetails);
}
else {
var tradeDetails = CloseTradeCollection[i];
tradeDetails.Id = trade.id;
tradeDetails.Ticket = trade.ticket;
tradeDetails.OpenTime = trade.opentime;
tradeDetails.CloseTime = trade.closetime;
tradeDetails.Symbol = trade.symbol;
tradeDetails.OpenPrice = trade.openprice;
tradeDetails.ClosePrice = trade.closeprice;
tradeDetails.Profit = trade.profit;
tradeDetails.Comment = trade.comment.Trim();
tradeDetails.History = DateTime.Now - tradeDetails.OpenTime;
//tradeDetails.RunningProfit = ????????
}
i++;
}
}
You can create a local variable to keep track of running profit, making use of the fact that the assignment operation returns the value being assigned.