public SymbolBar(string code, TimedBar bar) { this.Code = code; this.Bar = new Bar { Open = bar.Open, High = bar.High, Low = bar.Low, Close = bar.Close, Volume = bar.Volume, }; this.Time = bar.OpenTime; }
private void M1_Bar(TimedBar m1Bar, bool isPartial) { var serverTime = Account.ServerTime; //if (!IsSamePeriod(m1Bar.Time, Account.ServerTime) && m1Bar.Time < Account.ServerTime) //{ // logger.LogWarning($"[BAR] Got old {SymbolCode} bar for time {m1Bar.Time } when server time is {Account.ServerTime}"); //} if (m1Bar.OpenTime > ServerTimeFromM1Bar) { ServerTimeFromM1Bar = m1Bar.OpenTime; // May trigger a bar from previous minute, for all symbols, after a delay (to wait for remaining ticks to come in) } //#if FromTickToMinute if (bar.IsValid && !IsSamePeriod(bar.OpenTime, m1Bar.OpenTime)) { // Immediately Trigger a finished bar even after starting the timer above. RaiseTimeFrameBar(bar); bar = TimedBar.Invalid; } if (!bar.IsValid) { bar = new TimedBar() { OpenTime = MarketSeries.TimeFrame.GetPeriodStart(m1Bar.OpenTime), Open = m1Bar.Open, High = m1Bar.High, Low = m1Bar.Low, Close = m1Bar.Close, Volume = m1Bar.Volume, }; } else { bar = bar.Merge(m1Bar); } if (double.IsNaN(bar.Volume)) // REVIEW - is this correct for volume? { bar.Volume = 1; } else { bar.Volume++; } }
private void RaiseTimeFrameBar(TimedBar bar, bool finishedBar = true) { lock (M1BarToTimeFrameBarLock) { //var bar = tickToMinuteBars[symbolCode]; if (!bar.IsValid) { return; } var partial = finishedBar ? "" : " PARTIAL"; Debug.WriteLine($"[M1 to {MarketSeries.ToString()}] {bar}{partial}"); ((IMarketSeriesInternal)this.MarketSeries).OnBar(bar, finishedBar); bar = TimedBar.New; } }
public TimedBar Merge(TimedBar next) { var current = this; if (next.OpenTime != null) { High = Math.Max(current.High, next.High); Low = Math.Min(current.Low, next.Low); Close = next.Close; Volume = current.Volume + next.Volume; } return(this); //return new TimedBar //{ // OpenTime = current.OpenTime, // Open = current.Open, // Close = next.Close, // High = Math.Max(current.High, next.High), // Low = Math.Min(current.Low, next.Low), // Volume = current.Volume + next.Volume //}; }
static TimedBar() { Invalid = New; }
private void M1_Bar(TimedBar m1Bar) { M1_Bar(m1Bar, false); }
public virtual void OnBar(string symbolCode, TimeFrame timeFrame, TimedBar bar) { }
public void OnBar(IMarketSeries series, TimedBar bar) { OnBar(series.SymbolCode, series.TimeFrame, bar); }