コード例 #1
0
        public void ShowGraph(GraphWindow graphWindow)
        {
            //graphWindow.Show();



            Simulator1 S  = null;
            var        pl = 0.0;

            Task.Run(() =>
            {
                var settings = AppSettings.GetStrategySettings2("macd_small");

                S = new Simulator1(CurContextValues.ProductName,
                                   settings.time_interval,
                                   settings.slow_sma,
                                   settings.fast_sma,
                                   true);


                graphWindow.FillInitialVaues(DateTime.Now.AddDays(-17), DateTime.Now.AddHours(12),
                                             settings.time_interval, settings.slow_sma, settings.fast_sma, settings.signal);


                pl = S.Calculate(DateTime.Now.AddDays(-17),
                                 DateTime.Now.AddHours(12), settings.signal, true, true);

                S.Dispose();
            }).Wait();


            graphWindow.DrawSeriesSim1(S.CurResultsSeriesList, S.CurResultCrossList, pl);
            //Thread thread = new Thread(() =>
            //{



            //});
            //thread.SetApartmentState(ApartmentState.STA);
            //thread.Start();


            //thread.Join();
        }
コード例 #2
0
ファイル: GraphWindow.xaml.cs プロジェクト: sd37/Multiplier
        private void btnCalculate_Click(object sender, RoutedEventArgs e)
        {
            //System.Windows.c
            Cursor = Cursors.Wait;
            DateTime?tempStartTime = dtFrom.SelectedDate; //new DateTime(2018, 1, 1);
            DateTime?tempEndTime   = dtTo.SelectedDate;   //new DateTime(2018, 5, 1);

            DateTime startTime = (tempStartTime == null)? new DateTime(2018, 1, 1): tempStartTime.Value;
            DateTime endTime   = (tempStartTime == null) ? new DateTime(2018, 5, 1) : tempEndTime.Value;

            var ProductName = "LTC-USD";

            if (tempStartTime == null || tempEndTime == null)
            {
                Cursor = Cursors.Arrow;
                return;
            }



            if (txtInterval.Text == "" ||
                txtLargeSma.Text == "" ||
                txtSmallSma.Text == "" ||
                txtSignal.Text == "")
            {
                Cursor = Cursors.Arrow;
                return;
            }



            int interval    = 0; //Convert.ToInt16(txtInterval.Text);//30;
            int bigSmaLen   = 0; //Convert.ToInt16(txtLargeSma.Text); // 100;
            int smallSmaLen = 0; //Convert.ToInt16(txtSmallSma.Text); //50;
            int SignalLen   = 0; //Convert.ToInt16(txtSignal.Text); //10;

            try
            {
                interval    = Convert.ToInt16(txtInterval.Text); //30;
                bigSmaLen   = Convert.ToInt16(txtLargeSma.Text); // 100;
                smallSmaLen = Convert.ToInt16(txtSmallSma.Text); //50;
                SignalLen   = Convert.ToInt16(txtSignal.Text);   //10;
            }
            catch (Exception)
            {
                Cursor = Cursors.Arrow;
                MessageBox.Show("invalid input");
                return;
            }



            if (interval <= 0 ||
                bigSmaLen <= 0 ||
                smallSmaLen <= 0 ||
                SignalLen <= 0)
            {
                Cursor = Cursors.Arrow;
                return;
            }



            if (_Sim == null)
            {
                _Sim = new Simulator1(ProductName, interval, bigSmaLen, smallSmaLen);
            }
            else
            {
                //if (!(lastCommonInterval == interval && lastBigSma == bigSmaLen && lastSmallSma == smallSmaLen))
                //{
                //    _Sim.Dispose();
                //    _Sim = null;
                //    _Sim = new Simulator1(ProductName, interval, bigSmaLen, smallSmaLen);

                //}

                _Sim.Dispose();
                _Sim = null;
                _Sim = new Simulator1(ProductName, interval, bigSmaLen, smallSmaLen);
            }



            Task.Run(() =>
            {
                var pl = _Sim.Calculate(startTime, endTime, SignalLen, true, true, true);

                lastCommonInterval = interval;
                lastBigSma         = bigSmaLen;
                lastSmallSma       = smallSmaLen;


                DrawSeriesSim1(_Sim.CurResultsSeriesList, _Sim.CurResultCrossList, pl);
                Dispatcher.Invoke(() =>
                {
                    Cursor = Cursors.Arrow;// Mouse.OverrideCursor = Cursors.None;
                });
            });
        }