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

How to Add A New Instrument Series without the Expiry date?

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

    How to Add A New Instrument Series without the Expiry date?

    I'm trying to add a new instrument series with AddDataSeries()

    I see on the example page we specify the expiration date as for example "ES 09-16"
    PHP Code:
    protected override void OnStateChange()
    {
       if (
    State == State.Configure)
       {
           
    // Add a 5 minute Bars object - BarsInProgress index = 1
           
    AddDataSeries(BarsPeriodType.Minute5);

           
    // Add a 100 tick Bars object for the ES 09-16 contract - BarsInProgress index = 2
           
    AddDataSeries("ES 09-16"BarsPeriodType.Tick100);
       }


    Is it possible to specify the Instrument symbol only for example "ES" instead of "ES 09-16"?

    My purpose is to always get the latest expiry for the instrument by default, so I don't have to manually update the expiry every quarter/month/expiry. Thanks!

    #2
    Hi Paul, thanks for writing in.

    You will need to use the continuous contract (only if your data feed supports it, Kinetick supports continuous contracts but NinjaTrader Continuum does not). You can test your connection by pulling up ES ##-## on a chart or doing AddDataSeries("ES ##-##", BarsPeriodType.Tick, 100);

    Kind regards,
    -ChrisL
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Hello Chris and thanks for the direction. I'm getting this error

      Time Category Message
      24/03/2022 17:27:00 Default Error on requesting bars series: 'IB was unable to locate instrument. Please verify your symbol mapping is correct for instrument GC ##-## Nymex'

      my shortened/relevant script
      PHP Code:
      namespace NinjaTrader.NinjaScript.Indicators
      {
        public class 
      Testea Indicator
        
      {

          private 
      Series<doubleRangeTopRangeBottomRangeTopRangeBottom;

          private 
      Series<doubleGCSeries;


        protected 
      override void OnStateChange()
          {
            if (
      State == State.SetDefaults)
            {
            }        
            else if (
      State == State.Configure)
            {
              
      AddDataSeries("GC ##-##"BarsPeriodType.Day1);
            }
            else if (
      State == State.DataLoaded)
            {

              
      RangeTop = new Series<double>(thisMaximumBarsLookBack.Infinite);
              
      RangeBottom = new Series<double>(thisMaximumBarsLookBack.Infinite);
              
      RangeTopRangeBottom = new Series<double>(thisMaximumBarsLookBack.Infinite);


              
      GCSeries = new Series<double>(thisMaximumBarsLookBack.Infinite);
            }
          }


          protected 
      override void OnBarUpdate()
          {

            
      RangeTop[0] = High[0];
            
      RangeBottom[0] = Low[0];
            
      RangeTopRangeBottom[0] = High[0] - Low[0];


            if (
      BarsInProgress == 1)
            {

              
      GCSeries[0] = Highs[1][0]-Lows[1][0];

              Print(
      "GCSeries" GCSeries);

              
      Draw.TextFixed(
                
      this,
                
      "GCSeries",
                
      "Test "+GCSeries.ToString(),
                
      TextPosition.TopRight,
                
      Brushes.White,
                
      myFont,
                
      Brushes.Transparent,
                
      Brushes.Transparent,
                
      0);

            } 

      As you can see I have 3 same instrument as the one on the chart (CL 1min) Series<double>
      RangeTop, RangeBottom, RangeTopRangeBottom,
      and one extra instrument (GC Daily) Series<double> GCSeries.

      I basically need to display the value of
      PHP Code:
              GCSeries[0] = Highs[1][0]-Lows[1][0]; 

      on the TopRight position with Draw.TextFixed on the chart.

      I've added AddDataSeries("GC ##-##", BarsPeriodType.Day, 1); to the State.Configure scope,
      and
      GCSeries = new Series<double>(this, MaximumBarsLookBack.Infinite); to the State.DataLoaded scope.


      I've used
      if (BarsInProgress == 1)
      {
      }
      to encapsulate the code, but i'm not sure 1 is the correct BarsInProgress for GCSeries[0]/GCSeries/private Series<double> GCSeries; .

      How can I know for sure what the correct BarsInProgress is?

      Currently I think the BarsInProgress are
      BarsInProgress = 0 = the CL 1 min / Main Chart series
      BarsInProgress = 1 = GC ##-## / Gold Continuous Daily (1 day) series

      But since I have other same instrument series I'm wondering if it would instead be

      BarsInProgress = 0 = the CL 1 min / Main Chart series
      BarsInProgress = 1 = the CL 1 min RangeTop[0] = High[0];
      BarsInProgress = 2 = the CL 1 min RangeBottom[0] = Low[0];
      BarsInProgress = 3 = the CL 1 min RangeTopRangeBottom[0] = High[0] - Low[0];
      BarsInProgress = 4 = GC ##-## / Gold Continuous Daily (1 day) series

      Is the 1st or the 2nd set the right one? Or is it different? What simple way would you employ to check? Thanks!



      Doc and Thread references
      Adding multiple data-series & perform multiple operation on these

      Working with Multiple DataSeries

      Multi-Time Frame & Instruments

      PHP Code:
      // Declare two Series objects
      private Series<doubleprimarySeries;
      private 
      Series<doublesecondarySeries;

      protected 
      override void OnStateChange()
      {
          if (
      State == State.Configure)
        {
            
      // Adds a secondary bar object to the strategy.
            
      AddDataSeries(BarsPeriodType.Minute5);
        }
        else if (
      State == State.DataLoaded)
        {
            
      // Syncs a Series object to the primary bar object
            
      primarySeries = new Series<double>(this);

            
      /* Syncs another Series object to the secondary bar object.
             We use an arbitrary indicator overloaded with an ISeries<double> input to achieve the sync.
             The indicator can be any indicator. The Series<double> will be synced to whatever the
             BarsArray[] is provided.*/
            
      secondarySeries = new Series<double>(SMA(BarsArr ay[1], 50));

            
      // Stop-loss orders are placed 5 ticks below average entry price
            
      SetStopLoss(CalculationMode.Ticks5);

            
      // Profit target orders are placed 10 ticks above average entry price
            
      SetProfitTarget(CalculationMode.Ticks10);
        }


      AddDataSeries()

      Comment


        #4
        Chris, I've tested with "GC 04-22" as

        PHP Code:
        else if (State == State.Configure)
        {
             
        AddDataSeries("GC 04-22"BarsPeriodType.Day1);


        and it removes the error.
        But how to do it with the continuous or otherwise with IB connection?


        I've also then tested with

        BarsInProgress = 0 , returns an indexing error.

        BarsInProgress = 1/2/3/4 works without error, but nothing is displayed on the TopRight corner of the chart.

        Which BarsInProgress is the right one?
        What process/checking practice can you advise to make sure I can verify what BarsInProgress to use for future uses? Thanks!
        Last edited by PaulMohn; 03-24-2022, 01:38 PM.

        Comment


          #5
          Hi Paul, Interactive Brokers does not support the continuous contract through the NinjaTrader connection. You will need to use the current contract in AddDataSeries.

          The BarsInProgress goes in the order you call AddDataSeries. When BarsInProgress = 0 OnBarUpdate is being called for the primary series. When BarsInProgress = 1 OnBarUpdate is being called for the first series added with AddDataSeries and so on. The specific bar type can be printed through Print(BarsArray[BarsInProgress].BarsPeriod); To display the daily value do something similar to :

          Code:
          private double savedValue;
          OnBarUpdate()
          {
              if(BarsInProgress == 0)
              {
                   //Draw savedValue to Text here
              }
              if(BarsInProgress == 1)
              {
                  savedValue = Highs[1][0]-Lows[1][0];
              }
          }
          The linked series is not needed, but to link a Series<double> object to your secondary series:

          Code:
          //class level
          private Series<double> _series;
          
          //in OnStateChanged
          else if(State == State.DataLoaded)
          {
              _series = new Series<double>(BarsArray[1], MaximumBarsLookBack.Infinite); //will have a slot index for every bar of the secondary series.
          }
          Chris L.NinjaTrader Customer Service

          Comment


            #6
            Hi Chris, thanks for the reply.

            Interactive Brokers does not support the continuous contract through the NinjaTrader connection. You will need to use the current contract in AddDataSeries.
            What alternative can you suggest to the continuous contract? It would be very tedious and human error prone having to manually update every expiry for many added series every quarter/month/expiry.

            Isn't there something like a string function that can detect the current date and compare it to the contract next expiry and automatically assign the next expiry if the current date falls within the next expiry?

            I mean something like

            PHP Code:
            ExpiryFunction()
            {
               if(
            DateTime.Now.ToString() > PreviousExpiry && DateTime.Now.ToString() < NextExpiry)
               {
                  
            string instrumentExpiry NextExpiry;
               }
            }

            else if (
            State == State.Configure)
            {
               
            AddDataSeries("GC "+ExpiryFunctionBarsPeriodType.Day1);


            Or something better/simpler?


            The BarsInProgress goes in the order you call AddDataSeries. When BarsInProgress = 0 OnBarUpdate is being called for the primary series. When BarsInProgress = 1 OnBarUpdate is being called for the first series added with AddDataSeries and so on. The specific bar type can be printed through Print(BarsArray[BarsInProgress].BarsPeriod); To display the daily value do something similar to
            Ok thanks for the description. I have only one AddDataSeries (the GC one). So is the BarsInProgress = 1 the correct one for my AddDataSeries (GC series)?
            I ask again because it is confusing to know with other "non AddDataSeries" series added, and there's no explanation/example of this case in the documentation. Thanks!
            Last edited by PaulMohn; 03-24-2022, 02:23 PM.

            Comment


              #7
              Hi Paul, thanks for your reply. There is instrument information available through the MasterInstrument class:



              You would need to develop a database that will store the next contract to use in and use that contract in your calls to AddDataSeries.

              The GC instrument is the BarsInProgress = 1 bar context. That can be tested with Print(BarsArray[1].Instrument);

              Kind regards,
              -ChrisL

              Chris L.NinjaTrader Customer Service

              Comment


                #8
                Hi Chris thanks for the reply.

                Ok for the Database solution. Don't you already have some code I could adapt to the situation? It seems a feature that should be native to NT8 rather than the current harcoded only string expiry option. Thanks!

                I've tested the following attached script but nothing displays in the TopRight chart corner (the indicator is loaded on a CL 05-22 1 min chart).
                (i generated the template with the Indicator Wizard first then modified accordingly).
                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 
                DailyRanges Indicator
                  
                {
                    private 
                Series<doubleGCSeries;

                    protected 
                override void OnStateChange()
                    {
                      if (
                State == State.SetDefaults)
                      {
                        
                Description                 = @"Enter the description for your new custom Indicator here.";
                        
                Name                     "DailyRanges";
                        
                Calculate                 Calculate.OnBarClose;
                        
                IsOverlay                 true;
                        
                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)
                      {
                        
                AddDataSeries("GC 04-22"Data.BarsPeriodType.Day1Data.MarketDataType.Last);
                      }
                    }

                    protected 
                override void OnBarUpdate()
                    {

                      if (
                CurrentBar 55) return;


                      
                NinjaTrader.Gui.Tools.SimpleFont myFont = new NinjaTrader.Gui.Tools.SimpleFont("Courier New"12) { Size 12Bold true };

                      if (
                BarsInProgress == 0)
                      {
                        
                //DoX;
                      
                }

                      if (
                BarsInProgress == 1)
                      {

                        
                GCSeries[0] = Highs[1][0]-Lows[1][0];

                        Print(
                "GCSeries" GCSeries);

                        
                Draw.TextFixed(
                          
                this,
                          
                "GCSeries",
                          
                "Test "+GCSeries.ToString(),
                          
                TextPosition.TopRight,
                          
                Brushes.White,
                          
                myFont,
                          
                Brushes.Transparent,
                          
                Brushes.Transparent,
                          
                0);

                      }
                    }
                  }
                }

                #region NinjaScript generated code. Neither change nor remove.

                namespace NinjaTrader.NinjaScript.Indicators
                {
                  public 
                partial class Indicator NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
                  
                {
                    private 
                DailyRanges[] cacheDailyRanges;
                    public 
                DailyRanges DailyRanges()
                    {
                      return 
                DailyRanges(Input);
                    }

                    public 
                DailyRanges DailyRanges(ISeries<doubleinput)
                    {
                      if (
                cacheDailyRanges != null)
                        for (
                int idx 0idx cacheDailyRanges.Lengthidx++)
                          if (
                cacheDailyRanges[idx] != null && cacheDailyRanges[idx].EqualsInput(input))
                            return 
                cacheDailyRanges[idx];
                      return 
                CacheIndicator<DailyRanges>(new DailyRanges(), inputref cacheDailyRanges);
                    }
                  }
                }

                namespace 
                NinjaTrader.NinjaScript.MarketAnalyzerColumns
                {
                  public 
                partial class MarketAnalyzerColumn MarketAnalyzerColumnBase
                  
                {
                    public 
                Indicators.DailyRanges DailyRanges()
                    {
                      return 
                indicator.DailyRanges(Input);
                    }

                    public 
                Indicators.DailyRanges DailyRanges(ISeries<doubleinput )
                    {
                      return 
                indicator.DailyRanges(input);
                    }
                  }
                }

                namespace 
                NinjaTrader.NinjaScript.Strategies
                {
                  public 
                partial class Strategy NinjaTrader.Gui.NinjaScript.StrategyRenderBase
                  
                {
                    public 
                Indicators.DailyRanges DailyRanges()
                    {
                      return 
                indicator.DailyRanges(Input);
                    }

                    public 
                Indicators.DailyRanges DailyRanges(ISeries<doubleinput )
                    {
                      return 
                indicator.DailyRanges(input);
                    }
                  }
                }

                #endregion 

                What's wrong with the script? Does it work on your end as is? Thanks!


                I just tested removing the wizard auto-generated data. / Data.MarketDataType.Last etc. and it still return no display

                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 
                DailyRanges Indicator
                  
                {
                    private 
                Series<doubleGCSeries;

                    protected 
                override void OnStateChange()
                    {
                      if (
                State == State.SetDefaults)
                      {
                        
                Description                 = @"Enter the description for your new custom Indicator here.";
                        
                Name                     "DailyRanges";
                        
                Calculate                 Calculate.OnBarClose;
                        
                IsOverlay                 true;
                        
                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)
                      {
                        
                AddDataSeries("GC 04-22"BarsPeriodType.Day1);
                      }
                    }

                    protected 
                override void OnBarUpdate()
                    {

                      if (
                CurrentBar 55) return;


                      
                NinjaTrader.Gui.Tools.SimpleFont myFont = new NinjaTrader.Gui.Tools.SimpleFont("Courier New"12) { Size 12Bold true };

                      if (
                BarsInProgress == 0)
                      {
                        
                //DoX;
                      
                }

                      if (
                BarsInProgress == 1)
                      {

                        
                GCSeries[0] = Highs[1][0]-Lows[1][0];

                        Print(
                "GCSeries" GCSeries);

                        
                Draw.TextFixed(
                          
                this,
                          
                "GCSeries",
                          
                "Test "+GCSeries.ToString(),
                          
                TextPosition.TopRight,
                          
                Brushes.White,
                          
                myFont,
                          
                Brushes.Transparent,
                          
                Brushes.Transparent,
                          
                0);

                      }
                    }
                  }
                }

                #region NinjaScript generated code. Neither change nor remove.

                namespace NinjaTrader.NinjaScript.Indicators
                {
                  public 
                partial class Indicator NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
                  
                {
                    private 
                DailyRanges[] cacheDailyRanges;
                    public 
                DailyRanges DailyRanges()
                    {
                      return 
                DailyRanges(Input);
                    }

                    public 
                DailyRanges DailyRanges(ISeries<doubleinput)
                    {
                      if (
                cacheDailyRanges != null)
                        for (
                int idx 0idx cacheDailyRanges.Lengthidx++)
                          if (
                cacheDailyRanges[idx] != null && cacheDailyRanges[idx].EqualsInput(input))
                            return 
                cacheDailyRanges[idx];
                      return 
                CacheIndicator<DailyRanges>(new DailyRanges(), inputref cacheDailyRanges);
                    }
                  }
                }

                namespace 
                NinjaTrader.NinjaScript.MarketAnalyzerColumns
                {
                  public 
                partial class MarketAnalyzerColumn MarketAnalyzerColumnBase
                  
                {
                    public 
                Indicators.DailyRanges DailyRanges()
                    {
                      return 
                indicator.DailyRanges(Input);
                    }

                    public 
                Indicators.DailyRanges DailyRanges(ISeries<doubleinput )
                    {
                      return 
                indicator.DailyRanges(input);
                    }
                  }
                }

                namespace 
                NinjaTrader.NinjaScript.Strategies
                {
                  public 
                partial class Strategy NinjaTrader.Gui.NinjaScript.StrategyRenderBase
                  
                {
                    public 
                Indicators.DailyRanges DailyRanges()
                    {
                      return 
                indicator.DailyRanges(Input);
                    }

                    public 
                Indicators.DailyRanges DailyRanges(ISeries<doubleinput )
                    {
                      return 
                indicator.DailyRanges(input);
                    }
                  }
                }

                #endregion 
                Attached Files
                Last edited by PaulMohn; 03-24-2022, 03:31 PM.

                Comment


                  #9
                  Hi Paul, I do not have any example of a dynamicly switching contract name in the AddDataSeries, it will need to be made custom. Script you are showing here should draw the text within
                  if (BarsInProgress == 0)
                  {
                  //DoX;
                  }

                  So that you can reference the visible bars on the chart.

                  Kind regards.
                  -ChrisL
                  Chris L.NinjaTrader Customer Service

                  Comment


                    #10


                    I just tested with the prints outside the barsInProgress = 1 Scope as

                    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 
                    DailyRanges Indicator
                      
                    {
                        private 
                    Series<doubleGCSeries;

                        protected 
                    override void OnStateChange()
                        {
                          if (
                    State == State.SetDefaults)
                          {
                            
                    Description                 = @"Enter the description for your new custom Indicator here.";
                            
                    Name                     "DailyRanges";
                            
                    Calculate                 Calculate.OnBarClose;
                            
                    IsOverlay                 true;
                            
                    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)
                          {
                            
                    AddDataSeries("GC 04-22"BarsPeriodType.Day1);
                          }
                        }

                        protected 
                    override void OnBarUpdate()
                        {

                          if (
                    CurrentBar 55) return;


                          
                    NinjaTrader.Gui.Tools.SimpleFont myFont = new NinjaTrader.Gui.Tools.SimpleFont("Courier New"12) { Size 12Bold true };

                          if (
                    BarsInProgress == 0)
                          {
                            
                    //DoX;
                          
                    }

                          if (
                    BarsInProgress == 1)
                          {

                            
                    GCSeries[0] = Highs[1][0]-Lows[1][0];

                            Print(
                    "GCSeries" GCSeries);

                            
                    Draw.TextFixed(
                              
                    this,
                              
                    "GCSeries",
                              
                    "Test "+GCSeries.ToString(),
                              
                    TextPosition.TopRight,
                              
                    Brushes.White,
                              
                    myFont,
                              
                    Brushes.Transparent,
                              
                    Brushes.Transparent,
                              
                    0);

                          }



                            Print(
                    "GCSeries " GCSeries "Time[0] " Time[0]);
                        }
                      }
                    }

                    #region NinjaScript generated code. Neither change nor remove.

                    namespace NinjaTrader.NinjaScript.Indicators
                    {
                      public 
                    partial class Indicator NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
                      
                    {
                        private 
                    DailyRanges[] cacheDailyRanges;
                        public 
                    DailyRanges DailyRanges()
                        {
                          return 
                    DailyRanges(Input);
                        }

                        public 
                    DailyRanges DailyRanges(ISeries<doubleinput)
                        {
                          if (
                    cacheDailyRanges != null)
                            for (
                    int idx 0idx cacheDailyRanges.Lengthidx++)
                              if (
                    cacheDailyRanges[idx] != null && cacheDailyRanges[idx].EqualsInput(input))
                                return 
                    cacheDailyRanges[idx];
                          return 
                    CacheIndicator<DailyRanges>(new DailyRanges(), inputref cacheDailyRanges);
                        }
                      }
                    }

                    namespace 
                    NinjaTrader.NinjaScript.MarketAnalyzerColumns
                    {
                      public 
                    partial class MarketAnalyzerColumn MarketAnalyzerColumnBase
                      
                    {
                        public 
                    Indicators.DailyRanges DailyRanges()
                        {
                          return 
                    indicator.DailyRanges(Input);
                        }

                        public 
                    Indicators.DailyRanges DailyRanges(ISeries<doubleinput )
                        {
                          return 
                    indicator.DailyRanges(input);
                        }
                      }
                    }

                    namespace 
                    NinjaTrader.NinjaScript.Strategies
                    {
                      public 
                    partial class Strategy NinjaTrader.Gui.NinjaScript.StrategyRenderBase
                      
                    {
                        public 
                    Indicators.DailyRanges DailyRanges()
                        {
                          return 
                    indicator.DailyRanges(Input);
                        }

                        public 
                    Indicators.DailyRanges DailyRanges(ISeries<doubleinput )
                        {
                          return 
                    indicator.DailyRanges(input);
                        }
                      }
                    }

                    #endregion 

                    but it only prints the label (not the value in Print("GCSeries " + GCSeries + "Time[0] " + Time[0]); )

                    GCSeries Time[0] 24/03/2022 21:47:00
                    GCSeries Time[0] 24/03/2022 21:48:00
                    GCSeries Time[0] 24/03/2022 21:49:00
                    GCSeries Time[0] 24/03/2022 21:50:00
                    GCSeries Time[0] 24/03/2022 21:51:00
                    GCSeries Time[0] 24/03/2022 21:52:00
                    GCSeries Time[0] 24/03/2022 21:53:00
                    GCSeries Time[0] 24/03/2022 21:54:00
                    GCSeries Time[0] 24/03/2022 21:55:00
                    GCSeries Time[0] 24/03/2022 21:56:00
                    GCSeries Time[0] 24/03/2022 21:57:00
                    GCSeries Time[0] 24/03/2022 21:58:00
                    GCSeries Time[0] 24/03/2022 21:59:00

                    Comment


                      #11
                      Hi Paul, There is still no code within the BarsInProgress = 0 filter of this script. That is where all the drawing should go.

                      Kind regards.
                      -ChrisL
                      Chris L.NinjaTrader Customer Service

                      Comment


                        #12
                        Hi Paul, I do not have any example of a dynamicly switching contract name in the AddDataSeries, it will need to be made custom.
                        Please add a request feature, that should be native to NT8 and not custom/only for Kinetick subscribers considering the Multi-Brokers license owners. Thanks!

                        Script you are showing here should draw the text within
                        Why? it seems to contradict the BarsInProgress logic. Please explain thoroughly as the documentation is lacking in this regard.

                        I tested the following 2 scripts and it still doesn't display/print anything

                        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 
                        DailyRanges Indicator
                          
                        {
                            private 
                        Series<doubleGCSeries;

                            protected 
                        override void OnStateChange()
                            {
                              if (
                        State == State.SetDefaults)
                              {
                                
                        Description                 = @"Enter the description for your new custom Indicator here.";
                                
                        Name                     "DailyRanges";
                                
                        Calculate                 Calculate.OnBarClose;
                                
                        IsOverlay                 true;
                                
                        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)
                              {
                                
                        AddDataSeries("GC 04-22"BarsPeriodType.Day1);
                              }
                            }

                            protected 
                        override void OnBarUpdate()
                            {

                              if (
                        CurrentBars[0] < 55 || CurrentBars[1] < 55) return;


                              
                        NinjaTrader.Gui.Tools.SimpleFont myFont = new NinjaTrader.Gui.Tools.SimpleFont("Courier New"12) { Size 12Bold true };

                              if (
                        BarsInProgress == 0)
                              {
                                
                        GCSeries[0] = Highs[1][0]-Lows[1][0];

                                Print(
                        "GCSeries" GCSeries);

                                
                        Draw.TextFixed(
                                  
                        this,
                                  
                        "GCSeries",
                                  
                        "Test "+GCSeries.ToString(),
                                  
                        TextPosition.TopRight,
                                  
                        Brushes.White,
                                  
                        myFont,
                                  
                        Brushes.Transparent,
                                  
                        Brushes.Transparent,
                                  
                        0);
                              }

                              if (
                        BarsInProgress == 1)
                              {

                        //       GCSeries[0] = Highs[1][0]-Lows[1][0];

                        //       Print("GCSeries" + GCSeries);

                        //       Draw.TextFixed(
                        //         this,
                        //         "GCSeries",
                        //         "Test "+GCSeries.ToString(),
                        //         TextPosition.TopRight,
                        //         Brushes.White,
                        //         myFont,
                        //         Brushes.Transparent,
                        //         Brushes.Transparent,
                        //         0);

                              
                        }



                                Print(
                        "GCSeries " GCSeries "Time[0] " Time[0]);
                            }
                          }
                        }

                        #region NinjaScript generated code. Neither change nor remove.

                        namespace NinjaTrader.NinjaScript.Indicators
                        {
                          public 
                        partial class Indicator NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
                          
                        {
                            private 
                        DailyRanges[] cacheDailyRanges;
                            public 
                        DailyRanges DailyRanges()
                            {
                              return 
                        DailyRanges(Input);
                            }

                            public 
                        DailyRanges DailyRanges(ISeries<doubleinput)
                            {
                              if (
                        cacheDailyRanges != null)
                                for (
                        int idx 0idx cacheDailyRanges.Lengthidx++)
                                  if (
                        cacheDailyRanges[idx] != null && cacheDailyRanges[idx].EqualsInput(input))
                                    return 
                        cacheDailyRanges[idx];
                              return 
                        CacheIndicator<DailyRanges>(new DailyRanges(), inputref cacheDailyRanges);
                            }
                          }
                        }

                        namespace 
                        NinjaTrader.NinjaScript.MarketAnalyzerColumns
                        {
                          public 
                        partial class MarketAnalyzerColumn MarketAnalyzerColumnBase
                          
                        {
                            public 
                        Indicators.DailyRanges DailyRanges()
                            {
                              return 
                        indicator.DailyRanges(Input);
                            }

                            public 
                        Indicators.DailyRanges DailyRanges(ISeries<doubleinput )
                            {
                              return 
                        indicator.DailyRanges(input);
                            }
                          }
                        }

                        namespace 
                        NinjaTrader.NinjaScript.Strategies
                        {
                          public 
                        partial class Strategy NinjaTrader.Gui.NinjaScript.StrategyRenderBase
                          
                        {
                            public 
                        Indicators.DailyRanges DailyRanges()
                            {
                              return 
                        indicator.DailyRanges(Input);
                            }

                            public 
                        Indicators.DailyRanges DailyRanges(ISeries<doubleinput )
                            {
                              return 
                        indicator.DailyRanges(input);
                            }
                          }
                        }

                        #endregion 
                        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 
                        DailyRanges Indicator
                          
                        {
                            private 
                        Series<doubleGCSeries;

                            protected 
                        override void OnStateChange()
                            {
                              if (
                        State == State.SetDefaults)
                              {
                                
                        Description                 = @"Enter the description for your new custom Indicator here.";
                                
                        Name                     "DailyRanges";
                                
                        Calculate                 Calculate.OnBarClose;
                                
                        IsOverlay                 true;
                                
                        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)
                              {
                                
                        AddDataSeries("GC 04-22"BarsPeriodType.Day1);
                              }
                            }

                            protected 
                        override void OnBarUpdate()
                            {

                              if (
                        CurrentBars[0] < 55 || CurrentBars[1] < 55) return;


                              
                        NinjaTrader.Gui.Tools.SimpleFont myFont = new NinjaTrader.Gui.Tools.SimpleFont("Courier New"12) { Size 12Bold true };

                              if (
                        BarsInProgress == 0)
                              {
                        //       GCSeries[0] = Highs[1][0]-Lows[1][0];

                                
                        Print("GCSeries" GCSeries);

                                
                        Draw.TextFixed(
                                  
                        this,
                                  
                        "GCSeries",
                                  
                        "Test "+GCSeries.ToString(),
                                  
                        TextPosition.TopRight,
                                  
                        Brushes.White,
                                  
                        myFont,
                                  
                        Brushes.Transparent,
                                  
                        Brushes.Transparent,
                                  
                        0);
                              }

                              if (
                        BarsInProgress == 1)
                              {

                                
                        GCSeries[0] = Highs[1][0]-Lows[1][0];

                        //       Print("GCSeries" + GCSeries);

                        //       Draw.TextFixed(
                        //         this,
                        //         "GCSeries",
                        //         "Test "+GCSeries.ToString(),
                        //         TextPosition.TopRight,
                        //         Brushes.White,
                        //         myFont,
                        //         Brushes.Transparent,
                        //         Brushes.Transparent,
                        //         0);

                              
                        }



                                Print(
                        "GCSeries " GCSeries "Time[0] " Time[0]);
                            }
                          }
                        }

                        #region NinjaScript generated code. Neither change nor remove.

                        namespace NinjaTrader.NinjaScript.Indicators
                        {
                          public 
                        partial class Indicator NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
                          
                        {
                            private 
                        DailyRanges[] cacheDailyRanges;
                            public 
                        DailyRanges DailyRanges()
                            {
                              return 
                        DailyRanges(Input);
                            }

                            public 
                        DailyRanges DailyRanges(ISeries<doubleinput)
                            {
                              if (
                        cacheDailyRanges != null)
                                for (
                        int idx 0idx cacheDailyRanges.Lengthidx++)
                                  if (
                        cacheDailyRanges[idx] != null && cacheDailyRanges[idx].EqualsInput(input))
                                    return 
                        cacheDailyRanges[idx];
                              return 
                        CacheIndicator<DailyRanges>(new DailyRanges(), inputref cacheDailyRanges);
                            }
                          }
                        }

                        namespace 
                        NinjaTrader.NinjaScript.MarketAnalyzerColumns
                        {
                          public 
                        partial class MarketAnalyzerColumn MarketAnalyzerColumnBase
                          
                        {
                            public 
                        Indicators.DailyRanges DailyRanges()
                            {
                              return 
                        indicator.DailyRanges(Input);
                            }

                            public 
                        Indicators.DailyRanges DailyRanges(ISeries<doubleinput )
                            {
                              return 
                        indicator.DailyRanges(input);
                            }
                          }
                        }

                        namespace 
                        NinjaTrader.NinjaScript.Strategies
                        {
                          public 
                        partial class Strategy NinjaTrader.Gui.NinjaScript.StrategyRenderBase
                          
                        {
                            public 
                        Indicators.DailyRanges DailyRanges()
                            {
                              return 
                        indicator.DailyRanges(Input);
                            }

                            public 
                        Indicators.DailyRanges DailyRanges(ISeries<doubleinput )
                            {
                              return 
                        indicator.DailyRanges(input);
                            }
                          }
                        }

                        #endregion 
                        Last edited by PaulMohn; 03-24-2022, 04:00 PM.

                        Comment


                          #13
                          The solution to the 2nd problem

                          The following were needed
                          PHP Code:
                          namespace NinjaTrader.NinjaScript.Indicators
                          {
                            public class 
                          DailyRanges Indicator
                            
                          {
                              private 
                          Series<doubleGCSeries
                          PHP Code:

                                
                          else if (State == State.Configure)
                                {
                                  
                          AddDataSeries("GC 04-22"BarsPeriodType.Day1);
                                } 
                          PHP Code:

                                
                          else if (State == State.DataLoaded)
                                {
                                  
                          GCSeries = new Series<double>(thisMaximumBarsLookBack.Infinite);
                                } 
                          PHP Code:
                              protected override void OnBarUpdate()
                              {

                                if (
                          CurrentBars[0] < 55 || CurrentBars[1] < 4) return;


                                
                          NinjaTrader.Gui.Tools.SimpleFont myFont = new NinjaTrader.Gui.Tools.SimpleFont("Courier New"12) { Size 12Bold true };

                                if (
                          BarsInProgress == 0)
                                {
                                  
                          GCSeries[0] = Highs[1][0]-Lows[1][0];

                                  
                          Draw.TextFixed(
                                    
                          this,
                                    
                          "GCSeries",
                                    
                          "GC Daily High[0] - Low[0]: "+Instrument.MasterInstrument.RoundToTickSize(GCSeries[0] / TickSize),
                                    
                          TextPosition.TopRight,
                                    
                          Brushes.White,
                                    
                          myFont,
                                    
                          Brushes.Transparent,
                                    
                          Brushes.Transparent,
                                    
                          0);
                                }
                              } 
                          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 
                          DailyRanges Indicator
                            
                          {
                              private 
                          Series<doubleGCSeries;

                              protected 
                          override void OnStateChange()
                              {
                                if (
                          State == State.SetDefaults)
                                {
                                  
                          Description                 = @"Enter the description for your new custom Indicator here.";
                                  
                          Name                     "DailyRanges";
                                  
                          Calculate                 Calculate.OnBarClose;
                                  
                          IsOverlay                 true;
                                  
                          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)
                                {
                                  
                          AddDataSeries("GC 04-22"BarsPeriodType.Day1);
                                }
                                else if (
                          State == State.DataLoaded)
                                {
                                  
                          GCSeries = new Series<double>(thisMaximumBarsLookBack.Infinite);
                                }
                              }

                              protected 
                          override void OnBarUpdate()
                              {

                                if (
                          CurrentBars[0] < 55 || CurrentBars[1] < 4) return;


                                
                          NinjaTrader.Gui.Tools.SimpleFont myFont = new NinjaTrader.Gui.Tools.SimpleFont("Courier New"12) { Size 12Bold true };

                                if (
                          BarsInProgress == 0)
                                {
                                  
                          GCSeries[0] = Highs[1][0]-Lows[1][0];

                                  
                          Draw.TextFixed(
                                    
                          this,
                                    
                          "GCSeries",
                                    
                          "GC Daily High[0] - Low[0]: "+Instrument.MasterInstrument.RoundToTickSize(GCSeries[0] / TickSize),
                                    
                          TextPosition.TopRight,
                                    
                          Brushes.White,
                                    
                          myFont,
                                    
                          Brushes.Transparent,
                                    
                          Brushes.Transparent,
                                    
                          0);
                                }
                              }
                            }
                          }

                          #region NinjaScript generated code. Neither change nor remove.

                          namespace NinjaTrader.NinjaScript.Indicators
                          {
                            public 
                          partial class Indicator NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
                            
                          {
                              private 
                          DailyRanges[] cacheDailyRanges;
                              public 
                          DailyRanges DailyRanges()
                              {
                                return 
                          DailyRanges(Input);
                              }

                              public 
                          DailyRanges DailyRanges(ISeries<doubleinput)
                              {
                                if (
                          cacheDailyRanges != null)
                                  for (
                          int idx 0idx cacheDailyRanges.Lengthidx++)
                                    if (
                          cacheDailyRanges[idx] != null && cacheDailyRanges[idx].EqualsInput(input))
                                      return 
                          cacheDailyRanges[idx];
                                return 
                          CacheIndicator<DailyRanges>(new DailyRanges(), inputref cacheDailyRanges);
                              }
                            }
                          }

                          namespace 
                          NinjaTrader.NinjaScript.MarketAnalyzerColumns
                          {
                            public 
                          partial class MarketAnalyzerColumn MarketAnalyzerColumnBase
                            
                          {
                              public 
                          Indicators.DailyRanges DailyRanges()
                              {
                                return 
                          indicator.DailyRanges(Input);
                              }

                              public 
                          Indicators.DailyRanges DailyRanges(ISeries<doubleinput )
                              {
                                return 
                          indicator.DailyRanges(input);
                              }
                            }
                          }

                          namespace 
                          NinjaTrader.NinjaScript.Strategies
                          {
                            public 
                          partial class Strategy NinjaTrader.Gui.NinjaScript.StrategyRenderBase
                            
                          {
                              public 
                          Indicators.DailyRanges DailyRanges()
                              {
                                return 
                          indicator.DailyRanges(Input);
                              }

                              public 
                          Indicators.DailyRanges DailyRanges(ISeries<doubleinput )
                              {
                                return 
                          indicator.DailyRanges(input);
                              }
                            }
                          }

                          #endregion 
                          Last edited by PaulMohn; 03-24-2022, 06:04 PM.

                          Comment


                            #14
                            Hi Paul, I posted an example for you to reference. It will draw the range value of the CG to the top left of any chart. In the future please post a code file or use Pastebin to share code. The numerous code blocks make it difficult to read what your questions are.

                            Kind regards,
                            -ChrisL
                            Attached Files
                            Chris L.NinjaTrader Customer Service

                            Comment


                              #15
                              Hi Chris, thank you for your script.
                              It's not returning the correct value (please see screenshot)

                              How to get the correct value? Thanks!


                              Expiry method and here from Jim
                              Last edited by PaulMohn; 03-25-2022, 02:03 PM. Reason: Expiry method and here from Jim

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by algospoke, Yesterday, 06:40 PM
                              2 responses
                              19 views
                              0 likes
                              Last Post algospoke  
                              Started by ghoul, Today, 06:02 PM
                              3 responses
                              14 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Started by jeronymite, 04-12-2024, 04:26 PM
                              3 responses
                              45 views
                              0 likes
                              Last Post jeronymite  
                              Started by Barry Milan, Yesterday, 10:35 PM
                              7 responses
                              20 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Started by AttiM, 02-14-2024, 05:20 PM
                              10 responses
                              181 views
                              0 likes
                              Last Post jeronymite  
                              Working...
                              X