Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

barsType == null

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

    barsType == null

    Hello everyone,
    I'm a beginner when it comes to creating indicators for NT8.

    Unfortunately I have the problem that in the following script
    barsType == null
    and therefore nothing is displayed.

    I downloaded the original script from the support page.

    Can anyone help me with why barsType == null and what I need to do to display the print output of the bars.

    NT v8.1.3.1 64-bit
    NQ 12-24 Tick900
    Playback - mode

    Regards Falke07

    PHP 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;
    #endregion
    
    //This namespace holds Indicators in this folder and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Indicators
    {
        public class BarData : Indicator
        {
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Description                                    = @"Bar Daten";
                    Name                                        = "BarData";
                    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)
                  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);
        
                   Print("Delta Since High (bar): " + barsType.Volumes[CurrentBar].DeltaSh);
        
                   Print("Delta Since Low (bar): " + barsType.Volumes[CurrentBar].DeltaSl);
                }
                catch{}
            }
        }
    }
    
    #region NinjaScript generated code. Neither change nor remove.
    
    namespace NinjaTrader.NinjaScript.Indicators
    {
        public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
        {
            private BarData[] cacheBarData;
            public BarData BarData()
            {
                return BarData(Input);
            }
    
            public BarData BarData(ISeries<double> input)
            {
                if (cacheBarData != null)
                    for (int idx = 0; idx < cacheBarData.Length; idx++)
                        if (cacheBarData[idx] != null &&  cacheBarData[idx].EqualsInput(input))
                            return cacheBarData[idx];
                return CacheIndicator<BarData>(new BarData(), input, ref cacheBarData);
            }
        }
    }
    
    namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
    {
        public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
        {
            public Indicators.BarData BarData()
            {
                return indicator.BarData(Input);
            }
    
            public Indicators.BarData BarData(ISeries<double> input )
            {
                return indicator.BarData(input);
            }
        }
    }
    
    namespace NinjaTrader.NinjaScript.Strategies
    {
        public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
        {
            public Indicators.BarData BarData()
            {
                return indicator.BarData(Input);
            }
    
            public Indicators.BarData BarData(ISeries<double> input )
            {
                return indicator.BarData(input);
            }
        }
    }
    
    #endregion​ 
    

    #2
    Hello Falke07,

    Thank you for your post.

    As noted in the code you posted which is from the Help Guide:

    Code:
    // 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.VolumetricBarsType;
    Your post indicates you are applying this to a 900 tick chart, which is not a Volumetric series. You would either need to apply the script to a chart using Volumetric bars, or use the workaround as indicated in the note to call AddVolumetric().

    https://ninjatrader.com/support/help...volumetric.htm
    Gaby V.NinjaTrader Customer Service

    Comment


      #3
      Hello,

      I've been trying for days to find the right var and am struggling through the description. Unfortunately, I can't find the right ones because I'm still a beginner.

      At the moment I have:
      HTML Code:
      AddVolumetric("NQ 12-24", BarsPeriodType.Range, 1, VolumetricDeltaType.BidAsk, 1);
      I want to use the print version for a Renko 12 chart.

      Can anyone give me a tip on what the var for

      HTML Code:
      AddVolumetric("NQ 12-24", xxxx);
      should be so that I get data (print).

      I would be really grateful.

      Regards

      Falke07​

      Comment


        #4
        Hello Falke,

        That code looks like a valid call to AddVolumetric. When you print from the added series BarsInProgress index are you not getting any values?

        For example, if the added volumetric series is the first added series:

        if (BarsInProgress == 1)
        Print(Times[0][0] + " BIP: " + BarsInProgreess + " Close[0]: " + Close[0]);
        Gaby V.NinjaTrader Customer Service

        Comment


          #5
          Hello Gaby,

          yes, it works with:
          PHP Code:
          Print(Times[0][0] + " BIP: " + BarsInProgress + " Close[0]: " + Close[0]); 
          
          But how do I get the print version to work?

          As a beginner, I simply don't know how to do it.
          It would be enough if I could get two of these values ​​in print. Then the path should be clear.​​

          PHP Code:
          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);
          
          Print("Delta Since High (bar): " + barsType.Volumes[CurrentBar].DeltaSh);
          
          Print("Delta Since Low (bar): " + barsType.Volumes[CurrentBar].DeltaSl);
          }
          catch{} 
          

          Comment


            #6
            Hello,

            If you have already added the Volumetric series, have you also used the code suggested in the Help Guide?

            Code:
            NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsType barsType = BarsArray[1].BarsType as 
            NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsType;
            Gaby V.NinjaTrader Customer Service

            Comment


              #7
              Hello Gaby,

              Unfortunately I rem it while trying so much. Now active with the following code:​

              PHP Code:
              protected override void OnBarUpdate()
                      {
                          if(CurrentBars[0] < 20) return;
                          
                          if(BarsInProgress == 1)
                          {
                              NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsType barsType = BarsArray[1].BarsType as NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsType;
                          
                              Print(Times[0][0] + " BIP: " + BarsInProgress + " Close[0]: " + Close[0]);
                              Print("Total Volume: " + barsType.Volumes[CurrentBar].TotalVolume);
                          }
              }&#8203; 
              
              Unfortunately, the following error message appears in the output monitor

              HTML Code:
              07.11.2024 00:05:48 BIP: 1 Close[0]: 20916,75
              Indicator 'Test001': Error on calling 'OnBarUpdate' method on bar 20: Object reference not set to an instance of an object.​

              Comment


                #8
                Make sure you add a CurrentBars check for all added series.

                Code:
                if(CurrentBars[0] < 20 || CurrentBars[1] < 20) return;
                https://ninjatrader.com/support/help...urrentbars.htm
                Gaby V.NinjaTrader Customer Service

                Comment


                  #9
                  Attached is a sample script.

                  If you need further assistance please let me know.
                  Attached Files
                  Gaby V.NinjaTrader Customer Service

                  Comment


                    #10
                    Hello Gaby,

                    Unfortunately nothing is happening for me. No error message either.
                    I'm attaching a picture.



                    Could it be related to NT? I registered with Ninjatrader and downloaded and installed NT. That's all I did. Do I need an additional license for that?​
                    Attached Files
                    Last edited by Falke07; 11-13-2024, 04:40 AM.

                    Comment


                      #11
                      Hello,

                      Did you purchase the Order Flow+ addon? This needs to be purchased in order to use Volumetric Bars.

                      Gaby V.NinjaTrader Customer Service

                      Comment


                        #12
                        Hello Gaby,

                        OK. Got it so far.
                        Question:
                        Is the second option (Multiple Broker Add-on for Desktop Platform) the live account plan version that includes everything, including Order Flow+ for $99 / month?​

                        Attached Files

                        Comment


                          #13
                          Multi Broker addon does not include Order Flow+. It only allows you to be able to connect in NT with the additional supported brokers listed.
                          Gaby V.NinjaTrader Customer Service

                          Comment


                            #14
                            OK, then either the Order Flow for $59 / month or a one-time purchase for $1499

                            If you buy it once for $1499, does that include Order Flow+?

                            Am I seeing this correctly?​

                            Comment


                              #15
                              If you're referring to the Lifetime Account Plan, yes it comes with OrderFlow+ and is a one-time payment of $1499.
                              Gaby V.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Zek303, 10-20-2024, 06:17 PM
                              4 responses
                              62 views
                              0 likes
                              Last Post bltdavid  
                              Started by jointkp1, Today, 01:11 PM
                              0 responses
                              8 views
                              0 likes
                              Last Post jointkp1  
                              Started by warpinator, Today, 01:01 PM
                              0 responses
                              12 views
                              0 likes
                              Last Post warpinator  
                              Started by C_Hardy, 11-28-2024, 05:44 PM
                              9 responses
                              66 views
                              0 likes
                              Last Post C_Hardy
                              by C_Hardy
                               
                              Started by kellyboy, Today, 11:29 AM
                              0 responses
                              9 views
                              0 likes
                              Last Post kellyboy  
                              Working...
                              X