Beispiel #1
0
        private void Peacemaker()
        {
            if (!IsFeed || !Manager.IsLoadedRate)
            {
                return;
            }


            string pair = this.Pair;

            ServiceConfiguration.TimeFrame frame = this.Frame;
            int    span       = this.Span;
            double confidence = this.Confidecne;
            int    tests      = TTbxBacktests.GetInt(this);

            Rate[] Rates = Manager.ForexArchive.Data.GetValuesArray <ServiceConfiguration.TimeFrame, DateTime, Rate>(pair, frame); //Manager.ForexArchive.Data[pair][ServiceConfiguration.TimeFrame.DAILY].ValuesArray;// //


            // TTbxMax.dec


            if (Objects.IsNullOrEmpty(Rates) || !ServiceConfiguration.IsSpan(frame))
            {
                return;
            }



            Manager.ForexAnalysis.MonteCarlo(pair, frame, span, tests);


            double[][] MonteCarloData = Manager.ForexAnalysis.GetMonteCarlo(pair, frame, span, -1);
            if (Objects.IsNullOrEmpty(MonteCarloData))
            {
                Chart.Main.ClearSeries(this);
                return;
            }

            double[]   data  = Objects.ToArray <double>(RateInfo.Extract(Rates, RateInfo.Properties.CLOSE));
            DateTime[] dates = Objects.ToArray <DateTime>(RateInfo.Extract(Rates, RateInfo.Properties.DateTime));


            double Min  = 0;
            double Avg  = 0;
            double Max  = 0;
            double Test = 0;

            Manager.ForexAnalysis.GetStatistics(pair, frame, span, confidence, ref Max, ref Avg, ref Min, ref Test);

            this.SetOutputStatistic(pair, Max, Avg, Min);
            TTbxBacktestConfidence.SetValue(this, Test);
            TTbxBacktestSamples.SetValue(this, Manager.ForexAnalysis.MonteCarloBacktestSamples);

            double[] next = MonteCarloData.Last();// MonteCarloSimulation.Next(data, 50).ToArray();
            if (next == null)
            {
                return;
            }

            TTbxTestSamples.SetValue(this, MonteCarloData.Length);

            List <double> combine = new List <double>();

            combine.AddRange(data);
            combine.AddRange(next);

            if (Chart.Main.Series.Count <= 0 || Chart.Main.Series[0].Name != pair || Chart.Main.ID != frame + pair + span + tests)
            {
                Chart.Main.ID = frame + pair + span + tests;
                Chart.Main.ClearSeries(this);
                Chart.Main.Add(pair, SeriesChartType.Line, this);
                DataPoint[] points = ChartPointInfo.ToDataPoints(data, dates, ServiceConfiguration.Span(frame));
                Chart.Main.AddRange(this, pair, points, ChartValueType.DateTime, ChartValueType.Double);
            }
            else
            {
                DataPoint[] points = ChartPointInfo.ToDataPoints(next, dates.Last(), ServiceConfiguration.Span(frame));
                Chart.Main.UpdateRange(this, pair, points, ChartValueType.DateTime, ChartValueType.Double);
            }
        }