Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Get Volume Info from OnMarketData instead.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    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:
    [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]

    #2
    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.
    Kate W.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Kaledus, Today, 01:29 PM
    3 responses
    9 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Started by frankthearm, Yesterday, 09:08 AM
    14 responses
    47 views
    0 likes
    Last Post NinjaTrader_Clayton  
    Started by gentlebenthebear, Today, 01:30 AM
    2 responses
    13 views
    0 likes
    Last Post gentlebenthebear  
    Started by PaulMohn, Today, 12:36 PM
    2 responses
    17 views
    0 likes
    Last Post PaulMohn  
    Started by Conceptzx, 10-11-2022, 06:38 AM
    2 responses
    56 views
    0 likes
    Last Post PhillT
    by PhillT
     
    Working...
    X