[TABLE]
[TR]
[TD]protected override void OnBarUpdate()
{
if (Bars == null)
return;
// This sample assumes the Volumetric series is the primary DataSeries on the chart, if you would want to add a Volumetric series to a
// script, you could call AddVolumetric() in State.Configure and then for example use
// NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsType barsType = BarsArray[1].BarsType as
// NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsType;
NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsType barsType = Bars.BarsSeries.BarsType as
NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsType;
if (barsType == null)
return;
try
{
double price;
Print("=========================================================================");
Print("Bar: " + CurrentBar);
Print("Trades: " + barsType.Volumes[CurrentBar].Trades);
Print("Total Volume: " + barsType.Volumes[CurrentBar].TotalVolume);
Print("Total Buying Volume: " + barsType.Volumes[CurrentBar].TotalBuyingVolume);
Print("Total Selling Volume: " + barsType.Volumes[CurrentBar].TotalSellingVolume);
Print("Delta for bar: " + barsType.Volumes[CurrentBar].BarDelta);
Print("Delta for bar (%): " + barsType.Volumes[CurrentBar].GetDeltaPercent());
Print("Delta for Close: " + barsType.Volumes[CurrentBar].GetDeltaForPrice(Close[0]));
Print("Ask for Close: " + barsType.Volumes[CurrentBar].GetAskVolumeForPrice(Close[0]));
Print("Bid for Close: " + barsType.Volumes[CurrentBar].GetBidVolumeForPrice(Close[0]));
Print("Volume for Close: " + barsType.Volumes[CurrentBar].GetTotalVolumeForPrice(Close[0]));
Print("Maximum Ask: " + barsType.Volumes[CurrentBar].GetMaximumVolume(true, out price) + " at price: " + price);
Print("Maximum Bid: " + barsType.Volumes[CurrentBar].GetMaximumVolume(false, out price) + " at price: " + price);
Print("Maximum Combined: " + barsType.Volumes[CurrentBar].GetMaximumVolume(null, out price) + " at price: " + price);
Print("Maximum Positive Delta: " + barsType.Volumes[CurrentBar].GetMaximumPositiveDelta());
Print("Maximum Negative Delta: " + barsType.Volumes[CurrentBar].GetMaximumNegativeDelta());
Print("Max seen delta (bar): " + barsType.Volumes[CurrentBar].MaxSeenDelta);
Print("Min seen delta (bar): " + barsType.Volumes[CurrentBar].MinSeenDelta);
Print("Cumulative delta (bar): " + barsType.Volumes[CurrentBar].CumulativeDelta);
}
catch{}
}[/TD]
[/TR]
[/TABLE]
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Get Volume Info from OnMarketData instead.
Collapse
X
-
Get Volume Info from OnMarketData instead.
The code below gets volume info from OnBarUpdate(). The problem with this approach for my strategy is that you get the info after the bar finishes. I'd like to act as soon as i get this info even if the bar hasn't finished. Will it work and be just as reliable in OnMarketData(MarketDataEventArgs marketDataUpdate) function instead?
Code:Tags: None
-
Hello bc24fl,
Thank you for your reply.
I'd suggest if you need these values updated more frequently than at the end of the bar that you either run the strategy to Calculate OnEachTick, or you add a secondary 1 tick data series to your strategy and print this information for the first data series when BarsInProgress = 1 so it updates on each tick.
If you run the Strategy OnBarUpdate without the secondary 1 tick data series, you'd just get the same data in either OnBarUpdate or OnMarketDepth, since those numbers still only update once per bar.
Here's a link to our help guide that goes into how you can set your code up to calculate part every tick and calculate the rest OnBarClose:
Please let us know if we may be of further assistance to you.
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by CarlTrading, 03-31-2026, 09:41 PM
|
1 response
77 views
1 like
|
Last Post
|
||
|
Started by CarlTrading, 04-01-2026, 02:41 AM
|
0 responses
40 views
0 likes
|
Last Post
by CarlTrading
04-01-2026, 02:41 AM
|
||
|
Started by CaptainJack, 03-31-2026, 11:44 PM
|
0 responses
63 views
2 likes
|
Last Post
by CaptainJack
03-31-2026, 11:44 PM
|
||
|
Started by CarlTrading, 03-30-2026, 11:51 AM
|
0 responses
63 views
0 likes
|
Last Post
by CarlTrading
03-30-2026, 11:51 AM
|
||
|
Started by CarlTrading, 03-30-2026, 11:48 AM
|
0 responses
53 views
0 likes
|
Last Post
by CarlTrading
03-30-2026, 11:48 AM
|

Comment