Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to print bar delta

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

    How to print bar delta

    Hi,
    Given the following:


    else if (State == State.Configure)
    {
    AddVolumetric("ES 12-22", BarsPeriodType.Minute, 30, VolumetricDeltaType.BidAsk, 1);
    }
    }

    protected override void OnBarUpdate()
    {
    if (BarsInProgress != 0)
    return;

    if (CurrentBars[0] < 1)
    return;

    // Set 1
    if (Close[0] < Open[0])
    {
    Draw.Dot(this, @"Dot_1 " + Convert.ToString(CurrentBars[0]), false, 0, (Low[0] - 3) , Brushes.CornflowerBlue);
    //How Print the delta of the bar??
    }

    What line would I need to write in Set 1 to print the delta of the bar? The example in the documentation says the following, but unfortunately it is confusing/goes over my head:

    ​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{}
    }
    ​

    #2
    In the Ninjascript, give this a try:

    Code:
    else if (State == State.Configure)
    {
    AddVolumetric("ES 12-22", BarsPeriodType.Minute, 30, VolumetricDeltaType.BidAsk, 1);
    }
    }
    
    protected override void OnBarUpdate()
    {​
    
    if (BarsInProgress != 0)
    return;
    
    if (CurrentBars[0] < 1)
    return;
    
    if (Bars == null)
    return;​
    
    NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsType barsType = BarsArray[1].BarsType as NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsType; // using the added volumetric series!!​
    
    if (barsType == null)
    return;​
    
    // Set 1
    if (Close[0] < Open[0])
    {
    Draw.Dot(this, @"Dot_1 " + Convert.ToString(CurrentBars[0]), false, 0, (Low[0] - 3) , Brushes.CornflowerBlue);
    Print("Delta for bar: " + barsType.Volumes[CurrentBar].BarDelta);
    }​

    Comment


      #3
      Hi, thanks, Tasker! It works if I omit both of the:

      if (barsType == null)
      return;

      they throw errors up for some reason. Much appreciated!​

      Comment


        #4
        Hello trader3000a,

        Thanks for your note.

        Tasker-182 is correct. You could use barsType.Volumes[CurrentBar].BarDelta to get the BarDelta value from Order Flow Volumetric Bars.

        See this help guide page for more information and sample code: https://ninjatrader.com/support/help...htsub=bardelta

        Let me know if I may assist further.
        <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by ChrisR, Today, 12:04 PM
        0 responses
        4 views
        0 likes
        Last Post ChrisR
        by ChrisR
         
        Started by vitaly_p, Today, 11:21 AM
        3 responses
        7 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by Merlin997, Today, 11:44 AM
        0 responses
        1 view
        0 likes
        Last Post Merlin997  
        Started by Thomas75k, 11-29-2024, 02:11 AM
        9 responses
        78 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by NISNOS69, Yesterday, 08:00 AM
        3 responses
        13 views
        0 likes
        Last Post NISNOS69  
        Working...
        X