I am trying to calculate historical ask/bid volume per bar. I can not find the right answer in ninjascript documentation, so I decided to post new thread.
Primary chart 100 ticks
my script:
protected override void Initialize()
{
Add(Instrument.FullName, PeriodType.Tick, 1, MarketDataType.Ask);
Add(Instrument.FullName, PeriodType.Tick, 1, MarketDataType.Bid);
Add(Instrument.FullName, PeriodType.Tick, 1, MarketDataType.Last);
ClearOutputWindow();
CalculateOnBarClose = false;
DisplayInDataBox = false;
}
protected override void OnBarUpdate()
{
// primary data series - chart
if(BarsInProgress == 0)
{
Print("-------");
Print("Chart volume: " + Volume[0]);
Print("Total volume: " + this.totalVolume);
Print("Total ask: " + this.askVolume);
Print("Total bid: " + this.bidVolume);
this.askVolume = 0;
this.bidVolume = 0;
this.totalVolume = 0;
}
// new data series
if(BarsInProgress == 1) this.askVolume += (int)Volumes[1][0];
if(BarsInProgress == 2) this.bidVolume += (int)Volumes[2][0];
if(BarsInProgress == 3) this.totalVolume += (int)Volumes[3][0];
}
Output:
-------
Chart volume: 225
Total volume: 231
Total ask: 1897
Total bid: 3479
-------
Chart volume: 210
Total volume: 189
Total ask: 1629
Total bid: 2818
-------
Chart volume: 196
Total volume: 207
Total ask: 2104
Total bid: 2263
As you see in output,
"Chart volume" is correct value which is displayed on chart
"Total volume" is close to primary volume, but not exact the same, but bid and ask volume is totally different values.
Could anybody help me with this, please?
Comment