I am trying to code a strategy that would need to use data from the volumetric bars (such as imbalances), but I am unable to find the right code to make the strategy plot the volumetric bars to begin with.
The code below from the help guide doesn't do the job, unfortunately.
Thank you
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.VolumetricBarsTy pe barsType = BarsArray[1].BarsType as
// NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsTy pe;
NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsTy pe barsType = Bars.BarsSeries.BarsType as
NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsTy pe;
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{}
Comment