Beispiel #1
0
        private void Test01_a(long dateTime)
        {
            long ttSec = TTCommon.DateTimeToTTSec(dateTime);
            long ret   = TTCommon.TTSecToDateTime(ttSec);

            Console.WriteLine(dateTime + " -> " + ttSec + " -> ...");
            Console.WriteLine(ret);
        }
Beispiel #2
0
        private void ChartMoveMove(Chart chart, int x, int y)
        {
            try
            {
                double aX = chart.ChartAreas[0].AxisX.PixelPositionToValue(x);
                double aY = chart.ChartAreas[0].AxisY.PixelPositionToValue(y);

                long ttSec = DoubleTools.ToLong(aX * 86400.0);
                long dt    = TTCommon.TTSecToDateTime(ttSec);

                this.TTip.SetToolTip(
                    chart,
                    DateTimeUnit.FromDateTime(dt).ToString() + "\n" + aY.ToString("F9")
                    );
            }
            catch
            { }
        }
Beispiel #3
0
        private void MakeDataFile(string currPair)
        {
            Console.WriteLine("currPair: " + currPair);             // test cout

            CSChartManager cscm = new CSChartManager();
            CSChart        csc  = cscm.GetCSChart(currPair);
            TTChart        ttc  = new TTChart(csc);

            MAChart[] macs = new MAChart[MA_DAYS.Length];

            for (int index = 0; index < MA_DAYS.Length; index++)
            {
                macs[index] = new MAChart(ttSec => ttc.GetPrice(ttSec).Mid, 60 * 24 * MA_DAYS[index], 60);
            }

            long ttSecSt = TTCommon.DateTimeToTTSec(this.DateTimeSt);
            long ttSecEd = TTCommon.DateTimeToTTSec(this.DateTimeEd);

            Pulser pulser = new Pulser();

            using (CsvFileWriter writer = new CsvFileWriter(Path.Combine(W_DIR, currPair + ".csv")))
            {
                for (long ttSec = ttSecSt; ttSec <= ttSecEd; ttSec += 60)
                {
                    if (pulser.Invoke())
                    {
                        Console.WriteLine(TTCommon.TTSecToDateTime(ttSec) + " @ " + DateTime.Now);                         // test cout
                    }
                    writer.WriteCell(TTCommon.TTSecToDateTime(ttSec).ToString());
                    writer.WriteCell(ttSec.ToString());
                    writer.WriteCell(ttc.GetPrice(ttSec).Low.ToString("F9"));
                    writer.WriteCell(ttc.GetPrice(ttSec).Hig.ToString("F9"));
                    writer.WriteCell(ttc.GetPrice(ttSec).Mid.ToString("F9"));

                    foreach (MAChart mac in macs)
                    {
                        writer.WriteCell(mac.GetPrice(ttSec).ToString("F9"));
                    }

                    writer.EndRow();
                }
            }
            Console.WriteLine("done");             // test cout
        }
Beispiel #4
0
        private void MChart_MouseMove(object sender, MouseEventArgs e)
        {
            int x = e.X;
            int y = e.Y;

            if (this.MCMM_LastX == x && this.MCMM_LastY == y)
            {
                return;
            }

            this.MCMM_LastX = x;
            this.MCMM_LastY = y;

            if (this.MChart.ChartAreas.Count == 0)             // ? 未表示
            {
                return;
            }

            if (Ground.I.GrphData == null)             // ? 未表示
            {
                return;
            }

            if (Ground.I.GrphData.Start == -1)             // ? 未表示
            {
                return;
            }

            try
            {
                double aX = this.MChart.ChartAreas[0].AxisX.PixelPositionToValue(x);
                double aY = this.MChart.ChartAreas[0].AxisY.PixelPositionToValue(y);

                long ttSec = DoubleTools.ToLong(aX * 86400.0);
                long dt    = TTCommon.TTSecToDateTime(ttSec);

                this.TTip.SetToolTip(
                    this.MChart,
                    DateTimeUnit.FromDateTime(dt).ToString() + "\n" + aY.ToString("F9")
                    );
            }
            catch
            { }
        }
Beispiel #5
0
        private void DrawCharts()
        {
            long ttSecStart = this.TTSecEnd - this.TTSecStep * (Consts.PLOT_NUM - 1);

            this.MaChart.Series.Clear();
            this.MaChart.Legends.Clear();
            this.MaChart.ChartAreas.Clear();

            double maYMin = double.MaxValue;
            double maYMax = double.MinValue;

            // Low
            {
                Series srs = new Series();
                srs.ChartType   = SeriesChartType.Line;
                srs.Color       = Color.LightGray;
                srs.BorderWidth = 2;

                for (int index = 0; index < Consts.PLOT_NUM; index++)
                {
                    long   ttSec = this.TTSecEnd - this.TTSecStep * index;
                    double y     = ChartSrvc.I.Ttc.GetPrice(ttSec).Low;

                    maYMin = Math.Min(maYMin, y);
                    maYMax = Math.Max(maYMax, y);

                    srs.Points.AddXY(ttSec / 86400.0, y);
                }
                this.MaChart.Series.Add(srs);
            }

            // Hig
            {
                Series srs = new Series();
                srs.ChartType   = SeriesChartType.Line;
                srs.Color       = Color.LightGray;
                srs.BorderWidth = 2;

                for (int index = 0; index < Consts.PLOT_NUM; index++)
                {
                    long   ttSec = this.TTSecEnd - this.TTSecStep * index;
                    double y     = ChartSrvc.I.Ttc.GetPrice(ttSec).Hig;

                    maYMin = Math.Min(maYMin, y);
                    maYMax = Math.Max(maYMax, y);

                    srs.Points.AddXY(ttSec / 86400.0, y);
                }
                this.MaChart.Series.Add(srs);
            }

            // Mid
            {
                Series srs = new Series();
                srs.ChartType = SeriesChartType.Line;
                srs.Color     = Color.Green;

                for (int index = 0; index < Consts.PLOT_NUM; index++)
                {
                    long   ttSec = this.TTSecEnd - this.TTSecStep * index;
                    double y     = ChartSrvc.I.Ttc.GetPrice(ttSec).Mid;

                    maYMin = Math.Min(maYMin, y);
                    maYMax = Math.Max(maYMax, y);

                    srs.Points.AddXY(ttSec / 86400.0, y);
                }
                this.MaChart.Series.Add(srs);
            }

            for (int maIndex = 0; maIndex < ChartSrvc.I.Macs.Length; maIndex++)
            {
                ChartSrvc.MacInfo mac     = ChartSrvc.I.Macs[maIndex];
                Color             maColor = Consts.MaColors[maIndex];

                // ma
                {
                    Series srs = new Series();
                    srs.ChartType = SeriesChartType.Line;
                    srs.Color     = maColor;

                    for (int index = 0; index < Consts.PLOT_NUM; index++)
                    {
                        long   ttSec = this.TTSecEnd - this.TTSecStep * index;
                        double y     = mac.Mac.GetPrice(ttSec);

                        maYMin = Math.Min(maYMin, y);
                        maYMax = Math.Max(maYMax, y);

                        srs.Points.AddXY(ttSec / 86400.0, y);
                    }
                    this.MaChart.Series.Add(srs);
                }
            }

            // ca
            {
                ChartArea ca = new ChartArea();

                ca.AxisX.Minimum = ttSecStart / 86400.0;
                ca.AxisX.Maximum = this.TTSecEnd / 86400.0;
                ca.AxisY.Minimum = maYMin;
                ca.AxisY.Maximum = maYMax;

                {
                    double q = (ca.AxisX.Maximum - ca.AxisX.Minimum) / 6.0;

                    double x1 = ca.AxisX.Minimum;
                    double x2 = ca.AxisX.Minimum + q * 2.0;
                    double x3 = ca.AxisX.Minimum + q * 4.0;
                    double x4 = ca.AxisX.Maximum;

                    double xVal1 = ca.AxisX.Minimum + q * 1.0;
                    double xVal2 = ca.AxisX.Minimum + q * 3.0;
                    double xVal3 = ca.AxisX.Minimum + q * 5.0;

#if true
#if true
                    long xSec1 = DoubleTools.ToLong(xVal1 * 86400.0);
                    long xSec2 = DoubleTools.ToLong(xVal2 * 86400.0);
                    long xSec3 = DoubleTools.ToLong(xVal3 * 86400.0);

                    string xL1 = StringUtils.SecSpanToUIString(0);
                    string xL2 = StringUtils.SecSpanToUIString(xSec2 - xSec1);
                    string xL3 = StringUtils.SecSpanToUIString(xSec3 - xSec1);
#else // old
                    string xL1 = DateTimeUnit.FromDateTime(TTCommon.TTSecToDateTime(DoubleTools.ToLong(xVal1 * 86400.0))).ToString();
                    string xL2 = DateTimeUnit.FromDateTime(TTCommon.TTSecToDateTime(DoubleTools.ToLong(xVal2 * 86400.0))).ToString();
                    string xL3 = DateTimeUnit.FromDateTime(TTCommon.TTSecToDateTime(DoubleTools.ToLong(xVal3 * 86400.0))).ToString();
#endif

                    ca.AxisX.CustomLabels.Add(new CustomLabel(x1, x2, xL1, 0, LabelMarkStyle.None, GridTickTypes.All));
                    ca.AxisX.CustomLabels.Add(new CustomLabel(x2, x3, xL2, 0, LabelMarkStyle.None, GridTickTypes.All));
                    ca.AxisX.CustomLabels.Add(new CustomLabel(x3, x4, xL3, 0, LabelMarkStyle.None, GridTickTypes.All));
#else // old
                    ca.AxisX.CustomLabels.Add(new CustomLabel(x1, x2, xVal1.ToString("F3"), 0, LabelMarkStyle.None, GridTickTypes.All));
                    ca.AxisX.CustomLabels.Add(new CustomLabel(x2, x3, xVal2.ToString("F3"), 0, LabelMarkStyle.None, GridTickTypes.All));
                    ca.AxisX.CustomLabels.Add(new CustomLabel(x3, x4, xVal3.ToString("F3"), 0, LabelMarkStyle.None, GridTickTypes.All));
#endif
                }

                {
                    double q = (ca.AxisY.Maximum - ca.AxisY.Minimum) / 6.0;

                    double y1 = ca.AxisY.Minimum;
                    double y2 = ca.AxisY.Minimum + q * 2.0;
                    double y3 = ca.AxisY.Minimum + q * 4.0;
                    double y4 = ca.AxisY.Maximum;

                    double yVal1 = ca.AxisY.Minimum + q * 1.0;
                    double yVal2 = ca.AxisY.Minimum + q * 3.0;
                    double yVal3 = ca.AxisY.Minimum + q * 5.0;

                    ca.AxisY.CustomLabels.Add(new CustomLabel(y1, y2, yVal1.ToString("F3"), 0, LabelMarkStyle.None, GridTickTypes.All));
                    ca.AxisY.CustomLabels.Add(new CustomLabel(y2, y3, yVal2.ToString("F3"), 0, LabelMarkStyle.None, GridTickTypes.All));
                    ca.AxisY.CustomLabels.Add(new CustomLabel(y3, y4, yVal3.ToString("F3"), 0, LabelMarkStyle.None, GridTickTypes.All));
                }

                this.MaChart.ChartAreas.Add(ca);
            }

            this.DmaChart.Series.Clear();
            this.DmaChart.Legends.Clear();
            this.DmaChart.ChartAreas.Clear();

            double dmaYMin = Consts.DMA_LOW_03;
            double dmaYMax = Consts.DMA_HIG_03;

            {
                Action <double, int, Color> drawHorizontallyLine = (y, width, color) =>
                {
                    double x1 = ttSecStart / 86400.0;
                    double x2 = this.TTSecEnd / 86400.0;

                    Series srs = new Series();
                    srs.ChartType   = SeriesChartType.Line;
                    srs.Color       = color;
                    srs.BorderWidth = width;

                    srs.Points.AddXY(x1, y);
                    srs.Points.AddXY(x2, y);

                    this.DmaChart.Series.Add(srs);
                };

                drawHorizontallyLine(Consts.DMA_HIG_03, 7, Color.LightBlue);
                drawHorizontallyLine(Consts.DMA_HIG_02, 5, Color.LightBlue);
                drawHorizontallyLine(Consts.DMA_HIG_01, 3, Color.LightBlue);

                drawHorizontallyLine(0.0, 3, Color.LightGray);

                drawHorizontallyLine(Consts.DMA_LOW_01, 3, Color.LightPink);
                drawHorizontallyLine(Consts.DMA_LOW_02, 5, Color.LightPink);
                drawHorizontallyLine(Consts.DMA_LOW_03, 7, Color.LightPink);
            }

            for (int maIndex = 0; maIndex < ChartSrvc.I.Macs.Length; maIndex++)
            {
                ChartSrvc.MacInfo mac     = ChartSrvc.I.Macs[maIndex];
                Color             maColor = Consts.MaColors[maIndex];

                // ma
                {
                    Series srs = new Series();
                    srs.ChartType = SeriesChartType.Line;
                    srs.Color     = maColor;

                    for (int index = 0; index < Consts.PLOT_NUM; index++)
                    {
                        long   ttSec = this.TTSecEnd - this.TTSecStep * index;
                        double prY   = ChartSrvc.I.Ttc.GetPrice(ttSec).Mid;
                        double maY   = mac.Mac.GetPrice(ttSec);
                        double y     = (prY - maY) / maY;

                        dmaYMin = Math.Min(dmaYMin, y);
                        dmaYMax = Math.Max(dmaYMax, y);

                        srs.Points.AddXY(ttSec / 86400.0, y);
                    }
                    this.DmaChart.Series.Add(srs);
                }
            }

            // ca
            {
                ChartArea ca = new ChartArea();

                ca.AxisX.Minimum = ttSecStart / 86400.0;
                ca.AxisX.Maximum = this.TTSecEnd / 86400.0;
                ca.AxisY.Minimum = dmaYMin;
                ca.AxisY.Maximum = dmaYMax;

                {
                    double q = (ca.AxisX.Maximum - ca.AxisX.Minimum) / 6.0;

                    double x1 = ca.AxisX.Minimum;
                    double x2 = ca.AxisX.Minimum + q * 2.0;
                    double x3 = ca.AxisX.Minimum + q * 4.0;
                    double x4 = ca.AxisX.Maximum;

                    double xVal1 = ca.AxisX.Minimum + q * 1.0;
                    double xVal2 = ca.AxisX.Minimum + q * 3.0;
                    double xVal3 = ca.AxisX.Minimum + q * 5.0;

#if true
                    string xL1 = DateTimeUnit.FromDateTime(TTCommon.TTSecToDateTime(DoubleTools.ToLong(xVal1 * 86400.0))).ToString();
                    string xL2 = DateTimeUnit.FromDateTime(TTCommon.TTSecToDateTime(DoubleTools.ToLong(xVal2 * 86400.0))).ToString();
                    string xL3 = DateTimeUnit.FromDateTime(TTCommon.TTSecToDateTime(DoubleTools.ToLong(xVal3 * 86400.0))).ToString();

                    ca.AxisX.CustomLabels.Add(new CustomLabel(x1, x2, xL1, 0, LabelMarkStyle.None, GridTickTypes.All));
                    ca.AxisX.CustomLabels.Add(new CustomLabel(x2, x3, xL2, 0, LabelMarkStyle.None, GridTickTypes.All));
                    ca.AxisX.CustomLabels.Add(new CustomLabel(x3, x4, xL3, 0, LabelMarkStyle.None, GridTickTypes.All));
#else // old
                    ca.AxisX.CustomLabels.Add(new CustomLabel(x1, x2, xVal1.ToString("F3"), 0, LabelMarkStyle.None, GridTickTypes.All));
                    ca.AxisX.CustomLabels.Add(new CustomLabel(x2, x3, xVal2.ToString("F3"), 0, LabelMarkStyle.None, GridTickTypes.All));
                    ca.AxisX.CustomLabels.Add(new CustomLabel(x3, x4, xVal3.ToString("F3"), 0, LabelMarkStyle.None, GridTickTypes.All));
#endif
                }

                {
                    double q = (ca.AxisY.Maximum - ca.AxisY.Minimum) / 6.0;

                    double y1 = ca.AxisY.Minimum;
                    double y2 = ca.AxisY.Minimum + q * 2.0;
                    double y3 = ca.AxisY.Minimum + q * 4.0;
                    double y4 = ca.AxisY.Maximum;

                    double yVal1 = ca.AxisY.Minimum + q * 1.0;
                    double yVal2 = ca.AxisY.Minimum + q * 3.0;
                    double yVal3 = ca.AxisY.Minimum + q * 5.0;

                    ca.AxisY.CustomLabels.Add(new CustomLabel(y1, y2, yVal1.ToString("F3"), 0, LabelMarkStyle.None, GridTickTypes.All));
                    ca.AxisY.CustomLabels.Add(new CustomLabel(y2, y3, yVal2.ToString("F3"), 0, LabelMarkStyle.None, GridTickTypes.All));
                    ca.AxisY.CustomLabels.Add(new CustomLabel(y3, y4, yVal3.ToString("F3"), 0, LabelMarkStyle.None, GridTickTypes.All));
                }

                this.DmaChart.ChartAreas.Add(ca);
            }

            {
                string text =
                    DateTimeUnit.FromDateTime(TTCommon.TTSecToDateTime(ttSecStart)).ToString() +
                    " ~ " +
                    DateTimeUnit.FromDateTime(TTCommon.TTSecToDateTime(this.TTSecEnd)).ToString() +
                    ", Range: " +
                    (this.TTSecEnd - ttSecStart) +
                    " sec (" +
                    ((this.TTSecEnd - ttSecStart) / 86400.0) +
                    " days), Step: " +
                    this.TTSecStep +
                    " sec, MA: { " +
                    string.Join(", ", ChartSrvc.I.Macs.Select(v => v.SecSpan + "s_" + (v.SecSpan / 86400.0).ToString("F3") + "d")) +
                    " } MA_Step: " +
                    this.MaStep +
                    " sec";

                if (this.South.Text != text)
                {
                    this.South.Text = text;
                }
            }
        }