private void OnBarsUpdate(object sender, BarsUpdateEventArgs e) { if (State == State.Active && SuperDom != null && SuperDom.IsConnected) { if (SuperDom.IsReloading) { OnPropertyChanged(); return; } BarsUpdateEventArgs barsUpdate = e; lock (barsSync) { int currentMaxIndex = barsUpdate.MaxIndex; for (int i = lastMaxIndex + 1; i <= currentMaxIndex; i++) { if (barsUpdate.BarsSeries.GetIsFirstBarOfSession(i)) { // If a new session starts, clear out the old values and start fresh LastVolumes.Clear(); } double ask = barsUpdate.BarsSeries.GetAsk(i); double bid = barsUpdate.BarsSeries.GetBid(i); double close = barsUpdate.BarsSeries.GetClose(i); long volume = barsUpdate.BarsSeries.GetVolume(i); if (Bidask == VolumeSide.ask && lastBid != bid && close <= bid) { lastBid = bid; long newVolume; LastVolumes.AddOrUpdate(bid, newVolume = 1, (price, oldVolume) => newVolume = oldVolume + 1); } if (Bidask == VolumeSide.bid && lastAsk != ask && close >= ask) { lastAsk = ask; long newVolume; LastVolumes.AddOrUpdate(ask, newVolume = 1, (price, oldVolume) => newVolume = oldVolume + 1); } } lastMaxIndex = barsUpdate.MaxIndex; if (!clearLoadingSent) { SuperDom.Dispatcher.InvokeAsync(() => SuperDom.ClearLoadingString()); clearLoadingSent = true; } } } }
private void OnBarsUpdate(object sender, BarsUpdateEventArgs e) { if (State == State.Active && SuperDom != null && SuperDom.IsConnected) { if (SuperDom.IsReloading) { OnPropertyChanged(); return; } BarsUpdateEventArgs barsUpdate = e; lock (barsSync) { int currentMaxIndex = barsUpdate.MaxIndex; for (int i = lastMaxIndex + 1; i <= currentMaxIndex; i++) { if (barsUpdate.BarsSeries.GetIsFirstBarOfSession(i)) { // If a new session starts, clear out the old values and start fresh maxVolume = 0; totalBuyVolume = 0; totalLastVolume = 0; totalSellVolume = 0; Sells.Clear(); Buys.Clear(); LastVolumes.Clear(); } double ask = barsUpdate.BarsSeries.GetAsk(i); double bid = barsUpdate.BarsSeries.GetBid(i); double close = barsUpdate.BarsSeries.GetClose(i); long volume = barsUpdate.BarsSeries.GetVolume(i); if (ask != double.MinValue && close >= ask) { Buys.AddOrUpdate(close, volume, (price, oldVolume) => oldVolume + volume); totalBuyVolume += volume; } else if (bid != double.MinValue && close <= bid) { Sells.AddOrUpdate(close, volume, (price, oldVolume) => oldVolume + volume); totalSellVolume += volume; } long newVolume; LastVolumes.AddOrUpdate(close, newVolume = volume, (price, oldVolume) => newVolume = oldVolume + volume); totalLastVolume += volume; if (newVolume > maxVolume) { maxVolume = newVolume; } } lastMaxIndex = barsUpdate.MaxIndex; if (!clearLoadingSent) { SuperDom.Dispatcher.InvokeAsync(() => SuperDom.ClearLoadingString()); clearLoadingSent = true; } } } }