using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Xml; using TradeIdeas.TIProData; using TradeIdeas.TIProData.Configuration; using TradeIdeas.TIProData.Interfaces; using TradeIdeas.XML; namespace TradeIdeas.TIProGUI { public partial class OddsMakerConfiguration : Form { private IConnectionMaster _connectionMaster; private ISendManager _sendManager; private AlertForm _alertForm; public AlertForm AlertForm { get { return _alertForm; } } private List _phrases; private FontManager _fontManager; private const float DEFAULT_FONT_SIZE = 9.75F; private List _commonPhrases; private List _oddsMakerConfig; private OddsMakerColumnConfiguration _columnConfigType = GuiEnvironment.OddsMakerColumnConfigType; private XmlNode _location; private string _exitCondition; private string _windowName; private string _alertConfig; private const int TRACKBAR_TICK_HORIZONTAL_BORDER = 15; private OddsMakerConfigMemento _memento = new OddsMakerConfigMemento(); //for default settings(Visual Studio) private OddsMakerConfigMemento _userOddsSetting; //for saving user's current setting. private OddsMakerResults _result = null; private FlowLayoutPanel _panelBrowser = new FlowLayoutPanel(); public OddsMakerRequest _request = new OddsMakerRequest(); public OddsMakerConfiguration(string alertConfig, IConnectionMaster connectionMaster,string windowName,AlertForm alertForm,OddsMakerConfigMemento userOddsSetting) { _connectionMaster = connectionMaster; _sendManager = _connectionMaster.SendManager; _windowName = windowName; _alertConfig = alertConfig; _userOddsSetting = userOddsSetting; _request.SuccessDirectionUp = _userOddsSetting.Long; _exitCondition = ""; _alertForm = alertForm; InitializeComponent(); _location = GuiEnvironment.XmlConfig.Node("ODDSMAKER").Node("LOCATIONS").Select(); _phrases = GuiEnvironment.XmlConfig.Node("ODDSMAKER").Node("PHRASES"); _commonPhrases = GuiEnvironment.XmlConfig.Node("COMMON_PHRASES"); _oddsMakerConfig = GuiEnvironment.XmlConfig.Node("ODDSMAKER").Node("ODDSMAKER_CONFIG"); Icon = GuiEnvironment.Icon; Location = new Point(_alertForm.oddsLocation_X, _alertForm.oddsLocation_Y); //instead of hardcoding the maximum value of the below trackbar, we get this value from the server. trackBarDailyExitDays.Maximum = trackBarTestDays.Maximum = GuiEnvironment.GetGeneralInfo(_connectionMaster.SendManager).GetOddsMakerDays(); labelTestDaysMax.Text = GuiEnvironment.GetGeneralInfo(_connectionMaster.SendManager).GetOddsMakerDays().ToString(); PopulateStrings(); SetSlidersMinMax(); _memento.makeANote(this); //save snapshot of default state of the OddsMakerConfig if ( _userOddsSetting.isNew == true) { //This "if" block tests for an "empty" _userOddsSetting. //That's the case where we're pulling up an alert window and using the oddsmaker for //the very first time. Thus it is a brand new _userOddsSetting object being passed to //this form, which is "empty". So, default to the actual window design's settings... this.restoreDefault(_memento); } else { this.restoreDefault(_userOddsSetting); } _fontManager = new FontManager(this, DEFAULT_FONT_SIZE); selectTheFont(); InitializeTimeSliders(); if (rdoExitCondPercent.Checked || rdoExitCondBars.Checked || rdoExitCondAnotherAlert.Checked) ToggleAdvancedSection(false); else ToggleAdvancedSection(true); UpdateColumnConfigStatus(); Shown += new EventHandler(OddsMakerConfiguration_Shown); RequestFilters(); FixStopAndTargetGuiState(); } /// /// Requests the filters available to populate the comboboxes. /// private void RequestFilters() { ConfigurationWindowManager configManager = new ConfigurationWindowManager(); configManager.LoadFromServer(_connectionMaster, ConfigurationType.Alerts, OnConfigLoaded, _alertConfig); } /// /// List of available filters from the server. Requested upon starting this form. /// private List _filters = new List(); private void OnConfigLoaded(ConfigurationWindowManager configManager) { _filters.Clear(); _filters = configManager.FiltersInOrder.ToList(); PopulateFilters(); } private string _targetFilter = ""; private string _stopFilter = ""; private void PopulateFilters() { this.InvokeIfRequired(delegate() { comboBoxTargetFilter.DataSource = new BindingSource(_filters, null); comboBoxTargetFilter.DisplayMember = "Description"; comboBoxTargetFilter.ValueMember = "InternalCode"; comboBoxStopFilter.DataSource = new BindingSource(_filters, null); comboBoxStopFilter.DisplayMember = "Description"; comboBoxStopFilter.ValueMember = "InternalCode"; if (_targetFilter != "" && _filters.Where(x => x.InternalCode == _targetFilter).Count() > 0) { Filter filter = _filters.Where(x => x.InternalCode == _targetFilter).First(); comboBoxTargetFilter.SelectedValue = filter; } else comboBoxTargetFilter.SelectedIndex = 0; if (_stopFilter != "" && _filters.Where(x => x.InternalCode == _stopFilter).Count() > 0) { Filter filter = _filters.Where(x => x.InternalCode == _stopFilter).First(); comboBoxStopFilter.SelectedValue = filter; } else comboBoxStopFilter.SelectedIndex = 0; FixStopAndTargetGuiState(); }); } /// /// Enables/disables/hides/shows appropriate gui controls based on current selections. /// private void FixStopAndTargetGuiState() { this.InvokeIfRequired(delegate() { checkBoxUseStopFilter.Enabled = chkStopLoss.Checked; checkBoxUseTargetFilter.Enabled = chkProfitTarget.Checked; txtStopLoss.Enabled = !checkBoxUseStopFilter.Checked && chkStopLoss.Checked; txtProfitTarget.Enabled = !checkBoxUseTargetFilter.Checked && chkProfitTarget.Checked; comboBoxStopFilter.Enabled = chkStopLoss.Checked && checkBoxUseStopFilter.Checked; comboBoxTargetFilter.Enabled = chkProfitTarget.Checked && checkBoxUseTargetFilter.Checked; }); } void OddsMakerConfiguration_Shown(object sender, EventArgs e) { HighlightBuySell(); } /// /// Makes appropriate GUI changes to highlight whether this strategy goes long or short /// private void HighlightBuySell() { if (_request.SuccessDirectionUp) { Font boldFont = new Font(btnSimulateBuy.Font, FontStyle.Bold); btnSimulateBuy.Font = boldFont; Font normalFont = new Font(btnSimulateSell.Font, FontStyle.Regular); btnSimulateSell.Font = normalFont; btnSimulateBuy.Focus(); boldFont.Dispose(); normalFont.Dispose(); } else { Font boldFont = new Font(btnSimulateSell.Font, FontStyle.Bold); btnSimulateSell.Font = boldFont; Font normalFont = new Font(btnSimulateBuy.Font, FontStyle.Regular); btnSimulateBuy.Font = normalFont; btnSimulateSell.Focus(); boldFont.Dispose(); normalFont.Dispose(); } } Size _preHelpScreenFormSize; private void ShowHelpScreen() { _preHelpScreenFormSize = Size; Size = new Size(panelEntrySection.Width + 200, Size.Height); _panelBrowser = new FlowLayoutPanel(); _panelBrowser.Size = new Size(Size.Width - 40, panelButtons.Bottom); _panelBrowser.Location = new Point(panelEntrySection.Left, panelEntrySection.Top); _panelBrowser.WrapContents = true; WebBrowser browser = new WebBrowser(); string url = _oddsMakerConfig.Node("CONFIG_HELP_URL").PropertyForCulture("VALUE", "http://www.trade-ideas.com/OddsMaker/Help.html"); browser.Url = new Uri(url); browser.ScriptErrorsSuppressed = true; browser.Size = new Size(_panelBrowser.Width - 2, _panelBrowser.Height - 40); browser.Location = new Point(_panelBrowser.Left + 2, _panelBrowser.Top + 2); _panelBrowser.Controls.Add(browser); Button buttonCloseHelp = new Button(); buttonCloseHelp.Text = "Close Help"; buttonCloseHelp.Click += new EventHandler(buttonCloseHelp_Click); _panelBrowser.Controls.Add(buttonCloseHelp); Controls.Add(_panelBrowser); _panelBrowser.BringToFront(); buttonShowHelp.Enabled = false; panelButtons.Visible = false; //Hide panel buttons } void buttonCloseHelp_Click(object sender, EventArgs e) { Controls.Remove(_panelBrowser); Size = _preHelpScreenFormSize; panelButtons.Visible = true; //Show panel buttons buttonShowHelp.Enabled = true; _panelBrowser.Dispose(); } private void HideHelpScreen() { } private void SetSlidersMinMax() { DateTime marketOpenLocal = GuiEnvironment.GetMarketOpenLocalTime(); DateTime marketCloseLocal = GuiEnvironment.GetMarketCloseLocalTime(); TimeSpan span = marketCloseLocal - marketOpenLocal; int totalMinutes = (int)span.TotalMinutes; trackBarEndTime.Maximum = 0; trackBarEndTime.Minimum = -totalMinutes; trackBarStartTime.Minimum = 0; trackBarStartTime.Maximum = totalMinutes; trackBarTimeStop.Maximum = 0; trackBarTimeStop.Minimum = -totalMinutes; trackBarTimeAfterEntry.Minimum = 1; int minutesInTradingDay = (int)(marketCloseLocal - marketOpenLocal).TotalMinutes; trackBarTimeAfterEntry.Maximum = minutesInTradingDay; labelTimeAfterEntryMax.Text = minutesInTradingDay + " min"; } private void InitializeTimeSliders() { trackBarStartTime.ValueChanged += new EventHandler(trackBarStartTime_ValueChanged); trackBarEndTime.ValueChanged += new EventHandler(trackBarEndTime_ValueChanged); trackBarTimeStop.Scroll += new EventHandler(trackBarTimeStop_Scroll); trackBarTestDays.Scroll += new EventHandler(trackBarTestDays_Scroll); trackBarDailyExitDays.Scroll += new EventHandler(trackBarDailyExitDays_Scroll); trackBarTimeAfterEntry.Scroll += new EventHandler(trackBarTimeAfterEntry_Scroll); SetStartTime(); SetEndTime(); SetTimeStop(); SetTestDays(); SetDailyExitDays(); SetTimeAfterEntryExit(); labelEndTimeMax.Text = GuiEnvironment.GetMarketCloseLocalTime().ToShortTimeString(); labelStartTimeMax.Text = GuiEnvironment.GetMarketCloseLocalTime().ToShortTimeString(); labelEndTimeMin.Text = GuiEnvironment.GetMarketOpenLocalTime().ToShortTimeString(); labelStartTimeMin.Text = GuiEnvironment.GetMarketOpenLocalTime().ToShortTimeString(); labelTimeStopMax.Text = GuiEnvironment.GetMarketCloseLocalTime().ToShortTimeString(); labelTimeStopMin.Text = GuiEnvironment.GetMarketOpenLocalTime().ToShortTimeString(); UpdateExitConfigStatus(); } private void trackBarStartTime_ValueChanged(object sender, EventArgs e) { // starttime has min of 0, but endtime has max of zero, so we need to convert to time of day DateTime startTime = GuiEnvironment.GetMarketOpenLocalTime().AddMinutes(trackBarStartTime.Value); DateTime endTime = GuiEnvironment.GetMarketCloseLocalTime().AddMinutes(trackBarEndTime.Value); if (startTime >= endTime) trackBarStartTime.Value = (int)(endTime - GuiEnvironment.GetMarketOpenLocalTime()).TotalMinutes - 1; SetStartTime(); } void trackBarEndTime_ValueChanged(object sender, EventArgs e) { // starttime has min of 0, but endtime has max of zero, so we need to convert to time of day DateTime startTime = GuiEnvironment.GetMarketOpenLocalTime().AddMinutes(trackBarStartTime.Value); DateTime endTime = GuiEnvironment.GetMarketCloseLocalTime().AddMinutes(trackBarEndTime.Value); if (startTime >= endTime) trackBarEndTime.Value = (int)(startTime - GuiEnvironment.GetMarketCloseLocalTime()).TotalMinutes + 1; SetEndTime(); } void trackBarTimeAfterEntry_Scroll(object sender, EventArgs e) { SetTimeAfterEntryExit(); } private void SetTimeAfterEntryExit() { this.InvokeIfRequired(delegate() { labelTimeAfterEntryValue.Text = trackBarTimeAfterEntry.Value.ToString(); SizeF labelSize = CreateGraphics().MeasureString(labelTimeAfterEntryValue.Text, Font); double percentMax = (double)(trackBarTimeAfterEntry.Value - trackBarTimeAfterEntry.Minimum) / (trackBarTimeAfterEntry.Maximum - trackBarTimeAfterEntry.Minimum); int tickX = (int)Math.Round((trackBarTimeAfterEntry.Right - TRACKBAR_TICK_HORIZONTAL_BORDER - trackBarTimeAfterEntry.Left - TRACKBAR_TICK_HORIZONTAL_BORDER) * percentMax, 0) + trackBarTimeAfterEntry.Left + TRACKBAR_TICK_HORIZONTAL_BORDER - (int)(labelSize.Width / 2); Point tickPoint = labelTimeAfterEntryValue.Location; tickPoint.X = tickX; labelTimeAfterEntryValue.Location = tickPoint; }); } void trackBarDailyExitDays_Scroll(object sender, EventArgs e) { SetDailyExitDays(); } void trackBarTestDays_Scroll(object sender, EventArgs e) { SetTestDays(); } private void SetDailyExitDays() { this.InvokeIfRequired(delegate() { //labelDailyExitDaysValue.Text = trackBarDailyExitDays.Value.ToString(); string exitAtTheCloseOpen = "Open"; if (rdoExitTimeFutureClose.Checked) exitAtTheCloseOpen = "Close"; labelDailyExitDaysValue.Text = ""; if (trackBarDailyExitDays.Value == 0) labelDaysLater.Text = "Tomorrow at the " + exitAtTheCloseOpen; else if (trackBarDailyExitDays.Value == 1) labelDaysLater.Text = "Day after tomorrow (tomorrow + 1 day) at the " + exitAtTheCloseOpen; else if (trackBarDailyExitDays.Value > 1) labelDaysLater.Text = "Tomorrow + " + trackBarDailyExitDays.Value.ToString() + " days at the " + exitAtTheCloseOpen; SizeF labelSize = CreateGraphics().MeasureString(labelDailyExitDaysValue.Text, Font); double percentMax = (double)(trackBarDailyExitDays.Value - trackBarDailyExitDays.Minimum) / (trackBarDailyExitDays.Maximum - trackBarDailyExitDays.Minimum); int tickX = (int)Math.Round((trackBarDailyExitDays.Right - TRACKBAR_TICK_HORIZONTAL_BORDER - trackBarDailyExitDays.Left - TRACKBAR_TICK_HORIZONTAL_BORDER) * percentMax, 0) + trackBarDailyExitDays.Left + TRACKBAR_TICK_HORIZONTAL_BORDER - (int)(labelSize.Width / 2); Point tickPoint = labelDailyExitDaysValue.Location; tickPoint.X = tickX; labelDailyExitDaysValue.Location = tickPoint; }); } private void SetTestDays() { this.InvokeIfRequired(delegate() { labelTestDaysValue.Text = trackBarTestDays.Value.ToString(); SizeF labelSize = CreateGraphics().MeasureString(labelTestDaysValue.Text, Font); double percentMax = (double)(trackBarTestDays.Value - trackBarTestDays.Minimum) / (trackBarTestDays.Maximum - trackBarTestDays.Minimum); int tickX = (int)Math.Round((trackBarTestDays.Right - TRACKBAR_TICK_HORIZONTAL_BORDER - trackBarTestDays.Left - TRACKBAR_TICK_HORIZONTAL_BORDER) * percentMax, 0) + trackBarTestDays.Left + TRACKBAR_TICK_HORIZONTAL_BORDER - (int)(labelSize.Width / 2); Point tickPoint = labelTestDaysValue.Location; tickPoint.X = tickX; labelTestDaysValue.Location = tickPoint; }); } void trackBarTimeStop_Scroll(object sender, EventArgs e) { SetTimeStop(); } private void SetTimeStop() { this.InvokeIfRequired(delegate() { DateTime currentTimeStop = GuiEnvironment.GetMarketCloseLocalTime().AddMinutes((double)trackBarTimeStop.Value); labelTimeStopValue.Text = currentTimeStop.ToShortTimeString(); SizeF labelSize = CreateGraphics().MeasureString(labelEndTimeValue.Text, Font); double percentMax = (double)(trackBarTimeStop.Value - trackBarTimeStop.Minimum) / (trackBarTimeStop.Maximum - trackBarTimeStop.Minimum); int tickX = (int)Math.Round((trackBarTimeStop.Right - TRACKBAR_TICK_HORIZONTAL_BORDER - trackBarTimeStop.Left - TRACKBAR_TICK_HORIZONTAL_BORDER) * percentMax, 0) + trackBarTimeStop.Left + TRACKBAR_TICK_HORIZONTAL_BORDER - (int)(labelSize.Width / 2); Point tickPoint = labelTimeStopValue.Location; tickPoint.X = tickX; labelTimeStopValue.Location = tickPoint; }); } private void SetEndTime() { this.InvokeIfRequired(delegate() { DateTime currentEndTime = GuiEnvironment.GetMarketCloseLocalTime().AddMinutes((double)trackBarEndTime.Value); labelEndTimeValue.Text = currentEndTime.ToShortTimeString(); SizeF labelSize = CreateGraphics().MeasureString(labelEndTimeValue.Text, Font); double percentMax = (double)(trackBarEndTime.Value - trackBarEndTime.Minimum) / (trackBarEndTime.Maximum - trackBarEndTime.Minimum); int tickX = (int)Math.Round((trackBarEndTime.Right - TRACKBAR_TICK_HORIZONTAL_BORDER - trackBarEndTime.Left - TRACKBAR_TICK_HORIZONTAL_BORDER) * percentMax, 0) + trackBarEndTime.Left + TRACKBAR_TICK_HORIZONTAL_BORDER - (int)(labelSize.Width / 2); Point tickPoint = labelEndTimeValue.Location; tickPoint.X = tickX; labelEndTimeValue.Location = tickPoint; }); } void trackBarEndTime_Scroll(object sender, EventArgs e) { SetEndTime(); } private void SetStartTime() { this.InvokeIfRequired(delegate() { DateTime currentStartTime = GuiEnvironment.GetMarketOpenLocalTime().AddMinutes((double)trackBarStartTime.Value); labelStartTimeValue.Text = currentStartTime.ToShortTimeString(); SizeF labelSize = CreateGraphics().MeasureString(labelStartTimeValue.Text, Font); double percentMax = (double)(trackBarStartTime.Value - trackBarStartTime.Minimum) / (trackBarStartTime.Maximum - trackBarStartTime.Minimum); int tickX = (int)Math.Round((trackBarStartTime.Right - TRACKBAR_TICK_HORIZONTAL_BORDER - trackBarStartTime.Left - TRACKBAR_TICK_HORIZONTAL_BORDER) * percentMax, 0) + trackBarStartTime.Left + TRACKBAR_TICK_HORIZONTAL_BORDER - (int)(labelSize.Width / 2); Point tickPoint = labelStartTimeValue.Location; tickPoint.X = tickX; labelStartTimeValue.Location = tickPoint; }); } void trackBarStartTime_Scroll(object sender, EventArgs e) { SetStartTime(); } public void selectTheFont() { _fontManager.selectTheFont(); } private void PopulateStrings() { // TODO: The plan is to make this window resuable. But it might be hidden. So copy the // model form AlertColorPicker to make sure this method is called at the correct times. rdoByAtLeastDollar.Text = _phrases.Node("CURRENCY_SYMBOL").PropertyForCulture("TEXT", "***"); lblProfitTargetDollar.Text = _phrases.Node("CURRENCY_SYMBOL").PropertyForCulture("TEXT", "***"); lblStopLossDollar.Text = _phrases.Node("CURRENCY_SYMBOL").PropertyForCulture("TEXT", "***"); btnExitCondConfigure.Text = _phrases.Node("CONFIGURE").PropertyForCulture("TEXT", "***"); btnRestoreDefaults.Text = _phrases.Node("RESTORE_DEFAULTS").PropertyForCulture("TEXT", "***"); cancelButton.Text = _commonPhrases.Node("CANCEL").PropertyForCulture("TEXT", "***"); Text = _oddsMakerConfig.Node("TITLE_START").PropertyForCulture("TEXT", "***") + _windowName; //lblBackTest.Text = _oddsMakerConfig.Node("BACKTEST_SETUP").PropertyForCulture("TEXT", "***"); //lblStrategyTime.Text = _oddsMakerConfig.Node("STRATEGY_ENTRY_TIME_RANGE").PropertyForCulture("TEXT", "***"); labelInitiateTradesHeading.Text = _oddsMakerConfig.Node("INITIATE_TRADES_HEADING").PropertyForCulture("TEXT", "***"); lblEndtime.Text = _oddsMakerConfig.Node("END_TIME").PropertyForCulture("TEXT", "***"); lblStartTime.Text = _oddsMakerConfig.Node("START_TIME").PropertyForCulture("TEXT", "***"); //lblStartHour.Text = _oddsMakerConfig.Node("HOURS_AND").PropertyForCulture("TEXT", "***"); //lblEndHour.Text = _oddsMakerConfig.Node("HOURS_AND").PropertyForCulture("TEXT", "***"); //lblAfterOpen.Text = _oddsMakerConfig.Node("MINUTES_OPEN").PropertyForCulture("TEXT", "***"); //lblBeforeClose.Text = _oddsMakerConfig.Node("MINUTES_CLOSE").PropertyForCulture("TEXT", "***"); rdoExitTimeMinutesAfter.Text = _oddsMakerConfig.Node("AFTER_ENTRY").PropertyForCulture("TEXT", "***"); rdoExitTAtTheClose.Text = _oddsMakerConfig.Node("TIME_STOP_LABEL").PropertyForCulture("TEXT", "***"); rdoExitTimeAtTheOpen.Text = _oddsMakerConfig.Node("OPEN_AFTER_LABEL").PropertyForCulture("TEXT", "***"); rdoExitTimeFutureClose.Text = _oddsMakerConfig.Node("CLOSE_AFTER_LABEL").PropertyForCulture("TEXT", "***"); //ExitTimeGroupBox.Text = _oddsMakerConfig.Node("HOLD_POSITIONS").PropertyForCulture("TEXT", "***"); //ByAtLeastGroupBox.Text = _oddsMakerConfig.Node("SUCCESS").PropertyForCulture("TEXT", "***"); profitTargetGroupBox.Text = _oddsMakerConfig.Node("PROFIT_TARGET").PropertyForCulture("TEXT", "***"); chkProfitTarget.Text = _oddsMakerConfig.Node("CLOSE_POSITION").PropertyForCulture("TEXT", "***"); labelAdvancedExitsHeading.Text = _oddsMakerConfig.Node("ADVANCED_EXIT_HEADING").PropertyForCulture("TEXT", "***"); chkStopLoss.Text = _oddsMakerConfig.Node("STOP_LOSS_CLOSE").PropertyForCulture("TEXT", "***"); chkWiggle.Text = _oddsMakerConfig.Node("WIGGLE").PropertyForCulture("TEXT", "***"); labelAdvancedExitsHeading.Text = _oddsMakerConfig.Node("OTHER_EXIT").PropertyForCulture("TEXT", "***"); rdoExitCondNone.Text = _oddsMakerConfig.Node("NONE").PropertyForCulture("TEXT", "***"); rdoExitCondPercent.Text = _oddsMakerConfig.Node("PERCENT_TRAIL").PropertyForCulture("TEXT", "***"); rdoExitCondBars.Text = _oddsMakerConfig.Node("PERCENT_BARS").PropertyForCulture("TEXT", "***"); rdoExitCondAnotherAlert.Text = _oddsMakerConfig.Node("EXIT_STRATEGY").PropertyForCulture("TEXT", "***"); labelLocationHeading.Text = _oddsMakerConfig.Node("LOCATION").PropertyForCulture("TEXT", "***"); btnSimulateBuy.Text = _oddsMakerConfig.Node("SIMULATE_BUY").PropertyForCulture("TEXT", "***"); btnSimulateSell.Text = _oddsMakerConfig.Node("SIMULATE_SELL").PropertyForCulture("TEXT", "***"); // Try to restore the selection after (possibly) changing the language. int saveLocation = cboLocation.SelectedIndex; if (saveLocation < 0) { // If nothing was selected before (like the first time we display this window) select // the first item. saveLocation = 0; } // Remove any items we added last time. Start fresh every time. cboLocation.Items.Clear(); foreach (XmlNode currentRow in _location.Enum()) { string loc = ""; loc = currentRow.PropertyForCulture("TEXT", "***"); cboLocation.Items.Add(loc); } // Avoid a possible error. saveLocation = Math.Min(saveLocation, cboLocation.Items.Count - 1); cboLocation.SelectedIndex = saveLocation; } private void btnRestoreDefaults_Click(object sender, EventArgs e) { GuiEnvironment.RecordUseCase("OddsMakerConfig.Button.RestoreDefaults", _sendManager); restoreDefault(_memento); } public void restoreDefault(OddsMakerConfigMemento memento) { //Reset what shows in the form try { // we've combined the setting for these into a single slider in the new version // and we're storing the value for the slider in both values // however, in the event that the old settings are used, we still need to decide which // value to use depending on values of RDO_EXIT_TIME_FUTURE_CLOSE="True" RDO_EXIT_TIME_AT_THE_OPEN="False" int exitTimeOpenDays = memento.ExitTimeOpenDays; int exitTimeCloseDays = memento.ExitTimeCloseDays; int exitTimeDays = exitTimeOpenDays; if (memento.UseExitTimeFutureClose) exitTimeDays = exitTimeCloseDays; if (exitTimeDays > trackBarDailyExitDays.Maximum) trackBarDailyExitDays.Value = trackBarDailyExitDays.Maximum; else if (exitTimeDays < trackBarDailyExitDays.Minimum) trackBarDailyExitDays.Value = trackBarDailyExitDays.Minimum; else trackBarDailyExitDays.Value = exitTimeDays; } catch { trackBarDailyExitDays.Value = 1; } try { int timeStopMinutesBeforeClose = -memento.ExitTimeMinutesBefore; if (timeStopMinutesBeforeClose >= trackBarTimeStop.Minimum && timeStopMinutesBeforeClose <= trackBarTimeStop.Maximum) trackBarTimeStop.Value = timeStopMinutesBeforeClose; else trackBarTimeStop.Value = 0; } catch { trackBarTimeStop.Value = 0; } try { if (memento.ExitTimeMinutesAfter < trackBarTimeAfterEntry.Minimum) trackBarTimeAfterEntry.Value = trackBarTimeAfterEntry.Minimum; else if (memento.ExitTimeMinutesAfter > trackBarTimeAfterEntry.Maximum) trackBarTimeAfterEntry.Value = trackBarTimeAfterEntry.Maximum; else trackBarTimeAfterEntry.Value = memento.ExitTimeMinutesAfter; } catch { trackBarTimeAfterEntry.Value = 1; } //this.txtEntryHoursStart.Text = memento.txtEntryHoursStart; //this.txtEntryMinutesStart.Text = memento.txtEntryMinutesStart; //this.txtEntryHoursEnd.Text = memento.txtEntryHoursEnd; //this.txtEntryMinutesEnd.Text = memento.txtEntryMinutesEnd; // Check validity of user default before using it in the trackbar // Note: EntryMinuteStart >= 0 and EntryMinuteEnd <= 0 try { int startTimeMinutes = memento.EntryMinutesStart; int startTimeHours = memento.EntryMinutesStart; int totalMinutesFromStart = startTimeMinutes + startTimeHours * 60; if (totalMinutesFromStart < trackBarStartTime.Minimum) trackBarStartTime.Value = 0; else if (totalMinutesFromStart >= trackBarStartTime.Maximum) trackBarStartTime.Value = trackBarStartTime.Maximum - 1; else trackBarStartTime.Value = totalMinutesFromStart; } catch { // this catches the case where txtEntryMinutesStart can't be parsed as an int or any other exception. trackBarStartTime.Value = 0; } // Check validity of user default before using it in the trackbar try { DateTime startTime = GuiEnvironment.GetMarketOpenLocalTime().AddMinutes(trackBarStartTime.Value); // we need endtimeminutes as a negative number for the slider, but it's stored in the layout as a positive integer. int endTimeMinutes = memento.EntryMinutesEnd; int endTimeHours = memento.EntryHoursEnd; // saves in newer versions of OM will always have endTimeHours of 0, so this is in case the user has saved in earlier versions int totalMinutesFromEnd = endTimeMinutes + endTimeHours * 60; if (totalMinutesFromEnd > 0) totalMinutesFromEnd = -totalMinutesFromEnd; DateTime endTime = GuiEnvironment.GetMarketCloseLocalTime().AddMinutes(totalMinutesFromEnd); if (totalMinutesFromEnd <= trackBarEndTime.Minimum || startTime >= endTime) { // start time is after end time, set end time to start time + 1 minute trackBarEndTime.Value = (int)(startTime - GuiEnvironment.GetMarketCloseLocalTime()).TotalMinutes + 1; } else if (totalMinutesFromEnd > trackBarEndTime.Maximum) trackBarEndTime.Value = 0; else trackBarEndTime.Value = totalMinutesFromEnd; } catch { trackBarEndTime.Value = 0; } // Check validity of user default before using it in the trackbar try { if (memento.DaysOfTest < trackBarTestDays.Minimum || memento.DaysOfTest > trackBarTestDays.Maximum) trackBarTestDays.Value = trackBarTestDays.Maximum; else trackBarTestDays.Value = memento.DaysOfTest; } catch { trackBarTestDays.Value = trackBarTestDays.Maximum; } this.txtExitCondPercent.Text = ""; if (memento.ExitCondPercent.HasValue) this.txtExitCondPercent.Text = memento.ExitCondPercent.Value.ToString(); this.txtExitCondBars.Text = ""; if (memento.ExitCondBars.HasValue) this.txtExitCondBars.Text = memento.ExitCondBars.Value.ToString(); this.txtProfitTarget.Text = ""; if (memento.ProfitTarget.HasValue) this.txtProfitTarget.Text = memento.ProfitTarget.Value.ToString(); _targetFilter = memento.TargetFilter; checkBoxUseTargetFilter.Checked = memento.UseTargetFilter; this.txtStopLoss.Text = ""; if (memento.StopLoss.HasValue) this.txtStopLoss.Text = memento.StopLoss.Value.ToString(); _stopFilter = memento.StopFilter; checkBoxUseStopFilter.Checked = memento.UseStopFilter; //this.txtByAtLeastDollars.Text = memento.txtByAtLeastDollars; //this.txtByAtLeastPerCent.Text = memento.txtByAtLeastPerCent; //radio buttons... this.rdoByAtLeastDollar.Checked = memento.UseDollars; this.rdoExitCondNone.Checked = memento.UseNoAdvancedExit; this.rdoExitTimeMinutesAfter.Checked = memento.UseExitTimeMinutesAfter; this.rdoExitTAtTheClose.Checked = memento.UseExitAtTimeOfDay; this.rdoExitTimeFutureClose.Checked = memento.UseExitTimeFutureClose; this.rdoExitTimeAtTheOpen.Checked = memento.UseExitTimeFutureOpen; this.rdoByAtLeastPerCent.Checked = memento.UsePercent; this.rdoExitCondBars.Checked = memento.UseExitCondBars; this.rdoExitCondPercent.Checked = memento.UseExitCondPercent; this.rdoExitCondAnotherAlert.Checked = memento.UseExitCondAnotherAlert; this.rdoExitCondAnotherAlert.Enabled = memento.UseExitCondAnotherAlert; // if nothing is checked then check exit at time after trade entry if (!rdoExitTimeAtTheOpen.Checked && !rdoExitTAtTheClose.Checked && !rdoExitTimeFutureClose.Checked && !rdoExitTimeMinutesAfter.Checked) rdoExitTimeMinutesAfter.Checked = true; this.chkProfitTarget.Checked = memento.UseProfitTarget; this.chkStopLoss.Checked = memento.UseStopLoss; this.chkWiggle.Checked = memento.UseWiggle; this.cboLocation.SelectedIndex = memento.cboLocation; _exitCondition = memento.ExitCondition; SetEndTime(); SetStartTime(); SetDailyExitDays(); SetTestDays(); SetTimeAfterEntryExit(); SetTimeStop(); } /// /// Holds settings for OddsMaker. Can save and restore itself. /// public class OddsMakerConfigMemento :ICloneable { /*Utilize the memento design pattern to hold the default settings/user settings of the OddsMakerConfig Window*/ private bool _long = true; private int _daysOfTest = 30; //Initial default private int _daysToSkip; private int _exitTimeCloseDays; private int _exitTimeOpenDays; private int _exitTimeMinutesBefore; private int _exitTimeMinutesAfter = 60; //Initial default private int _entryHoursStart; private int _entryMinutesStart = 30; //Initial default private int _entryHoursEnd; private int _entryMinutesEnd = 60; //Initial default private double? _exitCondPercent = 0.5; private double? _exitCondBars = 0.5; private double? _profitTarget = 1.0; private double? _stopLoss = 1.0; private double _byAtLeastDollars; private double _byAtLeastPerCent; private string _exitCondition; //new private bool _rdoExitTAtTheClose; private bool _rdoExitTimeFutureClose; private bool _rdoExitTimeAtTheOpen; private bool _rdoByAtLeastDollar = true; //Initial default private bool _rdoByAtLeastPerCent; private bool _rdoExitCondNone = true; //Initial default private bool _rdoExitCondPercent; private bool _rdoExitCondBars; private bool _rdoExitTimeMinutesAfter = true; //Initial default private bool _rdoExitCondAnotherAlert; private bool _chkProfitTarget; private bool _chkStopLoss; private bool _chkWiggle; private bool _useStopFilter = false; private string _stopFilter = "SmartStopD"; //Initial default private bool _useTargetFilter = false; private string _targetFilter = "SmartStopD"; //Initial default private int _cboLocation; private bool _isNew; private OddsMakerConfiguration _default; public OddsMakerConfigMemento() { } /// /// true = long, false = short /// public bool Long { get { return _long; } set { _long = value; } } /// /// When the exit alert is enabled, this is the config. /// public string ExitCondition { get { return _exitCondition; } set { _exitCondition = value; } } /// /// Determines the number of days to test (1-30). /// public int DaysOfTest { get { return _daysOfTest; } set { _daysOfTest = value; } } /// /// Determines the number of days to skip (1-30). Deprecated - no longer displayed in the gui. /// public int DaysToSkip { get { return _daysToSkip; } set { _daysToSkip = value; } } /// /// The value for days when exiting at the close on a future date is selected (rdoExitTimeFutureClose). /// public int ExitTimeCloseDays { get { return _exitTimeCloseDays; } set { _exitTimeCloseDays = value; } } /// /// The value for days when exiting at the open on a future date is selected (rdoExitTimeAtTheOpen). /// public int ExitTimeOpenDays { get { return _exitTimeOpenDays; } set { _exitTimeOpenDays = value; } } /// /// When exit at time is checked (rdoExitAtTheClose) this determines the value on the slider. Represents minutes before the close. /// public int ExitTimeMinutesBefore { get { return _exitTimeMinutesBefore; } set { _exitTimeMinutesBefore = value; } } /// /// Determines the value 1-390 on the slider in the Minutes After Entry section in timed exits. /// public int ExitTimeMinutesAfter { get { return _exitTimeMinutesAfter; } set { _exitTimeMinutesAfter = value; } } /// /// Hours after the open to start trading /// public int EntryHoursStart { get { return _entryHoursStart; } set { _entryHoursStart = value; } } /// /// Minutes after the open to start trading /// public int EntryMinutesStart { get { return _entryMinutesStart; } set { _entryMinutesStart = value; } } /// /// Hours before the close to stop trading /// public int EntryHoursEnd { get { return _entryHoursEnd; } set { _entryHoursEnd = value; } } /// /// Minutes before the close to stop trading /// public int EntryMinutesEnd { get { return _entryMinutesEnd; } set { _entryMinutesEnd = value; } } /// /// Value for % Trailing Stop advanced exit. rdoExitCondPercent determines whether this setting is active. /// public double? ExitCondPercent { get { return _exitCondPercent; } set { _exitCondPercent = value; } } /// /// Value for Bars Trailing Stop advanced exit. rdoExitCondBars determines whether this setting is active. /// public double? ExitCondBars { get { return _exitCondBars; } set { _exitCondBars = value; } } /// /// Profit target offset. Depending on rdoByAtLeastDollar this could represent dollars or percent. /// public double? ProfitTarget { get { return _profitTarget; } set { _profitTarget = value; } } /// /// Stop loss offset. Depending on UseDollars this could represent dollars or percent. /// public double? StopLoss { get { return _stopLoss; } set { _stopLoss = value; } } /// /// Amount that a trade must go in your direction to count as a win. This is meant to provide a way to simulate commissions. /// public double ByAtLeastDollars { get { return _byAtLeastDollars; } set { _byAtLeastDollars = value; } } /// /// Amount that a trade must go in your direction to count as a win. This is meant to provide a way to simulate commissions. /// public double ByAtLeastPerCent { get { return _byAtLeastPerCent; } set { _byAtLeastPerCent = value; } } public bool UseDollars { get { return _rdoByAtLeastDollar; } set { _rdoByAtLeastDollar = value; } } /// /// true means no advanced exit conditions are selected /// public bool UseNoAdvancedExit { get { return _rdoExitCondNone; } set { _rdoExitCondNone = value; } } /// /// true means Minutes after entry is checked on the timed exit section. /// public bool UseExitTimeMinutesAfter { get { return _rdoExitTimeMinutesAfter; } set { _rdoExitTimeMinutesAfter = value; } } /// /// Determines whether the exit at time button is selected in the timed exits section. The value when this is checked is exitTimeMinutesBefore. /// public bool UseExitAtTimeOfDay { get { return _rdoExitTAtTheClose; } set { _rdoExitTAtTheClose = value; } } /// /// Determines whether exiting at a future close is selected. When active, the value is stored in exitTimeCloseDays. /// public bool UseExitTimeFutureClose { get { return _rdoExitTimeFutureClose; } set { _rdoExitTimeFutureClose = value; } } /// /// Determines whether exiting at a future open is selected. When active, the value is stored in exitTimeOpenDays. /// public bool UseExitTimeFutureOpen { get { return _rdoExitTimeAtTheOpen; } set { _rdoExitTimeAtTheOpen = value; } } /// /// Determines whether percents or dollars should be used for profit target, stop loss, and move by at least values. /// public bool UsePercent { get { return _rdoByAtLeastPerCent; } set { _rdoByAtLeastPerCent = value; } } /// /// Determines whether % Trailing Stop is selected on the advanced exits section. When active, the value is txtExitCondPercent. /// public bool UseExitCondPercent { get { return _rdoExitCondPercent; } set { _rdoExitCondPercent = value; } } /// /// Determines whether Bars Trailing Stop is selected on the advanced exits section. When active, the value is txtExitCondBars. /// public bool UseExitCondBars { get { return _rdoExitCondBars; } set { _rdoExitCondBars = value; } } /// /// true means exit alert is enabled. Exit alert config is stored in exitCondition. /// public bool UseExitCondAnotherAlert { get { return _rdoExitCondAnotherAlert; } set { _rdoExitCondAnotherAlert = value; } } /// /// Profit target is enabled = true, not enabled = false. /// public bool UseProfitTarget { get { return _chkProfitTarget; } set { _chkProfitTarget = value; } } /// /// true means a filter should be used for the profit target distance instead of a constant value. default is false. Filter name is defined in TargetFilter. /// public bool UseTargetFilter { get { return _useTargetFilter; } set { _useTargetFilter = value; } } /// /// Internal code for target filter to be used for profit target distance. /// public string TargetFilter { get { return _targetFilter; } set { _targetFilter = value; } } /// /// Stop loss is enabled = true, not enabled = false. /// public bool UseStopLoss { get { return _chkStopLoss; } set { _chkStopLoss = value; } } /// /// true means a filter should be used for the stop distance instead of a constant value. default is false. Filter name is defined in StopFilter. /// public bool UseStopFilter { get { return _useStopFilter; } set { _useStopFilter = value; } } /// /// Internal code for stop filter to be used for stop distance. /// public string StopFilter { get { return _stopFilter; } set { _stopFilter = value; } } /// /// Determines whether the + wiggle option is checked to add the wiggle value to the stop loss. /// public bool UseWiggle { get { return _chkWiggle; } set { _chkWiggle = value; } } public int cboLocation { get { return _cboLocation; } set { _cboLocation = value; } } public bool isNew { get { return _isNew; } set { _isNew = value; } } public object Clone() { return this.MemberwiseClone(); } public void makeANote(OddsMakerConfiguration original) //save settings for Cancels { isNew = false; _default = original; _long = _default._request.SuccessDirectionUp; _exitTimeCloseDays = _default.trackBarDailyExitDays.Value; _exitTimeOpenDays = _default.trackBarDailyExitDays.Value; // store _exitTimeMinutesBefore as a positive integer _exitTimeMinutesBefore = -_default.trackBarTimeStop.Value; _exitTimeMinutesAfter = _default.trackBarTimeAfterEntry.Value; _entryHoursStart = 0; _entryMinutesStart = _default.trackBarStartTime.Value; _entryHoursEnd = 0; // store EntryMinuteEnd as a positive integer _entryMinutesEnd = -_default.trackBarEndTime.Value; _daysOfTest = _default.trackBarTestDays.Value; double exitCondPercent = 0; if ("" != _default.txtExitCondPercent.Text && double.TryParse(_default.txtExitCondPercent.Text, out exitCondPercent)) _exitCondPercent = exitCondPercent; double exitCondBars = 0; if ("" != _default.txtExitCondBars.Text && double.TryParse(_default.txtExitCondBars.Text, out exitCondBars)) _exitCondBars = exitCondBars; double profitTarget = 0; if ("" != _default.txtProfitTarget.Text && double.TryParse(_default.txtProfitTarget.Text, out profitTarget)) _profitTarget = profitTarget; double stopLoss = 0; if ("" != _default.txtStopLoss.Text && double.TryParse(_default.txtStopLoss.Text, out stopLoss)) _stopLoss = stopLoss; _byAtLeastDollars = 0.01; _byAtLeastPerCent = 0.01; _rdoByAtLeastDollar = _default.rdoByAtLeastDollar.Checked; _rdoExitCondNone = _default.rdoExitCondNone.Checked; _rdoExitTimeMinutesAfter = _default.rdoExitTimeMinutesAfter.Checked; _rdoExitTAtTheClose = _default.rdoExitTAtTheClose.Checked; _rdoExitTimeFutureClose = _default.rdoExitTimeFutureClose.Checked; _rdoExitTimeAtTheOpen = _default.rdoExitTimeAtTheOpen.Checked; _rdoByAtLeastPerCent = _default.rdoByAtLeastPerCent.Checked; _rdoExitCondPercent = _default.rdoExitCondPercent.Checked; _rdoExitCondBars = _default.rdoExitCondBars.Checked; _rdoExitCondAnotherAlert = _default.rdoExitCondAnotherAlert.Checked; _chkProfitTarget = _default.chkProfitTarget.Checked; _chkStopLoss = _default.chkStopLoss.Checked; _chkWiggle = _default.chkWiggle.Checked; _cboLocation = _default.cboLocation.SelectedIndex; _exitCondition = _default._exitCondition; if (_default.comboBoxStopFilter.SelectedValue != null) { _useStopFilter = true; Filter filter = _default.comboBoxStopFilter.SelectedValue as Filter; if (null != filter) _stopFilter = filter.InternalCode; } else _useStopFilter = false; if (_default.comboBoxTargetFilter.SelectedValue != null) { _useTargetFilter = true; Filter filter = _default.comboBoxTargetFilter.SelectedValue as Filter; if (null != filter) _targetFilter = filter.InternalCode; } else _useTargetFilter = false; } public void Save(XmlNode description) //save to xml file (Layouts) { XmlNode om = description.NewNode("ODDSMAKER"); om.SetProperty("LONG", this.Long); om.SetProperty("DAYS_OF_TEST", _daysOfTest); om.SetProperty("DAYS_TO_SKIP", _daysToSkip); om.SetProperty("EXIT_TIME_CLOSE_DAYS", _exitTimeCloseDays); om.SetProperty("EXIT_TIME_OPEN_DAYS", _exitTimeOpenDays); om.SetProperty("EXIT_TIME_MINUTES_BEFORE", _exitTimeMinutesBefore); om.SetProperty("EXIT_TIME_MINUTES_AFTER", _exitTimeMinutesAfter); om.SetProperty("TXT_ENTRY_HOURS_START", EntryHoursStart); om.SetProperty("TXT_ENTRY_MINUTES_START", EntryMinutesStart); om.SetProperty("TXT_ENTRY_HOURS_END", EntryHoursEnd); om.SetProperty("TXT_ENTRY_MINUTES_END", EntryMinutesEnd); om.SetProperty("TXT_EXIT_COND_PERCENT", ExitCondPercent); om.SetProperty("TXT_EXIT_COND_BARS", ExitCondBars); om.SetProperty("TXT_PROFIT_TARGET", _profitTarget); om.SetProperty("TXT_STOP_LOSS", _stopLoss); om.SetProperty("TXT_BY_AT_LEAST_DOLLARS", _byAtLeastDollars); om.SetProperty("TXT_BY_AT_LEAST_PERCENT", _byAtLeastPerCent); om.SetProperty("EXIT_CONDITION", _exitCondition); om.SetProperty("RDO_EXIT_AT_THE_CLOSE", this.UseExitAtTimeOfDay); om.SetProperty("RDO_EXIT_TIME_FUTURE_CLOSE", this.UseExitTimeFutureClose); om.SetProperty("RDO_EXIT_TIME_AT_THE_OPEN", this.UseExitTimeFutureOpen); om.SetProperty("RDO_BY_AT_LEAST_DOLLAR", this.UseDollars); om.SetProperty("RDO_BY_AT_LEAST_PERCENT", this.UsePercent); om.SetProperty("RDO_EXIT_COND_NONE", this.UseNoAdvancedExit); om.SetProperty("RDO_EXIT_COND_PERCENT", this.UseExitCondPercent); om.SetProperty("RDO_EXIT_COND_BARS", this.UseExitCondBars); om.SetProperty("RDO_EXIT_TIME_MINUTES_AFTER", this.UseExitTimeMinutesAfter); om.SetProperty("RDO_EXIT_COND_ANOTHER_ALERT", this.UseExitCondAnotherAlert); om.SetProperty("CHK_PROFIT_TARGET", this.UseProfitTarget); om.SetProperty("USE_PROFIT_TARGET_FILTER", UseTargetFilter); om.SetProperty("PROFIT_TARGET_FILTER", TargetFilter); om.SetProperty("CHK_STOP_LOSS", this.UseStopLoss); om.SetProperty("USE_STOP_LOSS_FILTER", UseStopFilter); om.SetProperty("STOP_LOSS_FILTER", StopFilter); om.SetProperty("CHK_WIGGLE", this.UseWiggle); om.SetProperty("CBO_LOCATION", this.cboLocation); //The COLUMN_CONFIG is specifically for the web version. That is, when we create a cloud link here, //and load it to the TIPro Web... if(GuiEnvironment.OddsMakerColumnConfigType == OddsMakerColumnConfiguration.Favorites) om.SetProperty("COLUMN_CONFIG","Favorites"); else om.SetProperty("COLUMN_CONFIG", "Strategy"); om.SetProperty("IS_NEW", this.isNew); } public void Load(XmlNode source) //load from XML (Layouts) { //"magic numbers" correspond to the default values of the //config form. If someone alters the xml file, it will be those //numbers that the form will default to... XmlNode om = source.Node("ODDSMAKER"); Long = om.Property("LONG", true); _daysOfTest = om.Property("DAYS_OF_TEST", 30); _daysToSkip = om.Property("DAYS_TO_SKIP", 0); _exitTimeCloseDays = om.Property("EXIT_TIME_CLOSE_DAYS", 1); _exitTimeOpenDays = om.Property("EXIT_TIME_OPEN_DAYS", 1); _exitTimeMinutesBefore = om.Property("EXIT_TIME_MINUTES_BEFORE", 0); _exitTimeMinutesAfter = om.Property("EXIT_TIME_MINUTES_AFTER", 60); EntryHoursStart = om.Property("TXT_ENTRY_HOURS_START", 0); EntryMinutesStart = om.Property("TXT_ENTRY_MINUTES_START", 30); EntryHoursEnd = om.Property("TXT_ENTRY_HOURS_END", 60); EntryMinutesEnd = om.Property("TXT_ENTRY_MINUTES_END", 0); _exitCondPercent = om.Property("TXT_EXIT_COND_PERCENT", 0.5); _exitCondBars = om.Property("TXT_EXIT_COND_BARS", 0.5); _profitTarget = om.Property("TXT_PROFIT_TARGET", 1.0); _stopLoss = om.Property("TXT_STOP_LOSS", 1.0); _byAtLeastDollars = om.Property("TXT_BY_AT_LEAST_DOLLARS", 0.01); _byAtLeastPerCent = om.Property("TXT_BY_AT_LEAST_PERCENT", 0.1); _exitCondition = om.Property("EXIT_CONDITION", ""); UseExitAtTimeOfDay = om.Property("RDO_EXIT_AT_THE_CLOSE",false); UseExitTimeFutureClose = om.Property("RDO_EXIT_TIME_FUTURE_CLOSE",false); UseExitTimeFutureOpen = om.Property("RDO_EXIT_TIME_AT_THE_OPEN",false); UseDollars = om.Property("RDO_BY_AT_LEAST_DOLLAR",true); UsePercent = om.Property("RDO_BY_AT_LEAST_PERCENT",false); UseNoAdvancedExit = om.Property("RDO_EXIT_COND_NONE",true); UseExitCondPercent = om.Property("RDO_EXIT_COND_PERCENT",false); UseExitCondBars = om.Property("RDO_EXIT_COND_BARS",false); UseExitTimeMinutesAfter = om.Property("RDO_EXIT_TIME_MINUTES_AFTER",true); UseExitCondAnotherAlert = om.Property("RDO_EXIT_COND_ANOTHER_ALERT",false); UseProfitTarget = om.Property("CHK_PROFIT_TARGET",false); TargetFilter = om.Property("PROFIT_TARGET_FILTER", "SmartStopD"); UseTargetFilter = om.Property("USE_PROFIT_TARGET_FILTER", false); UseStopLoss = om.Property("CHK_STOP_LOSS",false); StopFilter = om.Property("STOP_LOSS_FILTER", "SmartStopD"); UseStopFilter = om.Property("USE_STOP_LOSS_FILTER", false); UseWiggle = om.Property("CHK_WIGGLE",false); cboLocation = om.Property("CBO_LOCATION",0); string colConfig = om.Property("COLUMN_CONFIG", ""); if (colConfig != "") { if (colConfig == "Favorites") GuiEnvironment.OddsMakerColumnConfigType = OddsMakerColumnConfiguration.Favorites; else GuiEnvironment.OddsMakerColumnConfigType = OddsMakerColumnConfiguration.Strategy; } isNew = om.Property("IS_NEW",false); } } private void btnSimulateSell_Click(object sender, EventArgs e) { GuiEnvironment.RecordUseCase("OddsMakerConfig.Button.SimulateSell", _sendManager); _request.SuccessDirectionUp = false; HighlightBuySell(); loadData(); } private void btnSimulateBuy_Click(object sender, EventArgs e) { GuiEnvironment.RecordUseCase("OddsMakerConfig.Button.SimulateBuy", _sendManager); _request.SuccessDirectionUp = true; HighlightBuySell(); loadData(); } private void loadData() { try { double number; _userOddsSetting.makeANote(this); _alertForm.SetOddsMakerSettings((OddsMakerConfiguration.OddsMakerConfigMemento)_userOddsSetting.Clone()); _request.DaysOfTest = trackBarTestDays.Value; _request.SkipDays = 0; _request.ColumnConfig = _columnConfigType; _request.EntryCondition = _alertConfig; _request.EntryTimeEnd = -trackBarEndTime.Value; _request.EntryTimeStart = trackBarStartTime.Value; switch (cboLocation.SelectedIndex) { case 1: _request.Location = SelectedLocation.Canada; break; case 0: default: _request.Location = SelectedLocation.US; break; } if (chkProfitTarget.Checked) { Filter selectedTargetFilter = comboBoxTargetFilter.SelectedItem as Filter; if (null != selectedTargetFilter && checkBoxUseTargetFilter.Checked) { _request.TargetFilter = selectedTargetFilter.InternalCode; _request.UseTargetFilter = true; } else { if (Double.TryParse(txtProfitTarget.Text, out number)) _request.ProfitTarget = number; else _request.ProfitTarget = 1; // Set to default } } else { _request.ProfitTarget = null; } if (chkStopLoss.Checked) { Filter selectedStopFilter = comboBoxStopFilter.SelectedItem as Filter; if (null != selectedStopFilter && checkBoxUseStopFilter.Checked) { _request.StopFilter = selectedStopFilter.InternalCode; _request.UseStopFilter = true; } else { if (Double.TryParse(txtStopLoss.Text, out number)) _request.StopLoss = number; else _request.StopLoss = 1; // Set to default } } else _request.StopLoss = null; _request.StopLossWiggle = chkWiggle.Checked; if (rdoByAtLeastPerCent.Checked) { _request.SuccessTypePercent = true; _request.SuccessMinMove = 0.01; } else { _request.SuccessMinMove = 0.01; } if (rdoExitTimeMinutesAfter.Checked) { _request.TimeoutType = TimeoutType.MinutesAfterEntry; _request.TimeoutMinutes = trackBarTimeAfterEntry.Value; } else if (rdoExitTAtTheClose.Checked) { _request.TimeoutType = TimeoutType.Close; _request.BeforeCloseMinutes = -trackBarTimeStop.Value; } else if (rdoExitTimeAtTheOpen.Checked) { _request.TimeoutType = TimeoutType.Open; _request.AtOpenDays = trackBarDailyExitDays.Value; } else if (rdoExitTimeFutureClose.Checked) { _request.TimeoutType = TimeoutType.FutureClose; _request.AtCloseDays = trackBarDailyExitDays.Value; } else { _request.TimeoutType = TimeoutType.MinutesAfterEntry; _request.TimeoutMinutes = trackBarTimeAfterEntry.Value; } _request.XmlMode = true; _request.ExitConditionAlert = _exitCondition; if (rdoExitCondPercent.Checked) { if (Double.TryParse(txtExitCondPercent.Text, out number)) _request.ExitConditionTrailingStop = number; else _request.ExitConditionTrailingStop = 0.5; // Set to default _request.ExitConditionType = ExitConditionType.TrailingPercent; } else if (rdoExitCondBars.Checked) { if (Double.TryParse(txtExitCondBars.Text, out number)) _request.ExitConditionTrailingStop = number; else _request.ExitConditionTrailingStop = 0.5; // Set to default _request.ExitConditionType = ExitConditionType.TrailingBars; } else if (rdoExitCondAnotherAlert.Checked) { _request.ExitConditionAlert = _exitCondition; _request.ExitConditionType = ExitConditionType.Alert; } else { _request.ExitConditionType = ExitConditionType.None; } _request.RequestCsvFile = true; //_result = new OddsMakerResults(_request, _connectionMaster, this, _windowName, _userOddsSetting); _result = new OddsMakerResults(_request, _connectionMaster, null, _windowName, _userOddsSetting); if (GuiEnvironment.openRelativeToMainWindow) { _result.Location = new Point(GuiEnvironment.currentMainWindowLeft, GuiEnvironment.currentMainWindowTop); Screen CurrentScreen = Screen.FromControl(this); Rectangle workingRectangle = CurrentScreen.WorkingArea; if (!workingRectangle.Contains(_result.DesktopBounds)) _result.Location = new Point(CurrentScreen.Bounds.X + 50, CurrentScreen.Bounds.Y + 50); // set position relative to current monitor } this.Hide(); } catch (System.FormatException) { MessageBox.Show ( "Data Invalid or Missing! Please fill in blank box/boxes with valid entries.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1 ); return; } } private void rdoByAtLeastDollar_CheckedChanged(object sender, EventArgs e) { if (rdoByAtLeastDollar.Checked == false) { GuiEnvironment.RecordUseCase("OddsMakerConfig.Radio.ByAtLeastPerCent", _sendManager); lblProfitTargetDollar.Visible = false; lblProfitTargetPercent.Visible = true; lblStopLossDollar.Visible = false; lblStopLossPercent.Visible = true; } else { GuiEnvironment.RecordUseCase("OddsMakerConfig.Radio.ByAtLeastDollar", _sendManager); lblProfitTargetDollar.Visible = true; lblProfitTargetPercent.Visible = false; lblStopLossDollar.Visible = true; lblStopLossPercent.Visible = false; } } private void cancelButton_Click(object sender, EventArgs e) { GuiEnvironment.RecordUseCase("OddsMakerConfig.Button.Cancel", _sendManager); this.restoreDefault(_userOddsSetting); this.Hide(); } public void setUserOddsSettings(OddsMakerConfiguration.OddsMakerConfigMemento settings) { _userOddsSetting = settings; } private void OddsMakerConfiguration_VisibleChanged(object sender, EventArgs e) { if (!Visible) { _alertForm.oddsLocation_X = Location.X; _alertForm.oddsLocation_Y = Location.Y; } if (Visible) { // The culture or date might have changed since the last time we were displayed. PopulateStrings(); if (this.Height > Screen.PrimaryScreen.Bounds.Height) { // Retrieve the working rectangle from the Screen class // using the PrimaryScreen and the WorkingArea properties. Rectangle workingRectangle = Screen.PrimaryScreen.WorkingArea; // Set the size of the form slightly less than size of // working rectangle. this.Size = new Size( workingRectangle.Width, workingRectangle.Height - 10); // Set the location so the entire form is visible. this.Location = new Point(5, 5); } } } private void OddsMakerConfiguration_FormClosing(object sender, FormClosingEventArgs e) { if (e.CloseReason == CloseReason.UserClosing) { // This window should be reusable, like a dialog box. e.Cancel = true; Hide(); } } private void btnExitCondConfigure_Click(object sender, EventArgs e) { GuiEnvironment.RecordUseCase("OddsMakerConfig.Button.Configure", _sendManager); ConfigWindowWrapper configWindowWrapper = ConfigWindowWrapper.DefaultFactory(ConfigurationType.Alerts, _connectionMaster); configWindowWrapper.InitialConfig = _exitCondition; configWindowWrapper.HideColumns = true; configWindowWrapper.UseCaseName = "Odds"; configWindowWrapper.NotAWindow = true; configWindowWrapper.ShowIt(); if (!configWindowWrapper.Canceled) { _exitCondition = configWindowWrapper.Strategy.MakeConfigString(); _request.ExitConditionType = ExitConditionType.Alert; rdoExitCondAnotherAlert.Enabled = true; rdoExitCondAnotherAlert.Checked = true; } } private void OddsMakerConfiguration_Layout(object sender, LayoutEventArgs e) { //fix some layout issues here //btnExitCondConfigure.Left = rdoExitCondAnotherAlert.Right + 3; //txtExitTimeOpenDays.Left = txtExitTimeCloseDays.Left = rdoExitTimeAtTheOpen.Right + 3; } private void HideShowDailyExitConfig() { if (rdoExitTimeAtTheOpen.Checked || rdoExitTimeFutureClose.Checked) { trackBarDailyExitDays.Enabled = true; labelDaysLater.Enabled = true; labelDailyExitDaysValue.Enabled = true; labelDaysLaterMin.Enabled = true; labelDaysLaterMax.Enabled = true; } else { trackBarDailyExitDays.Enabled = false; labelDaysLater.Enabled = false; labelDailyExitDaysValue.Enabled = false; labelDaysLaterMin.Enabled = false; labelDaysLaterMax.Enabled = false; } } private void HideShowExitTODSection() { if (rdoExitTAtTheClose.Checked) { trackBarTimeStop.Enabled = true; labelTimeStopValue.Enabled = true; labelTimeStopMax.Enabled = true; labelTimeStopMin.Enabled = true; } else { trackBarTimeStop.Enabled = false; labelTimeStopValue.Enabled = false; labelTimeStopMax.Enabled = false; labelTimeStopMin.Enabled = false; } } private void HideShowMinutesAfterEntrySection() { if (rdoExitTimeMinutesAfter.Checked) { labelTimeAfterEntryMax.Enabled = true; labelTimeAfterEntryMin.Enabled = true; labelTimeAfterEntryValue.Enabled = true; trackBarTimeAfterEntry.Enabled = true; } else { labelTimeAfterEntryMax.Enabled = false; labelTimeAfterEntryMin.Enabled = false; labelTimeAfterEntryValue.Enabled = false; trackBarTimeAfterEntry.Enabled = false; } } // this enables/disables controls within the Exit Config section to reflect what is currently selected private void UpdateExitConfigStatus() { HideShowDailyExitConfig(); HideShowExitTODSection(); HideShowMinutesAfterEntrySection(); SetDailyExitDays(); } private void rdoExitTimeAtTheOpen_CheckedChanged(object sender, EventArgs e) { if (rdoExitTimeAtTheOpen.Checked) { GuiEnvironment.RecordUseCase("OddsMakerConfig.Radio.ExitTimeAtTheOpen", _sendManager); } UpdateExitConfigStatus(); } private void rdoExitTimeFutureClose_CheckedChanged(object sender, EventArgs e) { if (rdoExitTimeFutureClose.Checked) { GuiEnvironment.RecordUseCase("OddsMakerConfig.Radio.ExitTimeFutureClose", _sendManager); } UpdateExitConfigStatus(); } private void rdoExitTimeMinutesAfter_CheckedChanged(object sender, EventArgs e) { if (rdoExitTimeMinutesAfter.Checked) { GuiEnvironment.RecordUseCase("OddsMakerConfig.Radio.ExitTimeMinutesAfter", _sendManager); } UpdateExitConfigStatus(); } private void rdoExitTAtTheClose_CheckedChanged(object sender, EventArgs e) { if (rdoExitTAtTheClose.Checked) { GuiEnvironment.RecordUseCase("OddsMakerConfig.Radio.ExitTAtTheClose", _sendManager); } UpdateExitConfigStatus(); } private void buttonShowAdvanced_Click(object sender, EventArgs e) { if (panelAdvanced.Visible) { GuiEnvironment.RecordUseCase("OddsMakerConfig.Button.HideAdvanced", _sendManager); ToggleAdvancedSection(true); } else { GuiEnvironment.RecordUseCase("OddsMakerConfig.Button.ShowAdvanced", _sendManager); ToggleAdvancedSection(false); } } private void ToggleAdvancedSection(bool hide) { panelEntire.Anchor = AnchorStyles.Top | AnchorStyles.Left; if (hide) { panelAdvanced.Visible = false; buttonShowAdvanced.Text = _oddsMakerConfig.Node("SHOW_ADVANCED_LABEL").PropertyForCulture("TEXT", "***"); Size panelSize = panelExitConfig.Size; panelSize.Height = panelRiskManagement.Bottom + 10; panelExitConfig.Size = panelSize; } else { panelAdvanced.Visible = true; buttonShowAdvanced.Text = _oddsMakerConfig.Node("HIDE_ADVANCED_LABEL").PropertyForCulture("TEXT", "***"); Size panelSize = panelExitConfig.Size; panelSize.Height = panelAdvanced.Bottom + 10; panelExitConfig.Size = panelSize; } int preferredPanelHeight = panelEntrySection.Size.Height + 10 + panelExitConfig.Size.Height + 20; panelEntire.Size = new Size(panelEntire.Width, preferredPanelHeight); panelEntire.AutoScrollMinSize = new Size(panelEntire.Size.Width, panelEntire.Size.Height); int preferredHeight = panelEntire.Size.Height + panelButtons.Height + 50; Screen screen = Screen.FromControl(this); int edgeOfScreen = screen.WorkingArea.Bottom; if (preferredHeight > edgeOfScreen) { Location = new Point(Location.X, 1); preferredPanelHeight = edgeOfScreen - panelButtons.Height - 40; preferredHeight = edgeOfScreen; // adjust size of panelEntire now panelEntire.Size = new Size(panelEntire.Width, preferredHeight - panelButtons.Height -50); } else { preferredHeight = panelEntire.Size.Height + panelButtons.Height + 70; } Height = preferredHeight; Point buttonPanelPoint = panelButtons.Location; buttonPanelPoint.Y = panelEntire.Bottom + 10; panelButtons.Location = buttonPanelPoint; panelEntire.Anchor = AnchorStyles.Top | AnchorStyles.Left; if (panelEntire.VerticalScroll.Visible) { panelEntire.VerticalScroll.Value = 0; } } private void trackBarStartTime_Validating(object sender, CancelEventArgs e) { } private void buttonShowHelp_Click(object sender, EventArgs e) { GuiEnvironment.RecordUseCase("OddsMakerConfig.Button.Help", _sendManager); ShowHelpScreen(); } /*The below event handlers are for tracking while the user uses the "sliders". The scroll event is fired too often and becomes unweildy-as evidenced by the log. The MousDown event appears to be a more suitable choice*/ private void trackBarStartTime_MouseDown(object sender, MouseEventArgs e) { GuiEnvironment.RecordUseCase("OddsMakerConfig.TrackBar.StartTime", _sendManager); } private void trackBarEndTime_MouseDown(object sender, MouseEventArgs e) { GuiEnvironment.RecordUseCase("OddsMakerConfig.TrackBar.EndTime", _sendManager); } private void trackBarTimeAfterEntry_MouseDown(object sender, MouseEventArgs e) { GuiEnvironment.RecordUseCase("OddsMakerConfig.TrackBar.TimeAfterEntry", _sendManager); } private void trackBarTimeStop_MouseDown(object sender, MouseEventArgs e) { GuiEnvironment.RecordUseCase("OddsMakerConfig.TrackBar.TimeStop", _sendManager); } private void trackBarDailyExitDays_MouseDown(object sender, MouseEventArgs e) { GuiEnvironment.RecordUseCase("OddsMakerConfig.TrackBar.DailyExitDays", _sendManager); } private void trackBarTestDays_MouseDown(object sender, MouseEventArgs e) { GuiEnvironment.RecordUseCase("OddsMakerConfig.TrackBar.TestDays", _sendManager); } private void rdoExitCondNone_CheckedChanged(object sender, EventArgs e) { if (rdoExitCondNone.Checked) { GuiEnvironment.RecordUseCase("OddsMakerConfig.Radio.ExitCondNone", _sendManager); } } private void rdoExitCondPercent_CheckedChanged(object sender, EventArgs e) { if (rdoExitCondPercent.Checked) { GuiEnvironment.RecordUseCase("OddsMakerConfig.Radio.ExitCondPercent", _sendManager); } } private void rdoExitCondBars_CheckedChanged(object sender, EventArgs e) { if (rdoExitCondBars.Checked) { GuiEnvironment.RecordUseCase("OddsMakerConfig.Radio.ExitCondBars", _sendManager); } } private void rdoExitCondAnotherAlert_CheckedChanged(object sender, EventArgs e) { if (rdoExitCondAnotherAlert.Checked) { GuiEnvironment.RecordUseCase("OddsMakerConfig.Radio.ExitCondAnotherAlert", _sendManager); } } private void cboLocation_SelectionChangeCommitted(object sender, EventArgs e) { GuiEnvironment.RecordUseCase("OddsMakerConfig.ComboBox.Location", _sendManager); } private void chkProfitTarget_CheckedChanged(object sender, EventArgs e) { GuiEnvironment.RecordUseCase("OddsMakerConfig.CheckBox.ProfitTarget", _sendManager); FixStopAndTargetGuiState(); } private void chkStopLoss_CheckedChanged(object sender, EventArgs e) { GuiEnvironment.RecordUseCase("OddsMakerConfig.CheckBox.StopLoss", _sendManager); FixStopAndTargetGuiState(); } private void chkWiggle_CheckedChanged(object sender, EventArgs e) { GuiEnvironment.RecordUseCase("OddsMakerConfig.CheckBox.Wiggle", _sendManager); } private void UpdateColumnConfigStatus() { radioColumnsStrategy.Checked = _columnConfigType == OddsMakerColumnConfiguration.Strategy; radioColumnsFavorites.Checked = _columnConfigType == OddsMakerColumnConfiguration.Favorites; buttonViewFavoriteColumns.Enabled = _columnConfigType == OddsMakerColumnConfiguration.Favorites; GuiEnvironment.OddsMakerColumnConfigType = _columnConfigType; } private void buttonViewFavoriteColumns_Click(object sender, EventArgs e) { string initialString = "O=8000000000000000000000000_41D_0&WN=My+Alerts" + GetColumnConfig(GuiEnvironment.OddsMakerFavoriteFilters); ConfigWindowWrapper configWindowWrapper = ConfigWindowWrapper.DefaultFactory(ConfigurationType.Alerts, _connectionMaster); configWindowWrapper.InitialConfig = initialString; configWindowWrapper.OnlyShowColumns = true; configWindowWrapper.UsingOddsMaker = true; configWindowWrapper.UseCaseName = "OddsColumns"; configWindowWrapper.ShowIt(); if (!configWindowWrapper.Canceled) { GuiEnvironment.OddsMakerFavoriteFilters = configWindowWrapper.Strategy.Columns.Select(x => x.InternalCode).ToList(); } } private string GetColumnConfig(List columns) { int index = 0; StringBuilder config = new StringBuilder(); foreach (string internalCode in columns) { config.Append("&show"); config.Append(index); index++; config.Append("="); config.Append(internalCode); } config.Append("&show"); config.Append(index); index++; config.Append('='); return config.ToString(); } private void radioColumnsStrategy_CheckedChanged(object sender, EventArgs e) { if (_columnConfigType != OddsMakerColumnConfiguration.Strategy) { _columnConfigType = OddsMakerColumnConfiguration.Strategy; UpdateColumnConfigStatus(); } } private void radioColumnsFavorites_CheckedChanged(object sender, EventArgs e) { if (_columnConfigType != OddsMakerColumnConfiguration.Favorites) { _columnConfigType = OddsMakerColumnConfiguration.Favorites; UpdateColumnConfigStatus(); } } private void comboBoxTargetFilter_SelectedIndexChanged(object sender, EventArgs e) { FixStopAndTargetGuiState(); } private void comboBoxStopFilter_SelectedIndexChanged(object sender, EventArgs e) { FixStopAndTargetGuiState(); } private void checkBoxUseStopFilter_CheckedChanged(object sender, EventArgs e) { FixStopAndTargetGuiState(); } private void checkBoxUseTargetFilter_CheckedChanged(object sender, EventArgs e) { FixStopAndTargetGuiState(); } } }