diff --git a/Model/CMTPositionModel.cs b/Model/CMTPositionModel.cs
index 7cd8875..0eaf424 100644
--- a/Model/CMTPositionModel.cs
+++ b/Model/CMTPositionModel.cs
@@ -72,7 +72,6 @@ namespace TradeBlotter.Model
base.OnPropertyChanged("ActiveMarketValue");
base.OnPropertyChanged("GainLoss");
base.OnPropertyChanged("GainLossPcnt");
-// base.OnPropertyChanged("RMultipleAsString");
base.OnPropertyChanged("RMultiple");
base.OnPropertyChanged("EdgeRatioAsString");
diff --git a/Model/MGPositionModel.cs b/Model/MGPositionModel.cs
index 0eef76a..81a382d 100644
--- a/Model/MGPositionModel.cs
+++ b/Model/MGPositionModel.cs
@@ -92,6 +92,15 @@ namespace TradeBlotter.Model
ZacksRank=position.ZacksRank;
SharpeRatio = position.SharpeRatio;
}
+
+ public MarketData.Generator.Momentum.Position Position
+ {
+ get
+ {
+ return position;
+ }
+ }
+
public String Symbol
{
get{return position.Symbol;}
diff --git a/TradeBlotter.csproj b/TradeBlotter.csproj
index 4baf58c..4cce3ae 100644
--- a/TradeBlotter.csproj
+++ b/TradeBlotter.csproj
@@ -145,9 +145,15 @@
ClosePositionDialog.xaml
+
+ ClosePositionDialogNoStop.xaml
+
EditPositionDialog.xaml
+
+ EditPositionDialogNoStop.xaml
+
ProformaAddPositionDialog.xaml
@@ -347,10 +353,18 @@
Designer
MSBuild:Compile
+
+ Designer
+ MSBuild:Compile
+
Designer
MSBuild:Compile
+
+ Designer
+ MSBuild:Compile
+
Designer
MSBuild:Compile
diff --git a/ViewModels/CMTTrendViewModel.cs b/ViewModels/CMTTrendViewModel.cs
index c68bdd1..96e3b86 100644
--- a/ViewModels/CMTTrendViewModel.cs
+++ b/ViewModels/CMTTrendViewModel.cs
@@ -1119,6 +1119,7 @@ namespace TradeBlotter.ViewModels
selectedPosition.Symbol,selectedPosition.PurchaseDate.ToShortDateString(),Utility.FormatCurrency(selectedPosition.PurchasePrice),Utility.FormatCurrency(selectedPosition.TrailingStopLimit));
MessageBox.Show(strMessage,"Edit Position");
}
+
public void AddToWatchListCommand(String symbol)
{
if(WatchListDA.IsInWatchList(symbol))
diff --git a/ViewModels/MomentumViewModel.cs b/ViewModels/MomentumViewModel.cs
index 4ac36cf..118b42b 100644
--- a/ViewModels/MomentumViewModel.cs
+++ b/ViewModels/MomentumViewModel.cs
@@ -25,6 +25,8 @@ using System.Windows.Threading;
using MarketData.Generator.Momentum;
using TradeBlotter.UIUtils;
using MarketData.Generator.Model;
+using MarketData.Generator.Interface;
+using Position = MarketData.Generator.Momentum.Position;
namespace TradeBlotter.ViewModels
{
@@ -87,6 +89,8 @@ namespace TradeBlotter.ViewModels
private RelayCommand movingAverageCommandPosition;
private RelayCommand displayHistoricalCommandPosition;
private RelayCommand displayHeadlinesCommandPosition;
+ private RelayCommand closePositionCommandPosition;
+ private RelayCommand editPositionCommandPosition;
// chart plotter
private bool showAsGainLoss=true;
private bool isLegendVisible=false;
@@ -209,6 +213,8 @@ namespace TradeBlotter.ViewModels
collection.Add(new MenuItem() { Text = "Display DCF Valuation", MenuItemClickedCommand = DisplayDCFValuationPosition, StaysOpenOnClick = false });
collection.Add(new MenuItem() { Text = "Add to Watchlist", MenuItemClickedCommand = AddToWatchListPosition, StaysOpenOnClick = false });
collection.Add(new MenuItem() { Text = "Remove from Watchlist", MenuItemClickedCommand = RemoveFromWatchListPosition, StaysOpenOnClick = false });
+ collection.Add(new MenuItem() { Text="Close Position...",MenuItemClickedCommand=ClosePosition,StaysOpenOnClick=false });
+ collection.Add(new MenuItem() { Text="Edit Position...",MenuItemClickedCommand=EditPosition,StaysOpenOnClick=false });
return collection;
}
}
@@ -834,6 +840,37 @@ namespace TradeBlotter.ViewModels
return removeFromWatchListCommandPosition;
}
}
+
+ public ICommand ClosePosition
+ {
+ get
+ {
+ if(closePositionCommandPosition==null)
+ {
+ closePositionCommandPosition=new RelayCommand(param => this.ClosePositionCommand(selectedPosition),param =>
+ {
+ if(null==selectedPosition||null==selectedPosition.Symbol) return false;
+ return true;
+ });
+ }
+ return closePositionCommandPosition;
+ }
+ }
+ public ICommand EditPosition
+ {
+ get
+ {
+ if(editPositionCommandPosition==null)
+ {
+ editPositionCommandPosition=new RelayCommand(param => this.EditPositionCommand(selectedPosition),param =>
+ {
+ if(null==selectedPosition||null==selectedPosition.Symbol||!Utility.IsEpoch(selectedPosition.SellDate)) return false;
+ return true;
+ });
+ }
+ return editPositionCommandPosition;
+ }
+ }
// *************************************************************************************************************************************************************
// ******************************************************************* I C O M M A N D S E S S I O N *********************************************************
// *************************************************************************************************************************************************************
@@ -1002,6 +1039,47 @@ namespace TradeBlotter.ViewModels
System.Windows.MessageBox.Show("Removed '"+symbol+"'","Success", MessageBoxButton.OK, MessageBoxImage.Information);
}
}
+
+ public void ClosePositionCommand(MGPositionModel selectedPosition)
+ {
+ Position clonedPosition=Position.Clone(selectedPosition.Position);
+ IPurePosition changedPosition=ClosePositionDialogNoStop.Prompt("Close Position",clonedPosition);
+ if(null==changedPosition) return;
+ MomentumBacktest momentumModel = new MomentumBacktest();
+ if (!momentumModel.ClosePosition(changedPosition.Symbol, changedPosition.PurchaseDate, changedPosition.SellDate, changedPosition.CurrentPrice, pathFileName))
+ {
+ MessageBox.Show("Failed to close the position, check log for details.", "Close Position");
+ return;
+ }
+ String strMessage = String.Format("Closed position for {0}, Purchase Date:{1}, Sell Date{2}, Current Price:{3}. Saved to {4}. A backup was created.",
+ changedPosition.Symbol,
+ changedPosition.PurchaseDate.ToShortDateString(),
+ changedPosition.SellDate.ToShortDateString(),
+ Utility.FormatCurrency(changedPosition.CurrentPrice),
+ pathFileName);
+ MessageBox.Show(strMessage, "Close Position");
+ LoadSessionFile();
+ }
+
+ public void EditPositionCommand(MGPositionModel selectedPosition)
+ {
+ Position clonedPosition=Position.Clone(selectedPosition.Position);
+ IPurePosition changedPosition=EditPositionDialogNoStop.Prompt("Edit Position",clonedPosition);
+ if(null==changedPosition) return;
+ MomentumBacktest momentumModel = new MomentumBacktest();
+ if (!momentumModel.EditPosition(changedPosition.Symbol, changedPosition.PurchaseDate, changedPosition.PurchasePrice, pathFileName))
+ {
+ MessageBox.Show("Failed to edit the position, check log for details.", "Edit Position");
+ return;
+ }
+ selectedPosition.PurchaseDate = changedPosition.PurchaseDate;
+ selectedPosition.PurchasePrice = changedPosition.PurchasePrice;
+ String strMessage = String.Format("Edited Position for {0} Purchase Date:{1} Purchase Price:{2}. A backup was created.",
+ selectedPosition.Symbol,
+ selectedPosition.PurchaseDate.ToShortDateString(),
+ Utility.FormatCurrency(selectedPosition.PurchasePrice));
+ MessageBox.Show(strMessage, "Edit Position");
+ }
// **************************************************************************************************************************************************************************
// ********************************************************************** C O M M A N D W O R K E R S S E S S I O N ********************************************************
// ***************************************************************************************************************************************************************************