[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 NullPointStrategies, Today, 05:17 AM
|
0 responses
52 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
130 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
70 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
44 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
48 views
0 likes
|
Last Post
|

Comment