using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using TradeIdeas.TIProData; using System.Windows.Forms; using TradeIdeas.XML; using System.Xml; // General info about moving averages: http://www.silverbearcafe.com/private/moveaverage.html // In particular: // "For a period-based EMA, "Multiplier" is equal to 2 / (1 + N) where N is the specified number of periods." namespace TradeIdeas.TIProGUI.CompareCount { public partial class CompareCountConfig : Form { private ConnectionMaster _connectionMaster; private Settings _settings; //Start location of this when first brought up... private static int _configLocation_X = 50; private static int _configLocation_Y = 50; public CompareCountConfig(ConnectionMaster connectionMaster,Settings settings) { _connectionMaster = connectionMaster; _settings = settings; InitializeComponent(); CompareCount.WindowIconCache.SetIcon(this); trackBar1.Value = _settings.SecondsPerDataPoint; updateSpeedLabel(); trackBarThickEMA.Value = (int)(_settings.FastRecentWeight * 100); updateThickEMALabel(); trackBarThinEMA.Value = (int)(_settings.SlowRecentWeight * 100); updateThinEMALabel(); Font = GuiEnvironment.FontSettings; } private void btnConfigGreen_Click(object sender, EventArgs e) { ConfigWindow form = new ConfigWindow(TIProData.Configuration.ConfigurationType.Alerts, _connectionMaster, _settings.BullConfigString); form.isCompareCountInUse = true; form.ShowDialog(); if (form.DialogResult == System.Windows.Forms.DialogResult.OK) { _settings.BullConfigString = form.AlertStrategy.MakeConfigString(); btnOK.Enabled = true; } form.Dispose(); } private void btnConfigRed_Click(object sender, EventArgs e) { ConfigWindow form = new ConfigWindow(TIProData.Configuration.ConfigurationType.Alerts, _connectionMaster, _settings.BearConfigString); form.isCompareCountInUse = true; form.ShowDialog(); if (form.DialogResult == System.Windows.Forms.DialogResult.OK) { _settings.BearConfigString = form.AlertStrategy.MakeConfigString(); btnOK.Enabled = true; } form.Dispose(); } private void btnOK_Click(object sender, EventArgs e) { this.DialogResult = DialogResult.OK; } private void btnCancel_Click(object sender, EventArgs e) { this.DialogResult = DialogResult.Cancel; } private void btnGreenCollaborate(object sender, EventArgs e) { CollaborateForm form = new CollaborateForm(); form.ConfigString = GuiEnvironment.XmlConfig.Node("ALERT_WINDOW").Node("CONFIG_PREFIX").PropertyForCulture("BASE", "***") + _settings.BullConfigString; form.ShowDialog(this); if (form.DialogResult == System.Windows.Forms.DialogResult.OK) { if (form.ConfigString != "") { _settings.BullConfigString = form.ConfigString; } btnOK.Enabled = true; } form.Dispose(); } private void btnRedCollaborate_Click(object sender, EventArgs e) { CollaborateForm form = new CollaborateForm(); form.ConfigString = GuiEnvironment.XmlConfig.Node("ALERT_WINDOW").Node("CONFIG_PREFIX").PropertyForCulture("BASE", "***") + _settings.BearConfigString; form.ShowDialog(this); if (form.DialogResult == System.Windows.Forms.DialogResult.OK) { if (form.ConfigString != "") { _settings.BearConfigString = form.ConfigString; } btnOK.Enabled = true; } form.Dispose(); } private void trackBar1_Scroll(object sender, EventArgs e) { btnOK.Enabled = true; updateSpeedLabel(); } private void updateSpeedLabel() { int seconds = trackBar1.Value; label3.Text = "One data point every " + seconds.ToString() + " seconds."; _settings.SecondsPerDataPoint = seconds; } private void trackBarThickEMA_Scroll(object sender, EventArgs e) { btnOK.Enabled = true; updateThickEMALabel(); } private void updateThickEMALabel() { int percent = trackBarThickEMA.Value; double fraction = percent / 100.0; label4.Text = getPeriod(fraction) + " periods, " + percent.ToString() + "%"; _settings.FastRecentWeight = fraction; } private void trackBarThinEMA_Scroll(object sender, EventArgs e) { btnOK.Enabled = true; updateThinEMALabel(); } private void updateThinEMALabel() { int percent = trackBarThinEMA.Value; double fraction = percent / 100.0; label7.Text = getPeriod(fraction) + " periods, " + percent.ToString() + "%"; _settings.SlowRecentWeight = fraction; } private double getPeriod(double fraction) { return Math.Round((2 - fraction) / fraction); } private void CompareCountConfig_VisibleChanged(object sender, EventArgs e) { //retain location when this window is created again... if (!this.Visible) { _configLocation_X = Location.X; _configLocation_Y = Location.Y; } else { Location = new Point(_configLocation_X, _configLocation_Y); } } } }