diff --git a/MainWindowResources.xaml b/MainWindowResources.xaml
index 7b053d9..66cb65c 100644
--- a/MainWindowResources.xaml
+++ b/MainWindowResources.xaml
@@ -84,6 +84,10 @@ This resource dictionary is used by the MainWindow.
+
+
+
+
diff --git a/Model/MGSHPositionModel.cs b/Model/MGSHPositionModel.cs
index 5072ff1..b5df854 100644
--- a/Model/MGSHPositionModel.cs
+++ b/Model/MGSHPositionModel.cs
@@ -16,6 +16,7 @@ using MarketData.Generator.Momentum;
using MarketData.DataAccess;
using System.CodeDom;
using MarketData.Generator.MGSHMomentum;
+using TradeBlotter.Interface;
namespace TradeBlotter.Model
{
@@ -47,7 +48,7 @@ namespace TradeBlotter.Model
base.OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset,null));
}
}
- public class MGSHPositionModel : ModelBase
+ public class MGSHPositionModel : ModelBase, IPositionModel
{
private MGSHPosition position = new MGSHPosition();
private int slot;
@@ -111,6 +112,37 @@ namespace TradeBlotter.Model
Comment=position.Comment;
}
+ public MGSHPosition Position
+ {
+ get{return position;}
+ set
+ {
+ Slot=-1;
+ Symbol=position.Symbol;
+ PurchaseDate=position.PurchaseDate;
+ SellDate=position.SellDate;
+ Shares=position.Shares;
+ PurchasePrice=position.PurchasePrice;
+ CurrentPrice=position.CurrentPrice;
+ Volume=position.Volume;
+ Return1D=position.Return1D;
+ CumReturn252=position.CumReturn252;
+ IDIndicator=position.IDIndicator;
+ Score=position.Score;
+ MaxDrawdown=position.MaxDrawdown;
+ MaxUpside=position.MaxUpside;
+ Velocity=position.Velocity;
+ PE=position.PE;
+ Beta=position.Beta;
+ ZacksRank=position.ZacksRank;
+ InitialStopLimit=position.InitialStopLimit;
+ TrailingStopLimit=position.TrailingStopLimit;
+ LastStopAdjustment=position.LastStopAdjustment;
+ Comment=position.Comment;
+ this.position.R=position.R;
+ }
+ }
+
private void UpdateProperties()
{
base.OnPropertyChanged("CurrentPrice");
diff --git a/TradeBlotter.csproj b/TradeBlotter.csproj
index 9bb66d6..c73565c 100644
--- a/TradeBlotter.csproj
+++ b/TradeBlotter.csproj
@@ -110,10 +110,13 @@
+
+
FloatingWindow.xaml
+
@@ -142,8 +145,8 @@
CMTTrendModelClosePositionDialog.xaml
-
- CMTTrendModelEditPositionDialog.xaml
+
+ EditPositionDialog.xaml
ProformaAddPositionDialog.xaml
@@ -154,6 +157,8 @@
+
+
@@ -181,7 +186,6 @@
-
@@ -213,6 +217,9 @@
BlotterView.xaml
+
+ BollingerBandPositionView.xaml
+
BollingerBandView.xaml
@@ -340,7 +347,7 @@
Designer
MSBuild:Compile
-
+
Designer
MSBuild:Compile
@@ -360,9 +367,13 @@
Designer
MSBuild:Compile
-
- Designer
+
MSBuild:Compile
+ Designer
+
+
+ MSBuild:Compile
+ Designer
Designer
diff --git a/UIUtils/CMTTrendModelEditPositionDialog.xaml b/UIUtils/CMTTrendModelEditPositionDialog.xaml
deleted file mode 100644
index 61dca4a..0000000
--- a/UIUtils/CMTTrendModelEditPositionDialog.xaml
+++ /dev/null
@@ -1,66 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Symbol
-
-
-
-
-
-
-
-
-
- 100.00
- Sync Trailing Stop
-
-
-
-
- 100.00
-
-
-
-
-
-
-
-
-
diff --git a/UIUtils/CMTTrendModelEditPositionDialog.xaml.cs b/UIUtils/CMTTrendModelEditPositionDialog.xaml.cs
deleted file mode 100644
index 1f0dd9e..0000000
--- a/UIUtils/CMTTrendModelEditPositionDialog.xaml.cs
+++ /dev/null
@@ -1,228 +0,0 @@
-using MarketData.DataAccess;
-using MarketData.MarketDataModel;
-using MarketData.Utils;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading;
-using System.Windows;
-using System.Windows.Controls;
-using System.Windows.Data;
-using System.Windows.Documents;
-using System.Windows.Input;
-using System.Windows.Media;
-using System.Windows.Media.Imaging;
-using System.Windows.Shapes;
-using System.Windows.Threading;
-using System.Media;
-using Position=MarketData.Generator.CMTrend.Position;
-
-
-namespace TradeBlotter.UIUtils
-{
- ///
- /// Interaction logic for CMTTrendModelEditPositionDialog.xaml
- ///
- public partial class CMTTrendModelEditPositionDialog:Window
- {
- private ManualResetEvent manualResetEvent=new ManualResetEvent(false);
- private String Symbol { get; set; }
- private DateTime PurchaseDate { get; set; }
- private double PurchasePrice{get;set;}
- private double TrailingStop{get;set;}
- private double InitialStop{get;set;}
- private double PositionRiskPercentDecimal{get;set;}
- private bool Result { get; set; }
-
- private CMTTrendModelEditPositionDialog(String title,Position position)
- {
- this.Background=new SolidColorBrush(Colors.AliceBlue);
- this.Owner=Application.Current.MainWindow;
- InitializeComponent();
- this.Loaded+=new RoutedEventHandler(CMTTrendModelEditPositionDialog_Loaded);
- this.Closing+=Window_Closing;
-
- dpPurchaseDate.SelectedDateChanged+=dpPurchaseDate_SelectionChanged;
-
- Title=title;
- Symbol=position.Symbol;
- PurchaseDate=position.PurchaseDate;
- PurchasePrice=position.PurchasePrice;
- TrailingStop=position.TrailingStopLimit;
- InitialStop=position.InitialStopLimit;
- PositionRiskPercentDecimal=position.PositionRiskPercentDecimal;
-
- txtSymbol.Text=Symbol;
- dpPurchaseDate.SelectedDate=PurchaseDate;
-
- lblInitialStopRecommendation.FontSize=12;
-
- cbSyncTrailingStop.IsChecked=true;
-
- UpdatePurchasePrice();
- UpdateInitialStop();
- UpdateTrailingStop();
- UpdateCompanyName();
- UpdateInitialStopRecommendation();
- }
- public ManualResetEvent Event { get { return manualResetEvent; } }
- public static Position Prompt(string title,Position position)
- {
- CMTTrendModelEditPositionDialog mmTrendModelEditPositionDialog=new CMTTrendModelEditPositionDialog(title,position);
- try { mmTrendModelEditPositionDialog.ShowDialog(); }
- catch(Exception) { return null; }
- mmTrendModelEditPositionDialog.Event.WaitOne();
- if(mmTrendModelEditPositionDialog.Result)
- {
- position.PurchaseDate=mmTrendModelEditPositionDialog.PurchaseDate;
- position.PurchasePrice=mmTrendModelEditPositionDialog.PurchasePrice;
- position.TrailingStopLimit=mmTrendModelEditPositionDialog.TrailingStop;
- position.InitialStopLimit=mmTrendModelEditPositionDialog.InitialStop;
- return position;
- }
- return null;
- }
- void CMTTrendModelEditPositionDialog_Loaded(object sender,RoutedEventArgs e)
- {
- txtPurchasePrice.Focus();
- }
- private void btnOk_Click(object sender,RoutedEventArgs e)
- {
- Result=Validate();
- if(!Result)
- {
- SystemSounds.Beep.Play();
- return;
- }
- Close();
- Event.Set();
- return;
- }
-// *******************************************************************************************************************************************************************************
-// ********************************************************************************** P U R C H A S E P R I C E ***************************************************************
-// *******************************************************************************************************************************************************************************
- private void txtPurchasePrice__OnLostFocusHandler(Object sender,RoutedEventArgs routedEventArgs)
- {
- HandlePurchasePriceEvents();
- }
- private void txtPurchasePrice_OnKeyDownHandler(object sender,KeyEventArgs e)
- {
- if(e.Key==Key.Return)
- {
- HandlePurchasePriceEvents();
- }
- }
- private void HandlePurchasePriceEvents()
- {
- double value=0.00;
- value=Utility.ParseCurrency(txtPurchasePrice.Text);
- if(PurchasePrice.Equals(value)) return;
- PurchasePrice=value;
- UpdatePurchasePrice();
- UpdateInitialStopRecommendation();
- }
- private void UpdatePurchasePrice()
- {
- txtPurchasePrice.Text=Utility.FormatCurrency(PurchasePrice);
- }
-// *******************************************************************************************************************************************************************************
-// ********************************************************************************** I N I T I A L S T O P R E C O M M E N D A T I O N **************************************
-// *******************************************************************************************************************************************************************************
- private void UpdateInitialStopRecommendation()
- {
- lblInitialStopRecommendation.Content="Recommended Initial Stop: "+Utility.FormatCurrency(PurchasePrice*(1.00-PositionRiskPercentDecimal),2);
- }
-// *******************************************************************************************************************************************************************************
-// ********************************************************************************** I N I T I A L S T O P *****************************************************************
-// *******************************************************************************************************************************************************************************
- private void txtInitialStop__OnLostFocusHandler(Object sender,RoutedEventArgs routedEventArgs)
- {
- HandleInitialStopEvents();
- }
- private void txtInitialStop_OnKeyDownHandler(object sender,KeyEventArgs e)
- {
- if(e.Key==Key.Return)
- {
- HandleInitialStopEvents();
- }
- }
- private void HandleInitialStopEvents()
- {
- double value=0.00;
- value=Utility.ParseCurrency(txtInitialStop.Text);
- if(InitialStop.Equals(value)) return;
- InitialStop=value;
- UpdateInitialStop();
- if(null!= cbSyncTrailingStop.IsChecked && cbSyncTrailingStop.IsChecked.Value)
- {
- TrailingStop=value;
- UpdateTrailingStop();
- }
- }
- private void UpdateInitialStop()
- {
- txtInitialStop.Text=Utility.FormatCurrency(InitialStop);
- }
-// *******************************************************************************************************************************************************************************
-// ********************************************************************************** T R A I L I N G S T O P *****************************************************************
-// *******************************************************************************************************************************************************************************
- private void txtTrailingStop__OnLostFocusHandler(Object sender,RoutedEventArgs routedEventArgs)
- {
- HandleTrailingStopEvents();
- }
- private void txtTrailingStop_OnKeyDownHandler(object sender,KeyEventArgs e)
- {
- if(e.Key==Key.Return)
- {
- HandleTrailingStopEvents();
- }
- }
- private void HandleTrailingStopEvents()
- {
- double value=0.00;
- value=Utility.ParseCurrency(txtTrailingStop.Text);
- if(TrailingStop.Equals(value)) return;
- TrailingStop=value;
- UpdateTrailingStop();
- }
- private void UpdateTrailingStop()
- {
- txtTrailingStop.Text=Utility.FormatCurrency(TrailingStop);
- }
-// *********************************************************************************************************************************************************************************
- private void dpPurchaseDate_SelectionChanged(object sender,RoutedEventArgs e)
- {
- if(null==dpPurchaseDate.SelectedDate) return;
- PurchaseDate=dpPurchaseDate.SelectedDate.Value;
- }
-// ***********************************************************************************************************************************************************************************
- private void Window_Closing(object sender,System.ComponentModel.CancelEventArgs e)
- {
- Event.Set();
- }
- private void btnCancel_Click(object sender,RoutedEventArgs e)
- {
- Result=false;
- Close();
- Event.Set();
- }
- private bool Validate()
- {
- DateGenerator dateGenerator=new DateGenerator();
- if(null==Symbol) return false;
- if(Utility.IsEpoch(PurchaseDate)) return false;
- if(!dateGenerator.IsMarketOpen(PurchaseDate))return false;
- if(double.IsNaN(PurchasePrice)) return false;
- if(double.IsNaN(TrailingStop)) return false;
- if(double.IsNaN(InitialStop)) return false;
- return true;
- }
- private void UpdateCompanyName()
- {
- CompanyProfile companyProfile=CompanyProfileDA.GetCompanyProfile(Symbol);
- if(null==companyProfile||null==companyProfile.CompanyName) return;
- lblCompanyName.Content=companyProfile.CompanyName.ToUpper();
- }
- }
-}
diff --git a/Utility/UIUtils.cs b/Utility/UIUtils.cs
index b5c77ba..426c1bc 100644
--- a/Utility/UIUtils.cs
+++ b/Utility/UIUtils.cs
@@ -140,9 +140,16 @@ namespace TradeBlotter.UIUtils
{
String key;
double offset=defaultOffset;
- if(portfolioTrade.IsOpen)key=portfolioTrade.Symbol+portfolioTrade.TradeDate.ToShortDateString();
- else key=portfolioTrade.Symbol+portfolioTrade.SellDate.ToShortDateString();
- if(tradesBySymbolAndDate.ContainsKey(key))
+
+ if (portfolioTrade.IsOpen)
+ {
+ key = portfolioTrade.Symbol + portfolioTrade.TradeDate.ToShortDateString();
+ }
+ else
+ {
+ key = portfolioTrade.Symbol + portfolioTrade.SellDate.ToShortDateString();
+ }
+ if (tradesBySymbolAndDate.ContainsKey(key))
{
if(hits>MAX_HITS)increment=5;
offset=tradesBySymbolAndDate[key]+increment;
diff --git a/ViewModels/BollingerBandViewModel.cs b/ViewModels/BollingerBandViewModel.cs
index 515c9ca..3666356 100644
--- a/ViewModels/BollingerBandViewModel.cs
+++ b/ViewModels/BollingerBandViewModel.cs
@@ -24,6 +24,7 @@ using System.Windows.Media;
using System.Windows.Threading;
using System.Windows.Forms;
using TradeBlotter.UIUtils;
+using TradeBlotter.Extensions;
// Author:Sean Kessler
@@ -173,17 +174,7 @@ namespace TradeBlotter.ViewModels
{
if(saveParameters.ContainsKey("StopHistoryCount"))
{
- stopLimits=new StopLimits();
- int stopHistoryCount=int.Parse((from KeyValuePair item in saveParameters where item.Key.Equals("StopHistoryCount") select item).FirstOrDefault().Value);
- for(int index=0;index item in saveParameters where item.Key.Equals(strItemKey) select item).FirstOrDefault().Value;
- NVPCollection nvpCollection=new NVPCollection(strStopHistoryItem);
- StopLimit stopLimit=MarketData.MarketDataModel.StopLimit.FromNVPCollection(nvpCollection);
- stopLimits.Add(stopLimit);
- }
- stopLimits=new StopLimits(stopLimits.OrderBy(x => x.EffectiveDate).ToList());
+ stopLimits = StopLimitsExtensions.FromSaveParams(saveParameters);
}
}
catch(Exception exception)
diff --git a/ViewModels/CMTTrendViewModel.cs b/ViewModels/CMTTrendViewModel.cs
index 72f9db9..fcdb05c 100644
--- a/ViewModels/CMTTrendViewModel.cs
+++ b/ViewModels/CMTTrendViewModel.cs
@@ -28,6 +28,8 @@ using StopLimit=MarketData.MarketDataModel.StopLimit;
using TradeBlotter.UIUtils;
using MarketData.Generator.Model;
using MarketData.Generator.ModelGenerators;
+using MarketData.Generator.Interface;
+using TradeBlotter.Extensions;
namespace TradeBlotter.ViewModels
{
@@ -950,41 +952,60 @@ namespace TradeBlotter.ViewModels
// *************************************************************************************************************************************************************
// ********************************************************************** C O M M A N D W O R K E R S P O S I T I O N ****************************************
// *************************************************************************************************************************************************************
+ //public void DisplayBollingerBandCommandPosition()
+ //{
+ // String strStopLimits=null;
+ // MarketData.MarketDataModel.StopLimits stopLimits=GetHistoricalStopLimitsMarketDataModel();
+ // StringBuilder sb=new StringBuilder();
+ // if(null!=stopLimits && 0!=stopLimits.Count)
+ // {
+ // sb.Append(",");
+ // NVPCollections nvpCollections=stopLimits.ToNVPCollections();
+ // sb.Append("StopHistoryCount").Append(",").Append(String.Format("{0}",nvpCollections.Count)).Append(",");
+ // for(int index=0;index x.AnalysisDate).ToList());
+ MarketData.Generator.Model.StopLimits stopLimits=new MarketData.Generator.Model.StopLimits(
+ (from MarketData.Generator.Model.StopLimit stopLimit in sessionParams.StopLimits where stopLimit.Symbol.Equals(selectedPosition.Symbol)
+ select stopLimit).OrderByDescending(x => x.AnalysisDate).ToList());
MarketData.MarketDataModel.StopLimit initialStopLimit=new MarketData.MarketDataModel.StopLimit();
initialStopLimit.Symbol=selectedPosition.Symbol;
diff --git a/ViewModels/MGSHMomentumViewModel.cs b/ViewModels/MGSHMomentumViewModel.cs
index b367c48..f2f7442 100644
--- a/ViewModels/MGSHMomentumViewModel.cs
+++ b/ViewModels/MGSHMomentumViewModel.cs
@@ -26,6 +26,9 @@ using MarketData.Generator.Momentum;
using TradeBlotter.UIUtils;
using MarketData.Generator.Model;
using MarketData.Generator.MGSHMomentum;
+using MarketData.Generator.Interface;
+using StopLimit=MarketData.MarketDataModel.StopLimit;
+using TradeBlotter.Extensions;
namespace TradeBlotter.ViewModels
{
@@ -88,6 +91,8 @@ namespace TradeBlotter.ViewModels
private RelayCommand movingAverageCommandPosition;
private RelayCommand displayHistoricalCommandPosition;
private RelayCommand displayHeadlinesCommandPosition;
+ private RelayCommand editPositionCommandPosition;
+
// chart plotter
private bool showAsGainLoss=true;
private bool isLegendVisible=false;
@@ -157,7 +162,10 @@ namespace TradeBlotter.ViewModels
// **************************************************************************************************************************************************************************
public bool BusyIndicator
{
- get { return busyIndicator; }
+ get
+ {
+ return busyIndicator;
+ }
set
{
busyIndicator = value;
@@ -166,8 +174,15 @@ namespace TradeBlotter.ViewModels
}
public String BusyContent
{
- get{return busyContent;}
- set{busyContent=value;base.OnPropertyChanged("BusyContent");}
+ get
+ {
+ return busyContent;
+ }
+ set
+ {
+ busyContent=value;
+ base.OnPropertyChanged("BusyContent");
+ }
}
// **************************************************************************************************************************************************************************
public ObservableCollection