失敗是正常的,因為程式的K Bar 計算不正確,就會影響整個交易結果 private IEnumerable<OHLCBar> generate_OHLCBar(IEnumerable<Tick> ticks, long barSizeInTicks) { TimeSpan natural_time = new TimeSpan(8, 45, 0); var bars = from tick in ticks let barIndexForDay = Math.Floor(tick.Timestamp.TimeOfDay.Subtract(natural_time).TotalSeconds / barSizeInTicks) let barBeginDateTime = tick.Timestamp.Date.Add(natural_time).AddSeconds(barIndexForDay * barSizeInTicks) let barEndDateTime = tick.Timestamp.Date.Add(natural_time).AddSeconds((barIndexForDay + 1) * barSizeInTicks) group tick by new { barBeginDateTime, barEndDateTime, tick.Symbol } into tickGroup orderby tickGroup.Key.barBeginDateTime 你有空再確認一下,每個時間區間是否是你要的結果