private void AdjustVolume(List<Trade> trade) { int count = trade.Count; for (int x = 1; x < count; x++) { //set traded price if (trade[x].Reason == Trade.Trigger.OpenLong || trade[x].Reason == Trade.Trigger.OpenShort) trade[x].TradedPrice = trade[x].CurrentPrice; else trade[x].TradedPrice = trade[x - 1].TradedPrice; var v = new OriginalVolume() { Stamp = trade[x].TimeStamp, Vol = trade[x].TradeVolume }; orgVol.Add(v); } //clear vol to 1 double tp = 0; for (int x = 1; x < count; x++) { trade[x].TradeVolume = 1; trade[x].TotalPL = 0; trade[x].RunningProfit = 0; if (trade[x].Position && trade[x].CurrentDirection == Trade.Direction.Long) trade[x].RunningProfit = trade[x].CurrentPrice - trade[x].TradedPrice; if (trade[x].Position & trade[x].CurrentDirection == Trade.Direction.Short) trade[x].RunningProfit = trade[x].TradedPrice - trade[x].CurrentPrice; if (trade[x - 1].Position && !trade[x].Position) { if (trade[x - 1].CurrentDirection == Trade.Direction.Long) trade[x].RunningProfit = trade[x].CurrentPrice - trade[x - 1].TradedPrice; if (trade[x - 1].CurrentDirection == Trade.Direction.Short) trade[x].RunningProfit = trade[x - 1].TradedPrice - trade[x].CurrentPrice; } if (trade[x].Reason == Trade.Trigger.CloseLong || trade[x].Reason == Trade.Trigger.CloseShort) { tp += trade[x].RunningProfit; trade[x].TotalPL = tp; trade[x].TotalRunningProfit = tp; } else trade[x].TotalRunningProfit = tp + trade[x].RunningProfit; } }
private void AdjustVolume(List <Trade> trade) { int count = trade.Count; for (int x = 1; x < count; x++) { //set traded price if (trade[x].Reason == Trade.Trigger.OpenLong || trade[x].Reason == Trade.Trigger.OpenShort) { trade[x].TradedPrice = trade[x].CurrentPrice; } else { trade[x].TradedPrice = trade[x - 1].TradedPrice; } var v = new OriginalVolume() { Stamp = trade[x].TimeStamp, Vol = trade[x].TradeVolume }; orgVol.Add(v); } //clear vol to 1 double tp = 0; for (int x = 1; x < count; x++) { trade[x].TradeVolume = 1; trade[x].TotalPL = 0; trade[x].RunningProfit = 0; if (trade[x].Position && trade[x].CurrentDirection == Trade.Direction.Long) { trade[x].RunningProfit = trade[x].CurrentPrice - trade[x].TradedPrice; } if (trade[x].Position & trade[x].CurrentDirection == Trade.Direction.Short) { trade[x].RunningProfit = trade[x].TradedPrice - trade[x].CurrentPrice; } if (trade[x - 1].Position && !trade[x].Position) { if (trade[x - 1].CurrentDirection == Trade.Direction.Long) { trade[x].RunningProfit = trade[x].CurrentPrice - trade[x - 1].TradedPrice; } if (trade[x - 1].CurrentDirection == Trade.Direction.Short) { trade[x].RunningProfit = trade[x - 1].TradedPrice - trade[x].CurrentPrice; } } if (trade[x].Reason == Trade.Trigger.CloseLong || trade[x].Reason == Trade.Trigger.CloseShort) { tp += trade[x].RunningProfit; trade[x].TotalPL = tp; trade[x].TotalRunningProfit = tp; } else { trade[x].TotalRunningProfit = tp + trade[x].RunningProfit; } } }