Exemplo n.º 1
0
        private int SetOptimize(IAsset asset, AutomaticallySetting auto, int repeat)
        {
            try
            {
                set = new StrategySetting
                {
                    ShortTick = auto.SetVariableAutomatic(IAsset.Variable.ShortTick, asset.ShortTickPeriod, ran.Next(1, 21)),
                    LongTick  = auto.SetVariableAutomatic(IAsset.Variable.LongTick, asset.LongTickPeriod, ran.Next(1, 16)),
                    ShortDay  = auto.SetVariableAutomatic(IAsset.Variable.ShortDay, asset.ShortDayPeriod, ran.Next(1, 11)),
                    LongDay   = auto.SetVariableAutomatic(IAsset.Variable.LongDay, asset.LongDayPeriod, ran.Next(1, 11)),
                    Reaction  = auto.SetVariableAutomatic(IAsset.Variable.Reaction, asset.Reaction, ran.Next(1, 51)),
                    Hedge     = auto.SetVariableAutomatic(IAsset.Variable.Hedge, asset.Hedge, ran.Next(0, 6)),
                    Base      = auto.SetVariableAutomatic(IAsset.Variable.Base, asset.Base, ran.Next(0, 3)),
                    Sigma     = auto.SetVariableAutomatic(IAsset.Variable.Sigma, asset.Sigma, ran.Next(0, 2)),
                    Percent   = auto.SetVariableAutomatic(IAsset.Variable.Percent, asset.Percent, ran.Next(0, 2)),
                    Max       = auto.SetVariableAutomatic(IAsset.Variable.Max, asset.Max, ran.Next(0, 2)),
                    Quantity  = auto.SetVariableAutomatic(IAsset.Variable.Quantity, asset.Quantity, ran.Next(0, 2)),
                    Time      = auto.SetVariableAutomatic(IAsset.Variable.Time, asset.Time, ran.Next(0, 6)),
                    Capital   = asset.Assets
                };
                Estimate = set.EstimatedTime(new List <string>(64), CalculateTheRemainingTime() * count, true);

                if (repeat % 2500 == 0 && TimerBox.Show("Run the Program Again and Set it Manually.", "Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2, 5157).Equals(DialogResult.OK))
                {
                    Application.ExitThread();
                    Application.Exit();
                }
                else if (repeat % 500 == 0 && TimerBox.Show("Do You Want to Use the Existing Settings?", "Question", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, 7519).Equals(DialogResult.OK))
                {
                    checkBox.Checked = true;
                    button.ForeColor = Color.Gold;
                    button.PerformClick();

                    return(int.MinValue);
                }
            }
            catch (Exception ex)
            {
                new LogMessage().Record("Exception", ex.ToString());

                if (TimerBox.Show("Run the Program Again and Set it Manually.", "Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2, 5157).Equals(DialogResult.OK))
                {
                    Application.ExitThread();
                    Application.Exit();
                }
            }
            return(Estimate.Count);
        }
Exemplo n.º 2
0
        private void TimerTick(object sender, EventArgs e)
        {
            timer.Stop();
            checkBox.Text = "Loading. . .";
            Application.DoEvents();
            BeginInvoke(new Action(() => options = new Options()));

            if (TimerBox.Show("Start Back Testing.\n\nClick 'No' to Do this Manually.\n\nIf Not Selected,\nIt will Automatically Proceed after 20 Seconds.", "Notice", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, 25617).Equals((DialogResult)7))
            {
                checkBox.Text = "Manual";

                return;
            }
            int setting, repeat = 0;

            ran           = new Random();
            checkBox.Font = new Font(checkBox.Font.Name, 8.25F, FontStyle.Regular);
            AutomaticallySetting auto = new AutomaticallySetting();

            do
            {
                setting       = SetOptimize(asset, auto, ++repeat);
                checkBox.Text = string.Concat("No.", repeat.ToString("N0"), " Co.", (setting / count).ToString("N0"));
                Application.DoEvents();
            }while (CalculateTheRemainingTime(setting));

            checkBox.Font = new Font(checkBox.Font.Name, checkBox.Font.Name.Equals("Consolas") ? 13.25F : 15.75F, FontStyle.Regular);
            checkBox.Text = "BackTesting";
            GC.Collect();

            if (setting > int.MinValue)
            {
                StartBackTesting(set);
            }

            timer.Dispose();
        }