public double GetValue(RawPrice.Value_e eValue) { if (Exac != null) { return(Exac[eValue]); } if (Prev == null) { if (Next == null) { return(UNKNOWN_CURRENCY_PAIR_VALUE); } return(Next[eValue]); } if (Next == null) { return(Prev[eValue]); } long p = DateTimeToSec.toSec(Prev.DateTime); long e = DateTimeToSec.toSec(this.DateTime); long n = DateTimeToSec.toSec(Next.DateTime); double rate = (double)(e - p) / (n - p); return(Prev[eValue] + (Next[eValue] - Prev[eValue]) * rate); }
private void WeSetDebugWin_Load(object sender, EventArgs e) { List <string> dest = new List <string>(); // ---- long sec = DateTimeToSec.toSec(20170529070000L); // 月曜日の7:00 == 取引開始 dest.Add("" + (sec % (86400L * 7))); // ---- lblOutput.Text = string.Join("\r\n", dest); }
private void executeArgs(bool keepAxY = false) { string args = this.Args.Text; try { args = StringTools.tokenize(args, "#")[0]; // ---- args -> vars ---- Queue <string> argq = new Queue <string>(StringTools.tokenize(args, ":")); CurrencyPair cPair = CurrencyPairs.All[CurrencyPairs.IndexOf(argq.Dequeue())]; long dateTime = long.Parse(argq.Dequeue()); if (DateTimeToSec.isFairDateTime(dateTime) == false) { throw new Exception("Bad dateTime"); } long secStart = DateTimeToSec.toSec(dateTime); long secInterval = StringToSec(argq.Dequeue()); long secBound = StringToSec(argq.Dequeue()); string sVisHigLow = argq.Dequeue(); long secMvAvgInterval = -1L; if (1 <= argq.Count) // 省略可能につき { secMvAvgInterval = StringToSec(argq.Dequeue()); } List <long> secMvAvgs = new List <long>(); while (1 <= argq.Count) // 省略可能につき { secMvAvgs.Add(StringToSec(argq.Dequeue())); } argq = null; if (secInterval < 1L) { throw new Exception("interval < 1"); } if (secBound < secInterval) { throw new Exception("bound < interval"); } if (secBound % secInterval != 0) { throw new Exception("期間はインターバルの倍数にしてね!"); } if (Consts.SAMPLING_MAX < secBound / secInterval) { throw new Exception("インターバル刻みすぎ!"); } if (Consts.SEC_BOUND_MAX < secBound) { throw new Exception("期間長過ぎ!"); } bool visHigLow; switch (sVisHigLow) { case "T": visHigLow = true; break; case "F": visHigLow = false; break; default: throw new Exception("Bad sVisHigLow: " + sVisHigLow); } //secBound /= secInterval; //secBound *= secInterval; // secMvAvgInterval ここでチェックしない。MovingAverage ctor に任せる。 // ---- //CurrencyPairs.FxCollect(); this.MChart.Series.Clear(); //this.MChart.Legends.Clear(); this.MChart.ChartAreas.Clear(); // ここから sec -> weSec に切り替えていく。 secStart = WeSec.SecToWeSec(secStart); double minMid = double.MaxValue; double maxMid = double.MinValue; WeSecPrices wsp = new WeSecPrices(cPair); List <MovingAverage> mvAvgs = new List <MovingAverage>(); foreach (long secMvAvg in secMvAvgs) { mvAvgs.Add(new MovingAverage(wsp, secMvAvgInterval, secMvAvg)); } if (visHigLow) { // 高値 { Series srs = new Series(); srs.ChartType = SeriesChartType.Line; srs.Color = Color.LightGray; for (long sec = 0; sec <= secBound; sec += secInterval) { double hig = wsp.GetPrice(secStart - sec).High; minMid = Math.Min(minMid, hig); maxMid = Math.Max(maxMid, hig); srs.Points.AddXY(-sec / 86400.0, hig); } this.MChart.Series.Add(srs); } // 安値 { Series srs = new Series(); srs.ChartType = SeriesChartType.Line; srs.Color = Color.Gray; for (long sec = 0; sec <= secBound; sec += secInterval) { double low = wsp.GetPrice(secStart - sec).Low; minMid = Math.Min(minMid, low); maxMid = Math.Max(maxMid, low); srs.Points.AddXY(-sec / 86400.0, low); } this.MChart.Series.Add(srs); } } // Mid { Series srs = new Series(); srs.ChartType = SeriesChartType.Line; srs.Color = Color.Green; for (long sec = 0; sec <= secBound; sec += secInterval) { double mid = wsp.GetPrice(secStart - sec).Mid; //double mid = cPair.GetPrice(DateTimeToSec.toDateTime(secStart - sec)).Mid; minMid = Math.Min(minMid, mid); maxMid = Math.Max(maxMid, mid); srs.Points.AddXY(-sec / 86400.0, mid); } this.MChart.Series.Add(srs); } Color[] MVAVG_COLORS = new Color[] { Color.Red, Color.Blue, Color.Purple, Color.DarkCyan, Color.DarkOrange, Color.DarkGray, }; for (int index = 0; index < mvAvgs.Count; index++) { MovingAverage mvAvg = mvAvgs[index]; Series srs = new Series(); srs.ChartType = SeriesChartType.Line; srs.Color = MVAVG_COLORS[index % MVAVG_COLORS.Length]; for (long sec = 0; ; sec += secMvAvgInterval) { double mid = mvAvg.GetMid(secStart - sec); //double mid = cPair.GetPrice(DateTimeToSec.toDateTime(secStart - sec)).Mid; minMid = Math.Min(minMid, mid); maxMid = Math.Max(maxMid, mid); srs.Points.AddXY(-sec / 86400.0, mid); if (secBound <= sec) { break; } } this.MChart.Series.Add(srs); } if (keepAxY) { minMid = LastAxYMin; maxMid = LastAxYMax; } else { LastAxYMin = minMid; LastAxYMax = maxMid; } LastStartWeSec = secStart; ChartArea ca = new ChartArea(); { double METER_SCALE = 1000.0; minMid = (long)(minMid * METER_SCALE) / METER_SCALE; maxMid = ((long)(maxMid * METER_SCALE) + 1) / METER_SCALE; } double axInterval; if (secBound < 86400L) { axInterval = 1.0 / 24.0; } else if (secBound < 86400L * 3) { axInterval = 1.0 / 2.0; } else if (secBound < 86400L * 25) { axInterval = 1.0; } else if (secBound < 86400L * 100) { axInterval = 5.0; } else if (secBound < 86400L * 250) { axInterval = 25.0; } else if (secBound < 86400L * 500) { axInterval = 50.0; } else { axInterval = 100.0; } ca.AxisX.Minimum = -secBound / 86400.0; ca.AxisX.Maximum = 0.0; ca.AxisX.Interval = axInterval; ca.AxisY.Minimum = minMid; ca.AxisY.Maximum = maxMid; this.MChart.ChartAreas.Add(ca); // ---- // 成功 this.Args.ForeColor = Color.Black; this.Args.Text = args; this.Args.SelectAll(); } catch (Exception e) { // 失敗 this.TTip.SetToolTip(this.Args, "" + e); this.Args.ForeColor = Color.Red; this.Args.Text = args + "#" + e.Message; this.Args.SelectionStart = 0; this.Args.SelectionLength = args.Length; } GC.Collect(); // 2bs }
private void DoAltCommand(string command, bool keepAxY = false) { try { string args = this.Args.Text; List <string> tokens = StringTools.tokenize(args, ":"); long dateTime = long.Parse(tokens[1]); long sec = DateTimeToSec.toSec(dateTime); long weSec = WeSec.SecToWeSec(sec); switch (command) { case "戻る": { long secBound = this.StringToSec(tokens[3]); weSec -= secBound / 4; } break; case "進む": { long secBound = this.StringToSec(tokens[3]); weSec += secBound / 4; } break; case "Y-拡大": { expandAxY(1.0 / 1.5); keepAxY = true; } break; case "Y-縮小": { expandAxY(1.5); keepAxY = true; } break; case "拡大": { long secInterval = this.StringToSec(tokens[2]); long secBound = this.StringToSec(tokens[3]); secInterval /= 2; secBound /= 2; // 調整 TODO { if (secBound % secInterval != 0) { secBound /= secInterval; secBound *= secInterval; } } tokens[2] = this.SecToString(secInterval); tokens[3] = this.SecToString(secBound); } break; case "縮小": { long secInterval = this.StringToSec(tokens[2]); long secBound = this.StringToSec(tokens[3]); secInterval *= 2; secBound *= 2; tokens[2] = this.SecToString(secInterval); tokens[3] = this.SecToString(secBound); } break; default: throw null; } sec = WeSec.WeSecToSec(weSec); dateTime = DateTimeToSec.toDateTime(sec); tokens[1] = "" + dateTime; args = string.Join(":", tokens); this.Args.Text = args; executeArgs(keepAxY); } catch { } }
public static long DateTimeToWeSec(long dateTime) { return(SecToWeSec(DateTimeToSec.toSec(dateTime))); }