private List <Bar> GenerateTickHistory(int interval, int maxBars, double lastPrice) { List <Bar> bars = new List <Bar>(); DateTime barTime = DateTime.UtcNow; barTime = new DateTime(barTime.Year, barTime.Month, barTime.Day, barTime.Hour, barTime.Minute, 0); var tick = new HistoryTickItem(barTime, lastPrice, 0); for (int i = 0; i < maxBars; i++) { tick = GenerateHistoryTick(tick); Bar aBar = new Bar { Date = tick.Time, Open = tick.Price, Close = tick.Price, High = tick.Price, Low = tick.Price, Volume = tick.Volume }; for (int t = 1; t < interval; t++) { tick = GenerateHistoryTick(tick); aBar.Open = tick.Price; aBar.High = Math.Max(aBar.High, aBar.Open); aBar.Low = Math.Min(aBar.Low, aBar.Open); aBar.Volume += tick.Volume; } bars.Add(aBar); } return(bars); }
private HistoryTickItem GenerateHistoryTick(HistoryTickItem tick) { DateTime date = tick.Time.AddSeconds(-m_Random.NextDouble()); double priceShift = (m_Random.NextDouble() > 0.5 ? 1 : -1) * (double)m_Random.Next(1000) / 100; int volume = m_Random.Next(1000000); return(new HistoryTickItem(date, tick.Price + priceShift, volume)); }
private List <Bar> GenerateRangeHistory(int interval, int maxBars, double lastPrice) { int maxTickGenerateCount = 50; double range = _tickSize * interval; List <Bar> bars = new List <Bar>(); DateTime barTime = DateTime.UtcNow; barTime = new DateTime(barTime.Year, barTime.Month, barTime.Day, barTime.Hour, barTime.Minute, 0); var tick = new HistoryTickItem(barTime, lastPrice, 0); for (int i = 0; i < maxBars; i++) { tick = GenerateHistoryTick(tick); Bar aBar = new Bar { Date = tick.Time, Open = tick.Price, Close = tick.Price, High = tick.Price, Low = tick.Price, Volume = tick.Volume }; bool created = false; for (int t = 0; t < maxTickGenerateCount; t++) { tick = GenerateHistoryTick(tick); aBar.Close = tick.Price; aBar.High = Math.Max(aBar.High, aBar.Close); aBar.Low = Math.Min(aBar.Low, aBar.Close); aBar.Volume += tick.Volume; if (aBar.High - aBar.Low > range) { created = true; break; } } if (!created) { if (aBar.Close - aBar.Low < aBar.High - aBar.Close) { aBar.Close = aBar.Low = aBar.High - range - (double)m_Random.Next(1000) / 1000; } else { aBar.Close = aBar.High = aBar.Low + range + (double)m_Random.Next(1000) / 1000; } } bars.Add(aBar); } return(bars); }