private void Test01_a(long dateTime) { long ttSec = TTCommon.DateTimeToTTSec(dateTime); long ret = TTCommon.TTSecToDateTime(ttSec); Console.WriteLine(dateTime + " -> " + ttSec + " -> ..."); Console.WriteLine(ret); }
private void Test01() { CSChartManager cscm = new CSChartManager(); CSChart csc = cscm.GetCSChart("USDJPY"); TTChart ttc = new TTChart(csc); MAChart mac = new MAChart(ttSec => ttc.GetPrice(ttSec).Mid, 10, 60); Console.WriteLine(mac.GetPrice(TTCommon.DateTimeToTTSec(20200401000000))); }
public void Test01() { CSChartManager cscm = new CSChartManager(); TTChart ttc = new TTChart(cscm.GetCSChart("USDJPY")); long ttSec = TTCommon.DateTimeToTTSec(20191101060000); Console.WriteLine(ttc.GetPrice(ttSec++).Ask); Console.WriteLine(ttc.GetPrice(ttSec++).Ask); Console.WriteLine(ttc.GetPrice(ttSec++).Ask); }
private void Test01_a(int dateStart, int dateEnd) { for (int maDay = 5; maDay <= 30; maDay += 5) { List <Info> infos = new List <Info>(); CSChartManager cscm = new CSChartManager(); CSChart csc = cscm.GetCSChart("USDJPY"); TTChart ttc = new TTChart(csc); MAChart mac = new MAChart(ttSec => ttc.GetPrice(ttSec).Mid, 60 * 24 * maDay, 60); for (int date = dateStart; date <= dateEnd;) { int nextDate = date; do { nextDate = DateToDay.ToDate(DateToDay.ToDay(nextDate) + 1); }while ("土日".Contains(DateTimeUnit.FromDate(nextDate).GetWeekday())); int bNextDate = Test01_b(nextDate, date, csc); long dt = date * 1000000L + 90000; long bNextDt = bNextDate * 1000000L + 90000; // ---- infos.Add(new Info() { MvAvgPrice = mac.GetPrice(TTCommon.DateTimeToTTSec(dt)), Price = csc.GetPrice(dt).Mid, NextDayPrice = csc.GetPrice(bNextDt).Mid, }); // ---- date = nextDate; } using (CsvFileWriter writer = new CsvFileWriter(string.Format(@"C:\temp\maDay={0}.csv", maDay))) { foreach (Info info in infos) { writer.WriteCell(info.Price.ToString("F9")); writer.WriteCell(info.MvAvgPrice.ToString("F9")); writer.WriteCell(info.NextDayPrice.ToString("F9")); writer.WriteCell((info.MvAvgPrice / info.Price).ToString("F9")); writer.WriteCell((info.NextDayPrice / info.Price).ToString("F9")); writer.EndRow(); } } } }
public void Test01() { CSChartManager cscm = new CSChartManager(); CSChart csc = cscm.GetCSChart("USDJPY"); TTChart ttc = new TTChart(csc); MAChart mac = new MAChart(ttSec => ttc.GetPrice(ttSec).Mid, 10, 60); for (int c = 0; c < 100; c++) { long ttSec = TTCommon.DateTimeToTTSec(20191101060000) + c * 60; Console.WriteLine(ttc.GetPrice(ttSec).Mid.ToString("F9") + " " + mac.GetPrice(ttSec).ToString("F9")); } }
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 { } }
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 }
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 { } }
private void MainWin_Shown(object sender, EventArgs e) { // -- 0001 try { this.MainWin_Resize(null, null); { string currPair = InputComboDlgTools.Show( "通貨ペア選択", "通貨ペアを選択して下さい。", Consts.CurrPairs.Select(v => new InputComboDlgTools.Item <string>(v, v)), false, Consts.DefaultCurrPair ); if (currPair == null) { throw new Exception("currPair == null"); } ChartSrvc.I = new ChartSrvc(currPair); } Consts.TTSEC_END_MIN = TTCommon.DateTimeToTTSec(20000101000000); Consts.TTSEC_END_MAX = TTCommon.DateTimeToTTSec(DateTimeToSec.Now.GetDateTime()); this.TTSecEnd = Consts.TTSEC_END_MAX; this.TTSecStep = Consts.TTSEC_STEP_MIN; { int maStep = InputStringDlgTools.Int( "移動平均プロット間隔入力", "移動平均のプロット間隔を秒単位で入力して下さい。", false, 60, Consts.MA_STEP_MIN, Consts.MA_STEP_MAX, -1 ); if (maStep == -1) { throw new Exception("maStep == -1"); } this.MaStep = maStep; } ChartSrvc.I.Macs = new ChartSrvc.MacInfo[] { ChartSrvc.MacInfo.Safe(86400 * 5, this.MaStep), // 5 days ChartSrvc.MacInfo.Safe(86400 * 25, this.MaStep), // 25 days }; this.DrawCharts(); this.移動平均入力ToolStripMenuItem_Click(null, null); // zantei } catch (Exception ex) { MessageDlgTools.Error("Error @ Shown", ex); Environment.Exit(1); // fatal } // ---- this.MTBusy.Leave(); }
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; } } }