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

Questions about looping through volumetric bars with a higher ticks per level than 1

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

    Questions about looping through volumetric bars with a higher ticks per level than 1

    Hello, I currently have the following code in my script:

    Code:
    AddVolumetric("NQ 12-15", BarsPeriodType.Minute, 1, VolumetricDeltaType.BidAsk, 4);
    and
    Code:
    double bar_ticks = (Bars.GetHigh(0) - Bars.GetLow(0)) / .25;
    The bar_ticks double is something I assume I will need for this, however if it is not necessary let me know. I would like to loop through the price levels on a bar, however the ways I have seen on previous forum posts have all been per tick. Now, I want the numbers I am getting from these levels to be from all 4 ticks contained in the level, added up. How could I go about looping through the volumetric bar to get the bid and ask volume of each price level (containing 4 ticks) instead of each tick level?

    #2
    Have you taken a look at the example at https://ninjatrader.com/support/help..._highlightsub= volumetric which shows how to retrieve the information specific to volumetric bars?

    Maybe this will get you started:

    Code:
    #region Using declarations
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Gui;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Gui.SuperDom;
    using NinjaTrader.Gui.Tools;
    using NinjaTrader.Data;
    using NinjaTrader.NinjaScript;
    using NinjaTrader.Core.FloatingPoint;
    using NinjaTrader.NinjaScript.DrawingTools;
    using NinjaTrader.NinjaScript.BarsTypes;
    #endregion
    
    //This namespace holds Indicators in this folder and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Indicators
    {
        public class TestVolumetric : Indicator
        {
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Description = @"Enter the description for your new custom Indicator here.";
                    Name = "TestVolumetric";
                    Calculate = Calculate.OnBarClose;
                    IsOverlay = false;
                    DisplayInDataBox = true;
                    DrawOnPricePanel = true;
                    DrawHorizontalGridLines = true;
                    DrawVerticalGridLines = true;
                    PaintPriceMarkers = true;
                    ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                    //Disable this property if your indicator requires custom values that cumulate with each new market data event.
                    //See Help Guide for additional information.
                    IsSuspendedWhileInactive = true;
                }
                else if (State == State.Configure)
                {
                }
            }
    
            protected override void OnBarUpdate()
            {
                if (Bars == null || BarsInProgress != 0 || CurrentBar < 0) 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;
    
                VolumetricBarsType volumetricBarsType = Bars.BarsSeries.BarsType as VolumetricBarsType;
                if (volumetricBarsType == null) return;
    
                VolumetricData currentBarVolumetricData = volumetricBarsType.Volumes[CurrentBar];
    
                try
                {
                    double price;
                    Print("=========================================================================");
                    Print("Bar: " + CurrentBar);
                    Print("Trades: " + currentBarVolumetricData.Trades);
                    Print("Total Volume: " + currentBarVolumetricData.TotalVolume);
                    Print("Total Buying Volume: " + currentBarVolumetricData.TotalBuyingVolume);
                    Print("Total Selling Volume: " + currentBarVolumetricData.TotalSellingVolume);
                    Print("Delta for bar: " + currentBarVolumetricData.BarDelta);
                    Print("Delta for bar (%): " + currentBarVolumetricData.GetDeltaPercent());
                    Print("Delta for Close: " + currentBarVolumetricData.GetDeltaForPrice(Close[0]));
                    Print("Ask for Close: " + currentBarVolumetricData.GetAskVolumeForPrice(Close[0]));
                    Print("Bid for Close: " + currentBarVolumetricData.GetBidVolumeForPrice(Close[0]));
                    Print("Volume for Close: " + currentBarVolumetricData.GetTotalVolumeForPrice(Close[0]));
                    Print("Maximum Ask: " + currentBarVolumetricData.GetMaximumVolume(true, out price) + " at price: " + price);
                    Print("Maximum Bid: " + currentBarVolumetricData.GetMaximumVolume(false, out price) + " at price: " + price);
                    Print("Maximum Combined: " + currentBarVolumetricData.GetMaximumVolume(null, out price) + " at price: " + price);
                    Print("Maximum Positive Delta: " + currentBarVolumetricData.GetMaximumPositiveDelta());
                    Print("Maximum Negative Delta: " + currentBarVolumetricData.GetMaximumNegativeDelta());
                    Print("Max seen delta (bar): " + currentBarVolumetricData.MaxSeenDelta);
                    Print("Min seen delta (bar): " + currentBarVolumetricData.MinSeenDelta);
                    Print("Cumulative delta (bar): " + currentBarVolumetricData.CumulativeDelta);
    
                    Print("Delta Since High (bar): " + currentBarVolumetricData.DeltaSh);
    
                    Print("Delta Since Low (bar): " + currentBarVolumetricData.DeltaSl);
    
                    double low = currentBarVolumetricData.Low;
                    double high = currentBarVolumetricData.High;
                    Print("Low: " + Instrument.MasterInstrument.FormatPrice(low));
                    Print("High: " + Instrument.MasterInstrument.FormatPrice(high));
    
                    long[,] volumes = currentBarVolumetricData.Volumes;
                    for (int i = 0; i < volumes.GetLength(0); i++)
                    {
                        for (int j = 0; j < volumes.GetLength(1); j++)
                        {
                            Print("Volumes[" + i + "," + j + "] = " + volumes[i, j]);
                        }
                    }
                }
                catch
                {
                }
            }
        }
    }
    
    #region NinjaScript generated code. Neither change nor remove.
    
    namespace NinjaTrader.NinjaScript.Indicators
    {
        public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
        {
            private TestVolumetric[] cacheTestVolumetric;
            public TestVolumetric TestVolumetric()
            {
                return TestVolumetric(Input);
            }
    
            public TestVolumetric TestVolumetric(ISeries<double> input)
            {
                if (cacheTestVolumetric != null)
                    for (int idx = 0; idx < cacheTestVolumetric.Length; idx++)
                        if (cacheTestVolumetric[idx] != null &&  cacheTestVolumetric[idx].EqualsInput(input))
                            return cacheTestVolumetric[idx];
                return CacheIndicator<TestVolumetric>(new TestVolumetric(), input, ref cacheTestVolumetric);
            }
        }
    }
    
    namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
    {
        public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
        {
            public Indicators.TestVolumetric TestVolumetric()
            {
                return indicator.TestVolumetric(Input);
            }
    
            public Indicators.TestVolumetric TestVolumetric(ISeries<double> input )
            {
                return indicator.TestVolumetric(input);
            }
        }
    }
    
    namespace NinjaTrader.NinjaScript.Strategies
    {
        public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
        {
            public Indicators.TestVolumetric TestVolumetric()
            {
                return indicator.TestVolumetric(Input);
            }
    
            public Indicators.TestVolumetric TestVolumetric(ISeries<double> input )
            {
                return indicator.TestVolumetric(input);
            }
        }
    }
    
    #endregion
    ​
    Bruce DeVault
    QuantKey Trading Vendor Services
    NinjaTrader Ecosystem Vendor - QuantKey

    Comment


      #3
      Thank you, I will try to figure some things out with this new information. The lines on For Price Volume will help a lot.

      Best regards,

      Ryan Beckmann

      Comment


        #4
        I keep running into an issue where when I try to pull the for price volume, it says it does not exist in the current context. I have a volumetric data series configured in state.configure as well. Any fix for this?

        Comment


          #5
          Hello rbeckmann05,

          Thanks for your notes.

          QuantKey_Bruce has provided some great information on this matter.

          Are you referring to a compile error stating "does not exist in the current context."?

          How are you defining the line of code in your script that is throwing this error?

          To clarify, you have called AddVolumetric() to add a secondary volumetric data series to the script. Is that correct?

          If so, please send us a screenshot of the error message and the line of code the error is referencing so we may accurately assist.
          • To send a screenshot with Windows 10 or newer I would recommend using the Windows Snipping Tool.
          • Alternatively to send a screenshot press Alt + PRINT SCREEN to take a screenshot of the selected window. Then go to Start--> Accessories--> Paint, and press CTRL + V to paste the image. Lastly, save it as a jpeg file and send the file as an attachment.

          Order Flow Volumetric Bars: https://ninjatrader.com/support/help...flow_volumetri c_bars2.htm
          Brandon H.NinjaTrader Customer Service

          Comment


            #6
            Hello Brandon, I was able to figure this issue out, thank you and Mr. Bruce for the help. However, now I am wondering if there is a way to keep a region highlighted until it is tested by price? The region is painted automatically, not drawn manually if that changes anything.

            Comment


              #7
              Hello rbeckmann05,

              Thanks for your notes.

              Are your referring to extending a drawing object until a certain condition occurs?

              To extend a draw object you would need to call the Draw method again, such as Draw.RegionHighlightX(), and pass in the same exact tag name to the Draw method to modify that drawing on the chart.

              From the help guide: "For example, if you pass in a value of "myTag", each time this tag is used, the same draw object is modified. If unique tags are used each time, a new draw object will be created each time."

              RegionHighlightX(): https://ninjatrader.com/support/help...highlightx.htm
              RegionHighlightY(): https://ninjatrader.com/support/help...highlighty.htm
              Brandon H.NinjaTrader Customer Service

              Comment


                #8
                Hi Brandon,

                That makes sense, checked through the docs and it gave me some new ideas. However, I am still having some issues with the code. Is there any way I could send you the code privately and a screen shot of what the chart looks like with my current code? Let me know if there is an easier way for you too, I am fine with whatever works, just would prefer to keep it private.

                Thank you,

                Ryan Beckmann

                Comment


                  #9
                  Hello rbeckmann05,

                  Thanks for your notes.

                  You could write in to support[at]ninjatrader[dot]com with a brief description of your question and attach your exported script and screenshot to your email.

                  One of our Support technicians will be happy to provide you with direction on this matter after reviewing your inquiry.

                  To export the script, go to Tools > Export > NinjaScript AddOn.
                  Brandon H.NinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by llanqui, Today, 03:53 AM
                  0 responses
                  4 views
                  0 likes
                  Last Post llanqui
                  by llanqui
                   
                  Started by burtoninlondon, Today, 12:38 AM
                  0 responses
                  10 views
                  0 likes
                  Last Post burtoninlondon  
                  Started by AaronKoRn, Yesterday, 09:49 PM
                  0 responses
                  14 views
                  0 likes
                  Last Post AaronKoRn  
                  Started by carnitron, Yesterday, 08:42 PM
                  0 responses
                  11 views
                  0 likes
                  Last Post carnitron  
                  Started by strategist007, Yesterday, 07:51 PM
                  0 responses
                  14 views
                  0 likes
                  Last Post strategist007  
                  Working...
                  X