I try to write a very simple indicator based on MarketDataType.Last event but I have noticed that a cumulative volume on specific bar based on last traded price is different than VOL value. Let's take a look on example:
Here is a simple code:
if(e.MarketDataType == MarketDataType.Last)
{
sumvol += e.Volume;
Print("CurrentBar =" + (CurrentBar+1).ToString() + " " + "SumVol = " + sumvol.ToString());
}
}
protected override void OnBarUpdate()
{
if(IsFirstTickOfBar)
{
sumvol = 0;
}
}
On 5 minutes chart it looks following:
CurrentBar =4085 SumVol = 533
CurrentBar =4085 SumVol = 534
CurrentBar =4085 SumVol = 535
CurrentBar =4086 SumVol = 1
CurrentBar =4086 SumVol = 2
CurrentBar =4086 SumVol = 3
CurrentBar =4086 SumVol = 5
There is a difference between the VOL which is 569 and the real time cumulative volume which is 535. When the new bar is created suddenly I observe missing volume. Please take a look on the screen.
Furthermore, when bar is closed and I update/refresh a chart the value calculated from historical data is correct.
CurrentBar =4085 SumVol = 563
CurrentBar =4085 SumVol = 564
CurrentBar =4085 SumVol = 565
CurrentBar =4085 SumVol = 566
CurrentBar =4085 SumVol = 567
CurrentBar =4085 SumVol = 568
CurrentBar =4085 SumVol = 569
CurrentBar =4086 SumVol = 1
CurrentBar =4086 SumVol = 2
CurrentBar =4086 SumVol = 3
CurrentBar =4086 SumVol = 5
CurrentBar =4086 SumVol = 6
CurrentBar =4086 SumVol = 7
CurrentBar =4086 SumVol = 8
CurrentBar =4086 SumVol = 9
Could someone explain me why it happens?
Comment