This commit is contained in:
2025-02-24 21:30:26 -05:00
parent 7a7126d171
commit 1b56b16a30
8 changed files with 1027 additions and 0 deletions

View File

@@ -0,0 +1,59 @@
<Window x:Class="TradeBlotter.UIUtils.ClosePositionDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Close Position" Height="260" Width="200"
xmlns:wpfx="http://schemas.xceed.com/wpf/xaml/toolkit"
WindowStartupLocation="CenterScreen"
SizeToContent="WidthAndHeight"
MinWidth="200"
MinHeight="200"
WindowStyle="SingleBorderWindow"
ResizeMode="CanMinimize">
<wpfx:BusyIndicator Name="BusyBar" IsBusy="{Binding Path=BusyIndicator}" BusyContent="{Binding Path=BusyContent}">
<StackPanel Margin="5" Orientation="Vertical">
<Grid DockPanel.Dock="Left" Margin="0,2,4,2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="6" />
<ColumnDefinition Width="75*" />
<ColumnDefinition Width="6" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="20*" />
<RowDefinition Height="25" />
<RowDefinition Height="25" />
<RowDefinition Height="25" />
<RowDefinition Height="25" />
<RowDefinition Height="25" />
<RowDefinition Height="25" />
<RowDefinition Height="25" />
<RowDefinition Height="25" />
<RowDefinition Height="25" />
</Grid.RowDefinitions>
<Label Name="lblCompanyName" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="3"></Label>
<Label Name="lblSymbol" Grid.Row="2" Grid.Column="0">Symbol</Label>
<TextBox Name="txtSymbol" IsEnabled="False" Grid.Row="2" IsReadOnly="True" Grid.Column="2" MinWidth="75" AcceptsReturn="true">Symbol</TextBox>
<Label Name="lblPurchaseDate" Grid.Row="3" Grid.Column="0" MinWidth="75">Purchase Date</Label>
<DatePicker Name="dpPurchaseDate" IsEnabled="False" Grid.Row="3" Grid.Column="2"></DatePicker>
<Label Name="lblSellDate" Grid.Row="4" Grid.Column="0" MinWidth="75">Sell Date</Label>
<DatePicker Name="dpSellDate" Grid.Row="4" Grid.Column="2" SelectedDateChanged="dpSellDate_SelectionChanged"></DatePicker>
<Label Name="lblSellPrice" Grid.Row="5" Grid.Column="0">Sell Price</Label>
<TextBox Name="txtSellPrice" Grid.Row="5" Grid.Column="2" MinWidth="75" LostFocus="txtSellPrice_OnLostFocusHandler" KeyDown="txtSellPrice_OnKeyDownHandler">100.00</TextBox>
<Label FontWeight="Bold" FontSize="10" Name="lblSellPriceInstructions" Grid.Row="6" Grid.Column="0" Grid.ColumnSpan="3">(enter sell price then hit enter key)</Label>
<CheckBox Name="cbDeleteStop" Grid.Row="7" Grid.Column="0">Delete Stop</CheckBox>
<Label Name="lblMessage" Grid.Row="8" Grid.Column="0" Grid.ColumnSpan="5"></Label>
<Button Content="_Ok" MinWidth="75" IsDefault="False" Margin="2" Name="btnOk" Click="btnOk_Click" Grid.Row="9" Grid.Column="0"/>
<Button Content="_Cancel" MinWidth="75" IsCancel="True" Margin="2" Name="btnCancel" Click="btnCancel_Click" Grid.Row="9" Grid.Column="2"/>
</Grid>
</StackPanel>
</wpfx:BusyIndicator>
</Window>

View File

@@ -0,0 +1,213 @@
using MarketData.DataAccess;
using MarketData.Generator.Interface;
using MarketData.MarketDataModel;
using MarketData.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Media;
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 Position=MarketData.Generator.CMTrend.Position;
namespace TradeBlotter.UIUtils
{
/// <summary>
/// Interaction logic for ClosePositionDialog.xaml
/// </summary>
public partial class ClosePositionDialog:Window
{
private ManualResetEvent manualResetEvent=new ManualResetEvent(false);
private String Symbol{get;set;}
private DateTime PurchaseDate { get; set; }
private DateTime SellDate{get;set;}
private double SellPrice { get; set; }
private bool DeleteStop{get;set;}
private bool Result { get; set; }
private ClosePositionDialog(String title,IPosition position,bool hasStopLimit)
{
this.Background=new SolidColorBrush(Colors.AliceBlue);
this.Owner=Application.Current.MainWindow;
InitializeComponent();
this.Loaded+=new RoutedEventHandler(CMTTrendModelClosePositionDialog_Loaded);
this.Closing+=Window_Closing;
dpPurchaseDate.SelectedDateChanged+=dpPurchaseDate_SelectionChanged;
dpSellDate.SelectedDateChanged+=dpPurchaseDate_SelectionChanged;
cbDeleteStop.Click+=cbDeleteStop_SelectionChanged;
Title=title;
Symbol=position.Symbol;
PurchaseDate=position.PurchaseDate;
if(Utility.IsEpoch(position.SellDate))
{
SellDate = DateTime.Now;
}
else
{
SellDate=position.SellDate;
}
SellPrice=position.TrailingStopLimit;
DeleteStop=hasStopLimit;
txtSymbol.Text=Symbol;
dpPurchaseDate.SelectedDate=PurchaseDate;
dpSellDate.SelectedDate=SellDate;
cbDeleteStop.IsChecked=DeleteStop;
UpdateSellPrice();
UpdateCompanyName();
}
public ManualResetEvent Event
{
get
{
return manualResetEvent;
}
}
public static IPosition Prompt(string title,IPosition position,bool hasStopLimit,ref bool deleteStop)
{
ClosePositionDialog closePositionDialog=new ClosePositionDialog(title,position,hasStopLimit);
try { closePositionDialog.ShowDialog(); }
catch(Exception) { return null; }
closePositionDialog.Event.WaitOne();
if( closePositionDialog.Result)
{
position.SellDate=closePositionDialog.SellDate;
position.CurrentPrice=closePositionDialog.SellPrice;
deleteStop=closePositionDialog.DeleteStop;
return position;
}
return null;
}
void CMTTrendModelClosePositionDialog_Loaded(object sender,RoutedEventArgs e)
{
txtSellPrice.Focus();
}
private void btnOk_Click(object sender,RoutedEventArgs e)
{
Result=Validate();
if(!Result)
{
SystemSounds.Beep.Play();
return;
}
Close();
Event.Set();
return;
}
private void cbDeleteStop_SelectionChanged(object sender,RoutedEventArgs e)
{
DeleteStop=cbDeleteStop.IsChecked.Value;
}
private void txtSellPrice_OnLostFocusHandler(Object sender,RoutedEventArgs routedEventArgs)
{
HandleSellPriceEvents();
}
private void txtSellPrice_OnKeyDownHandler(object sender,KeyEventArgs e)
{
if(e.Key==Key.Return)
{
HandleSellPriceEvents();
}
}
private void HandleSellPriceEvents()
{
double value=0.00;
value=Utility.ParseCurrency(txtSellPrice.Text);
if(SellPrice.Equals(value)) return;
SellPrice=value;
UpdateSellPrice();
}
private void dpPurchaseDate_SelectionChanged(object sender,RoutedEventArgs e)
{
if(null==dpPurchaseDate.SelectedDate) return;
PurchaseDate=dpPurchaseDate.SelectedDate.Value;
}
private void dpSellDate_SelectionChanged(object sender,RoutedEventArgs e)
{
if(null==dpSellDate.SelectedDate) return;
SellDate=dpSellDate.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)
{
SetMessage("Invalid Symbol.");
return false;
}
if(Utility.IsEpoch(PurchaseDate))
{
SetMessage("Invalid Purchase Date.");
return false;
}
if(Utility.IsEpoch(SellDate))
{
SetMessage("Invalid Sell Date.");
return false;
}
if(!dateGenerator.IsMarketOpen(SellDate))
{
SetMessage("Market closed on Sell Date.");
return false;
}
if(double.IsNaN(SellPrice))
{
SetMessage("Invalid Sell Price.");
return false;
}
SetMessage("");
return true;
}
private void UpdateSellPrice()
{
txtSellPrice.Text=Utility.FormatCurrency(SellPrice);
}
private void UpdateCompanyName()
{
CompanyProfile companyProfile=CompanyProfileDA.GetCompanyProfile(Symbol);
if(null==companyProfile||null==companyProfile.CompanyName) return;
lblCompanyName.Content=companyProfile.CompanyName.ToUpper();
}
private void SetMessage(String message)
{
lblMessage.Content=message;
}
}
}

View File

@@ -0,0 +1,57 @@
<Window x:Class="TradeBlotter.UIUtils.ClosePositionDialogNoStop"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Close Position" Height="260" Width="200"
xmlns:wpfx="http://schemas.xceed.com/wpf/xaml/toolkit"
WindowStartupLocation="CenterScreen"
SizeToContent="WidthAndHeight"
MinWidth="200"
MinHeight="200"
WindowStyle="SingleBorderWindow"
ResizeMode="CanMinimize">
<wpfx:BusyIndicator Name="BusyBar" IsBusy="{Binding Path=BusyIndicator}" BusyContent="{Binding Path=BusyContent}">
<StackPanel Margin="5" Orientation="Vertical">
<Grid DockPanel.Dock="Left" Margin="0,2,4,2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="6" />
<ColumnDefinition Width="75*" />
<ColumnDefinition Width="6" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="20*" />
<RowDefinition Height="25" />
<RowDefinition Height="25" />
<RowDefinition Height="25" />
<RowDefinition Height="25" />
<RowDefinition Height="25" />
<RowDefinition Height="25" />
<RowDefinition Height="25" />
<RowDefinition Height="25" />
<RowDefinition Height="25" />
</Grid.RowDefinitions>
<Label Name="lblCompanyName" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="3"></Label>
<Label Name="lblSymbol" Grid.Row="2" Grid.Column="0">Symbol</Label>
<TextBox Name="txtSymbol" IsEnabled="False" Grid.Row="2" IsReadOnly="True" Grid.Column="2" MinWidth="75" AcceptsReturn="true">Symbol</TextBox>
<Label Name="lblPurchaseDate" Grid.Row="3" Grid.Column="0" MinWidth="75">Purchase Date</Label>
<DatePicker Name="dpPurchaseDate" IsEnabled="False" Grid.Row="3" Grid.Column="2"></DatePicker>
<Label Name="lblSellDate" Grid.Row="4" Grid.Column="0" MinWidth="75">Sell Date</Label>
<DatePicker Name="dpSellDate" Grid.Row="4" Grid.Column="2" SelectedDateChanged="dpSellDate_SelectionChanged"></DatePicker>
<Label Name="lblSellPrice" Grid.Row="5" Grid.Column="0">Sell Price</Label>
<TextBox Name="txtSellPrice" Grid.Row="5" Grid.Column="2" MinWidth="75" LostFocus="txtSellPrice_OnLostFocusHandler" KeyDown="txtSellPrice_OnKeyDownHandler">100.00</TextBox>
<Label FontWeight="Bold" FontSize="10" Name="lblSellPriceInstructions" Grid.Row="6" Grid.Column="0" Grid.ColumnSpan="3">(enter sell price then hit enter key)</Label>
<Label Name="lblMessage" Grid.Row="8" Grid.Column="0" Grid.ColumnSpan="5"></Label>
<Button Content="_Ok" MinWidth="75" IsDefault="False" Margin="2" Name="btnOk" Click="btnOk_Click" Grid.Row="9" Grid.Column="0"/>
<Button Content="_Cancel" MinWidth="75" IsCancel="True" Margin="2" Name="btnCancel" Click="btnCancel_Click" Grid.Row="9" Grid.Column="2"/>
</Grid>
</StackPanel>
</wpfx:BusyIndicator>
</Window>

View File

@@ -0,0 +1,203 @@
using MarketData.DataAccess;
using MarketData.Generator.Interface;
using MarketData.MarketDataModel;
using MarketData.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Media;
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 Position=MarketData.Generator.CMTrend.Position;
namespace TradeBlotter.UIUtils
{
/// <summary>
/// Interaction logic for ClosePositionDialogNoStop.xaml
/// </summary>
public partial class ClosePositionDialogNoStop : Window
{
private ManualResetEvent manualResetEvent=new ManualResetEvent(false);
private String Symbol{get;set;}
private DateTime PurchaseDate { get; set; }
private DateTime SellDate{get;set;}
private double SellPrice { get; set; }
private bool Result { get; set; }
private ClosePositionDialogNoStop(String title,IPurePosition position)
{
this.Background=new SolidColorBrush(Colors.AliceBlue);
this.Owner=Application.Current.MainWindow;
InitializeComponent();
this.Loaded+=new RoutedEventHandler(ClosePositionDialogNoStop_Loaded);
this.Closing+=Window_Closing;
dpPurchaseDate.SelectedDateChanged+=dpPurchaseDate_SelectionChanged;
dpSellDate.SelectedDateChanged+=dpPurchaseDate_SelectionChanged;
Title=title;
Symbol=position.Symbol;
PurchaseDate=position.PurchaseDate;
if(Utility.IsEpoch(position.SellDate))
{
SellDate = DateTime.Now;
}
else
{
SellDate=position.SellDate;
}
// SellPrice=position.TrailingStopLimit;
txtSymbol.Text=Symbol;
dpPurchaseDate.SelectedDate=PurchaseDate;
dpSellDate.SelectedDate=SellDate;
UpdateSellPrice();
UpdateCompanyName();
}
public ManualResetEvent Event
{
get
{
return manualResetEvent;
}
}
public static IPurePosition Prompt(string title,IPurePosition position)
{
ClosePositionDialogNoStop closePositionDialog=new ClosePositionDialogNoStop(title,position);
try { closePositionDialog.ShowDialog(); }
catch(Exception) { return null; }
closePositionDialog.Event.WaitOne();
if( closePositionDialog.Result)
{
position.SellDate=closePositionDialog.SellDate;
position.CurrentPrice=closePositionDialog.SellPrice;
return position;
}
return null;
}
void ClosePositionDialogNoStop_Loaded(object sender,RoutedEventArgs e)
{
txtSellPrice.Focus();
}
private void btnOk_Click(object sender,RoutedEventArgs e)
{
Result=Validate();
if(!Result)
{
SystemSounds.Beep.Play();
return;
}
Close();
Event.Set();
return;
}
private void txtSellPrice_OnLostFocusHandler(Object sender,RoutedEventArgs routedEventArgs)
{
HandleSellPriceEvents();
}
private void txtSellPrice_OnKeyDownHandler(object sender,KeyEventArgs e)
{
if(e.Key==Key.Return)
{
HandleSellPriceEvents();
}
}
private void HandleSellPriceEvents()
{
double value=0.00;
value=Utility.ParseCurrency(txtSellPrice.Text);
if(SellPrice.Equals(value)) return;
SellPrice=value;
UpdateSellPrice();
}
private void dpPurchaseDate_SelectionChanged(object sender,RoutedEventArgs e)
{
if(null==dpPurchaseDate.SelectedDate) return;
PurchaseDate=dpPurchaseDate.SelectedDate.Value;
}
private void dpSellDate_SelectionChanged(object sender,RoutedEventArgs e)
{
if(null==dpSellDate.SelectedDate) return;
SellDate=dpSellDate.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)
{
SetMessage("Invalid Symbol.");
return false;
}
if(Utility.IsEpoch(PurchaseDate))
{
SetMessage("Invalid Purchase Date.");
return false;
}
if(Utility.IsEpoch(SellDate))
{
SetMessage("Invalid Sell Date.");
return false;
}
if(!dateGenerator.IsMarketOpen(SellDate))
{
SetMessage("Market closed on Sell Date.");
return false;
}
if(double.IsNaN(SellPrice))
{
SetMessage("Invalid Sell Price.");
return false;
}
SetMessage("");
return true;
}
private void UpdateSellPrice()
{
txtSellPrice.Text=Utility.FormatCurrency(SellPrice);
}
private void UpdateCompanyName()
{
CompanyProfile companyProfile=CompanyProfileDA.GetCompanyProfile(Symbol);
if(null==companyProfile||null==companyProfile.CompanyName) return;
lblCompanyName.Content=companyProfile.CompanyName.ToUpper();
}
private void SetMessage(String message)
{
lblMessage.Content=message;
}
}
}

View File

@@ -0,0 +1,66 @@
<Window x:Class="TradeBlotter.UIUtils.EditPositionDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Edit Position" Height="319.586" Width="196.793"
xmlns:wpfx="http://schemas.xceed.com/wpf/xaml/toolkit"
WindowStartupLocation="CenterScreen"
SizeToContent="WidthAndHeight"
MinWidth="200"
MinHeight="340"
WindowStyle="SingleBorderWindow"
ResizeMode="CanMinimize">
<wpfx:BusyIndicator Name="BusyBar" IsBusy="{Binding Path=BusyIndicator}" BusyContent="{Binding Path=BusyContent}">
<StackPanel Margin="5" Orientation="Vertical">
<Grid DockPanel.Dock="Left" Margin="0,2,4,2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="6" />
<ColumnDefinition Width="75*" />
<ColumnDefinition Width="6" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="20*" />
<RowDefinition Height="25" />
<RowDefinition Height="25" />
<RowDefinition Height="25" />
<RowDefinition Height="25" />
<RowDefinition Height="25" />
<RowDefinition Height="25" />
<RowDefinition Height="25" />
<RowDefinition Height="25" />
<RowDefinition Height="25" />
<RowDefinition Height="25" />
<RowDefinition Height="25" />
<RowDefinition Height="25" />
</Grid.RowDefinitions>
<Label Name="lblCompanyName" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="3"></Label>
<Label Name="lblSymbol" Grid.Row="2" Grid.Column="0">Symbol</Label>
<TextBox Name="txtSymbol" IsEnabled="False" Grid.Row="2" IsReadOnly="True" Grid.Column="2" MinWidth="75" AcceptsReturn="true">Symbol</TextBox>
<Label Name="lblPurchaseDate" Grid.Row="3" Grid.Column="0" MinWidth="75">Purchase Date</Label>
<DatePicker Name="dpPurchaseDate" IsEnabled="False" Grid.Row="3" Grid.Column="2"></DatePicker>
<Label Name="lblPurchasePrice" Grid.Row="4" Grid.Column="0" MinWidth="75">Purchase Price</Label>
<TextBox Name="txtPurchasePrice" Grid.Row="4" Grid.Column="2" LostFocus="txtPurchasePrice__OnLostFocusHandler" KeyDown="txtPurchasePrice_OnKeyDownHandler"></TextBox>
<Label FontWeight="Bold" FontSize="10" Name="lblPurchasePriceInstructions" Grid.Row="5" Grid.Column="0" Grid.ColumnSpan="3">(enter purchase price then hit enter key)</Label>
<Label Name="lblInitialStop" Grid.Row="6" Grid.Column="0">Initial Stop</Label>
<TextBox Name="txtInitialStop" Grid.Row="6" Grid.Column="2" MinWidth="75" LostFocus="txtInitialStop__OnLostFocusHandler" KeyDown="txtInitialStop_OnKeyDownHandler">100.00</TextBox>
<CheckBox Name="cbSyncTrailingStop" Grid.Row="7" Grid.Column="0">Sync Trailing Stop</CheckBox>
<Label FontWeight="Bold" FontSize="10" Name="lblInitialStopInstructions" Grid.Row="8" Grid.Column="0" Grid.ColumnSpan="3">(enter initial stop then hit enter key)</Label>
<Label FontWeight="Bold" FontSize="10" Name="lblInitialStopRecommendation" Grid.Row="9" Grid.Column="0" Grid.ColumnSpan="3"></Label>
<Label Name="lblTrailingStop" Grid.Row="10" Grid.Column="0">Trailing Stop</Label>
<TextBox Name="txtTrailingStop" Grid.Row="10" Grid.Column="2" MinWidth="75" LostFocus="txtTrailingStop__OnLostFocusHandler" KeyDown="txtTrailingStop_OnKeyDownHandler">100.00</TextBox>
<Label FontWeight="Bold" FontSize="10" Name="lblTrailingStopInstructions" Grid.Row="11" Grid.Column="0" Grid.ColumnSpan="3">(enter trailing stop then hit enter key)</Label>
<Button Content="_Ok" MinWidth="75" IsDefault="False" Margin="2" Name="btnOk" Click="btnOk_Click" Grid.Row="12" Grid.Column="0"/>
<Button Content="_Cancel" MinWidth="75" IsCancel="True" Margin="2" Name="btnCancel" Click="btnCancel_Click" Grid.Row="12" Grid.Column="2"/>
</Grid>
</StackPanel>
</wpfx:BusyIndicator>
</Window>

View File

@@ -0,0 +1,229 @@
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;
using MarketData.Generator.Interface;
namespace TradeBlotter.UIUtils
{
/// <summary>
/// Interaction logic for EditPositionDialog.xaml
/// </summary>
public partial class EditPositionDialog : 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 EditPositionDialog(String title,IPosition position)
{
this.Background=new SolidColorBrush(Colors.AliceBlue);
this.Owner=Application.Current.MainWindow;
InitializeComponent();
this.Loaded+=new RoutedEventHandler(EditPositionDialog_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 IPosition Prompt(string title,IPosition position)
{
EditPositionDialog editPositionDialog=new EditPositionDialog(title,position);
try { editPositionDialog.ShowDialog(); }
catch(Exception) { return null; }
editPositionDialog.Event.WaitOne();
if(editPositionDialog.Result)
{
position.PurchaseDate=editPositionDialog.PurchaseDate;
position.PurchasePrice=editPositionDialog.PurchasePrice;
position.TrailingStopLimit=editPositionDialog.TrailingStop;
position.InitialStopLimit=editPositionDialog.InitialStop;
return position;
}
return null;
}
void EditPositionDialog_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();
}
}
}

View File

@@ -0,0 +1,50 @@
<Window x:Class="TradeBlotter.UIUtils.EditPositionDialogNoStop"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Edit Position" Height="209.665" Width="196.793"
xmlns:wpfx="http://schemas.xceed.com/wpf/xaml/toolkit"
WindowStartupLocation="CenterScreen"
SizeToContent="WidthAndHeight"
MinWidth="200"
MinHeight="210"
WindowStyle="SingleBorderWindow"
ResizeMode="CanMinimize">
<wpfx:BusyIndicator Name="BusyBar" IsBusy="{Binding Path=BusyIndicator}" BusyContent="{Binding Path=BusyContent}">
<StackPanel Margin="5" Orientation="Vertical">
<Grid DockPanel.Dock="Left" Margin="0,2,4,2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="6" />
<ColumnDefinition Width="75*" />
<ColumnDefinition Width="6" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="20*" />
<RowDefinition Height="25" />
<RowDefinition Height="25" />
<RowDefinition Height="25" />
<RowDefinition Height="25" />
<RowDefinition Height="25" />
<RowDefinition Height="25" />
</Grid.RowDefinitions>
<Label Name="lblCompanyName" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="3"></Label>
<Label Name="lblSymbol" Grid.Row="2" Grid.Column="0">Symbol</Label>
<TextBox Name="txtSymbol" IsEnabled="False" Grid.Row="2" IsReadOnly="True" Grid.Column="2" MinWidth="75" AcceptsReturn="true">Symbol</TextBox>
<Label Name="lblPurchaseDate" Grid.Row="3" Grid.Column="0" MinWidth="75">Purchase Date</Label>
<DatePicker Name="dpPurchaseDate" IsEnabled="False" Grid.Row="3" Grid.Column="2"></DatePicker>
<Label Name="lblPurchasePrice" Grid.Row="4" Grid.Column="0" MinWidth="75">Purchase Price</Label>
<TextBox Name="txtPurchasePrice" Grid.Row="4" Grid.Column="2" LostFocus="txtPurchasePrice__OnLostFocusHandler" KeyDown="txtPurchasePrice_OnKeyDownHandler"></TextBox>
<Label FontWeight="Bold" FontSize="10" Name="lblPurchasePriceInstructions" Grid.Row="5" Grid.Column="0" Grid.ColumnSpan="3">(enter purchase price then hit enter key)</Label>
<Button Content="_Ok" MinWidth="75" IsDefault="False" Margin="2" Name="btnOk" Click="btnOk_Click" Grid.Row="12" Grid.Column="0"/>
<Button Content="_Cancel" MinWidth="75" IsCancel="True" Margin="2" Name="btnCancel" Click="btnCancel_Click" Grid.Row="12" Grid.Column="2"/>
</Grid>
</StackPanel>
</wpfx:BusyIndicator>
</Window>

View File

@@ -0,0 +1,150 @@
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;
using MarketData.Generator.Interface;
namespace TradeBlotter.UIUtils
{
/// <summary>
/// Interaction logic for EditPositionDialogNoStop.xaml
/// </summary>
public partial class EditPositionDialogNoStop : Window
{
private ManualResetEvent manualResetEvent=new ManualResetEvent(false);
private String Symbol { get; set; }
private DateTime PurchaseDate { get; set; }
private double PurchasePrice{get;set;}
private bool Result { get; set; }
private EditPositionDialogNoStop(String title,IPurePosition position)
{
this.Background=new SolidColorBrush(Colors.AliceBlue);
this.Owner=Application.Current.MainWindow;
InitializeComponent();
this.Loaded+=new RoutedEventHandler(EditPositionDialog_Loaded);
this.Closing+=Window_Closing;
dpPurchaseDate.SelectedDateChanged+=dpPurchaseDate_SelectionChanged;
Title=title;
Symbol=position.Symbol;
PurchaseDate=position.PurchaseDate;
PurchasePrice=position.PurchasePrice;
txtSymbol.Text=Symbol;
dpPurchaseDate.SelectedDate=PurchaseDate;
UpdatePurchasePrice();
UpdateCompanyName();
}
public ManualResetEvent Event { get { return manualResetEvent; } }
public static IPurePosition Prompt(string title,IPurePosition position)
{
EditPositionDialogNoStop editPositionDialog=new EditPositionDialogNoStop(title,position);
try { editPositionDialog.ShowDialog(); }
catch(Exception) { return null; }
editPositionDialog.Event.WaitOne();
if(editPositionDialog.Result)
{
position.PurchaseDate=editPositionDialog.PurchaseDate;
position.PurchasePrice=editPositionDialog.PurchasePrice;
return position;
}
return null;
}
void EditPositionDialog_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();
}
private void UpdatePurchasePrice()
{
txtPurchasePrice.Text=Utility.FormatCurrency(PurchasePrice);
}
// *********************************************************************************************************************************************************************************
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;
return true;
}
private void UpdateCompanyName()
{
CompanyProfile companyProfile=CompanyProfileDA.GetCompanyProfile(Symbol);
if(null==companyProfile||null==companyProfile.CompanyName) return;
lblCompanyName.Content=companyProfile.CompanyName.ToUpper();
}
}
}