示例#1
0
        // ---- 項目ここまで

        public bool IsSame(GrphCond other)
        {
            return
                (this.CurrPair == other.CurrPair &&
                 this.DateTimeSt == other.DateTimeSt &&
                 this.DateTimeEd == other.DateTimeEd &&
                 ArrayTools.Comp(this.MaDays, other.MaDays, (a, b) => a.Index - b.Index) == 0);
        }
示例#2
0
文件: MainWin.cs 项目: stackprobe/Fx
        private GrphCond GetGrphCond()
        {
            GrphCond cond = new GrphCond();

            {
                string currPair = this.CurrPair.SelectedItem.ToString();

                if (StringTools.LiteValidate(currPair, StringTools.ALPHA, 6, 6) == false)
                {
                    throw new Exception("通貨ペアが選択されていません。");
                }

                cond.CurrPair = currPair;
            }

            {
                long st = long.Parse(this.DateTimeSt.Text);
                long ed = long.Parse(this.DateTimeEd.Text);

                if (DateTimeToSecUtils.IsFairDateTime(st) == false)
                {
                    throw new Exception("開始日時の書式エラー");
                }

                if (DateTimeToSecUtils.IsFairDateTime(ed) == false)
                {
                    throw new Exception("終了日時の書式エラー");
                }

                if (st < Ground.I.Period_DateTimeSt)
                {
                    throw new Exception("開始日時が古すぎる。");
                }

                if (Ground.I.Period_DateTimeEd < ed)
                {
                    throw new Exception("終了日時が先すぎる。");
                }

                if (ed <= st)
                {
                    throw new Exception("終了日時 <= 開始日時");
                }

                cond.DateTimeSt = st;
                cond.DateTimeEd = ed;
            }

            CheckBox[] maDayCBs = GetMaDayCheckBoxes();

            {
                List <GrphCond.MaDayInfo> dest = new List <GrphCond.MaDayInfo>();

                for (int index = 0; index < maDayCBs.Length; index++)
                {
                    CheckBox maDayCB = maDayCBs[index];

                    if (maDayCB.Checked)
                    {
                        dest.Add(new GrphCond.MaDayInfo()
                        {
                            Index = index,
                            Day   = int.Parse(maDayCB.Tag.ToString()),
                        });
                    }
                }
                cond.MaDays = dest.ToArray();
            }

            return(cond);
        }
示例#3
0
文件: MainWin.cs 项目: stackprobe/Fx
        private void DrawGrph(GrphCond cond)
        {
            if (Ground.I.GrphData == null || cond.CurrPair != Ground.I.GrphData.CurrPair)             // ? グラフデータ更新の必要あり
            {
                Ground.I.GrphData = null;
                GC.Collect();

                BusyDlgTools.Show(Program.APP_TITLE, "グラフデータをロードしています。(通貨ペア:" + cond.CurrPair + ")", () =>
                {
                    Ground.I.GrphData = new GrphData(cond.CurrPair);
                });

                GC.Collect();
            }

            Ground.I.GrphData.SetRange(cond.DateTimeSt, cond.DateTimeEd);

            // ---- グラフの描画ここから

            this.MChart.Series.Clear();
            this.MChart.ChartAreas.Clear();

            double yMin = double.MaxValue;
            double yMax = double.MinValue;

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

                for (int index = Ground.I.GrphData.Start; index <= Ground.I.GrphData.End; index += Ground.I.GrphData.Step)
                {
                    GrphData.PriceInfo price = Ground.I.GrphData.GetPrice(index);
                    double             low   = price.Low;

                    yMin = Math.Min(yMin, low);
                    yMax = Math.Max(yMax, low);

                    srs.Points.AddXY(price.TTSec / 86400.0, low);
                }
                this.MChart.Series.Add(srs);
            }

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

                for (int index = Ground.I.GrphData.Start; index <= Ground.I.GrphData.End; index += Ground.I.GrphData.Step)
                {
                    GrphData.PriceInfo price = Ground.I.GrphData.GetPrice(index);
                    double             hig   = price.Hig;

                    yMin = Math.Min(yMin, hig);
                    yMax = Math.Max(yMax, hig);

                    srs.Points.AddXY(price.TTSec / 86400.0, hig);
                }
                this.MChart.Series.Add(srs);
            }

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

                for (int index = Ground.I.GrphData.Start; index <= Ground.I.GrphData.End; index += Ground.I.GrphData.Step)
                {
                    GrphData.PriceInfo price = Ground.I.GrphData.GetPrice(index);
                    double             mid   = price.Mid;

                    yMin = Math.Min(yMin, mid);
                    yMax = Math.Max(yMax, mid);

                    srs.Points.AddXY(price.TTSec / 86400.0, mid);
                }
                this.MChart.Series.Add(srs);
            }

            Color[] maColors = new Color[]
            {
                Color.Red,
                Color.Blue,
                Color.Purple,
                Color.DarkCyan,
                Color.DarkOrange,
            };

            for (int maIndex = 0; maIndex < cond.MaDays.Length; maIndex++)
            {
                GrphCond.MaDayInfo maDay = cond.MaDays[maIndex];
                int   maColorIndex       = Math.Min(maIndex, maColors.Length - 1);
                Color maColor            = maColors[maColorIndex];

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

                    for (int index = Ground.I.GrphData.Start; index <= Ground.I.GrphData.End; index += Ground.I.GrphData.Step)
                    {
                        GrphData.PriceInfo price = Ground.I.GrphData.GetPrice(index);
                        double             maVal = price.MaVals[maDay.Index];

                        yMin = Math.Min(yMin, maVal);
                        yMax = Math.Max(yMax, maVal);

                        srs.Points.AddXY(price.TTSec / 86400.0, maVal);
                    }
                    this.MChart.Series.Add(srs);
                }
            }

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

                {
                    long span = Ground.I.GrphData.GetPrice(Ground.I.GrphData.End).TTSec - Ground.I.GrphData.GetPrice(Ground.I.GrphData.Start).TTSec;

                    if (span < 86400)
                    {
                        axInterval = 1.0 / 24;
                    }
                    else if (span < 86400 * 2)
                    {
                        axInterval = 0.5;
                    }
                    else if (span < 86400 * 20)
                    {
                        axInterval = 1.0;
                    }
                    else
                    {
                        axInterval = 10.0;
                    }
                }

                ca.AxisX.Minimum  = Ground.I.GrphData.GetPrice(Ground.I.GrphData.Start).TTSec / 86400.0;
                ca.AxisX.Maximum  = Ground.I.GrphData.GetPrice(Ground.I.GrphData.End).TTSec / 86400.0;
                ca.AxisX.Interval = axInterval;
                ca.AxisY.Minimum  = yMin;
                ca.AxisY.Maximum  = yMax;

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

            // ---- グラフの描画ここまで
        }
示例#4
0
文件: MainWin.cs 项目: stackprobe/Fx
        private void MainTimer_Tick(object sender, EventArgs e)
        {
            if (this.MTBusy.HasVisitor())
            {
                return;
            }

            this.MTBusy.Enter();
            try
            {
                if (this.XPressed)
                {
                    this.XPressed = false;
                    this.CloseWindow();
                    return;
                }

                // -- 3001

                // ---- CondChanged

                if (this.CondChangedCount == 1)                 // Do Refresh
                {
                    GrphCond cond                = null;
                    string   statusText          = this.Status.Text;
                    bool     statusTextErrorFlag = false;

                    try
                    {
                        cond = this.GetGrphCond();
                    }
                    catch (Exception ex)
                    {
                        statusText          = ex.Message;
                        statusTextErrorFlag = true;

                        this.LastGrphCond = null;
                    }

                    if (cond != null && (this.LastGrphCond == null || this.LastGrphCond.IsSame(cond) == false)) // ? グラフ更新の必要あり
                    {
                        this.LastGrphCond = cond;                                                               // DrawGrph()が例外を投げたとき何度もDrawGrph()しないよう、先に更新する。
                        this.DrawGrph(cond);

                        statusText =
                            DateTimeUnit.FromDateTime(Ground.I.GrphData.GetPrice(Ground.I.GrphData.Start).DateTime) +
                            " ~ " +
                            DateTimeUnit.FromDateTime(Ground.I.GrphData.GetPrice(Ground.I.GrphData.End).DateTime) +
                            ", Range: " +
                            (Ground.I.GrphData.GetPrice(Ground.I.GrphData.End).TTSec - Ground.I.GrphData.GetPrice(Ground.I.GrphData.Start).TTSec) +
                            " sec (" +
                            ((Ground.I.GrphData.GetPrice(Ground.I.GrphData.End).TTSec - Ground.I.GrphData.GetPrice(Ground.I.GrphData.Start).TTSec) / 86400.0).ToString("F3") +
                            " days), Step: " +
                            Ground.I.GrphData.Step +
                            " mins";
                    }

                    if (this.Status.Text != statusText)
                    {
                        this.Status.Text = statusText;
                    }

                    Color statusTextForeColor = Consts.LABEL_FORE_COLOR;
                    Color statusTextBackColor = Consts.LABEL_BACK_COLOR;

                    if (statusTextErrorFlag)
                    {
                        statusTextForeColor = Color.White;
                        statusTextBackColor = Color.Red;
                    }

                    if (this.Status.ForeColor != statusTextForeColor)
                    {
                        this.Status.ForeColor = statusTextForeColor;
                    }

                    if (this.Status.BackColor != statusTextBackColor)
                    {
                        this.Status.BackColor = statusTextBackColor;
                    }
                }

                {
                    string text = StringTools.Repeat("/", this.CondChangedCount);

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

                if (0 < this.CondChangedCount)
                {
                    this.CondChangedCount--;
                }

                // ----
            }
            catch (Exception ex)
            {
                MessageDlgTools.Error(Program.APP_TITLE + " - Error @ Timer", ex);
            }
            finally
            {
                this.MTBusy.Leave();
                this.MTCount++;
            }
        }