﻿ NinjaScript > Language Reference > Common > System Indicator Methods > Order Flow Volumetric Bars

Order Flow Volumetric Bars

 Navigation:  NinjaScript > Language Reference > Common > System Indicator Methods > Order Flow Volumetric Bars   ## Description

NinjaTrader Order Flow Volumetric bars provide a detailed ‘x-ray’ view into each price bar’s aggressive buying and selling activity. This technique primarily attempts to answer the question which side was the most aggressive at each price level. This is done by calculating the delta (greek for difference) between buying and selling volume.

Many of the NinjaTrader Order Flow Volumetric Bar and Bar Statistics values could be accessed from your custom NinjaScript objects further leveraging the power of these analysis techniques.

## Methods and Properties the VolumetricBarsType exposes

 BarDelta Gets a long value with the total bar's delta CumulativeDelta Gets a long value with the cumulative delta (Note: the accumulation is reset at the session break) GetAskVolumeForPrice(double price) Gets the ask volume (long value) for the passed in price GetBidVolumeForPrice(double price) Gets the sell volume (long value) for the passed in price GetDeltaForPrice(double price) Gets the horizontal delta (long value) for the passed in price GetDeltaPercent() Gets a double value with the delta % of volume for the bar GetMaximumPositiveDelta() Gets the highest positive delta (long value) for the bar (if there is no positive delta in the bar, it will get the lowest negative delta) GetMaximumNegativeDelta() Gets the highest negative delta (long value) for the bar (if there is no negative delta in the bar, it will get the lowest positive delta) GetMaximumVolume(bool? askVolume, out double price) Gets the highest Ask, Bid or combined volume (long value) for the bar and returns the price at which it occurred.   - pass in true for getting the highest Ask volume - pass in false for getting the highest Bid volume - pass in null for getting the highest combined volume   For scenarios where Ticks per level is greater than 1, this method will return the lowest price - with Ticks per level known, the remaining prices in the result cell could be custom calculated if desired. GetTotalVolumeForPrice(double price) Gets the total volume (long value) for the passed in price MaxSeenDelta Gets the highest delta (long value) seen intrabar MinSeenDelta Gets the lowest delta (long value) seen intrabar TotalBuyingVolume Gets the total buying volume (long value) for the bar TotalSellingVolume Gets the total selling volume (long value) for the bar Trades Gets to total number of trades (long value) for the bar

## 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.BarsType as

if (barsType == null)
return;

try
{
double price;
Print("=========================================================================");
Print("Bar: " + CurrentBar);
Print("Total Volume: " + barsType.Volumes[CurrentBar].TotalVolume);
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));
Print("Bid for Close: " + barsType.Volumes[CurrentBar].GetBidVolumeForPrice(Close));
Print("Volume for Close: " + barsType.Volumes[CurrentBar].GetTotalVolumeForPrice(Close));
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{}
}

 Note: Please note in the example above a CurrentBar reference is used as index, and not a BarsAgo reference.