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

Access AddDataSeries values

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

    Access AddDataSeries values

    I'm new to NT 8.

    AddDataSeries("^DVOL", Data.BarsPeriodType.Minute, 1, Data.MarketDataType.Last);

    I have this auto generated statement in OneStateChange() method but I'm uncertain how i access the data value from this data series in the OnBarUpdate().

    What I want to do is plot the DVOL within my indicator study.

    Thank you :-)

    #2
    Hello bigsurftrader,

    Thanks for your post and welcome to the Forums!

    Just to be clear you are trying to create an indicator to show the data series ^DVOL? As opposed to just adding it to a chart as a dataseries? Are you intending to do anything else with the ^DVOL data?

    If all you want is to show ^DVOL on the chart then right mouse click on the chart, select Data series, then in the data series window in the instrument selector either find or type ^DVOL and press enter key to add to the chart. ^DVOL will then be shown in its own panel in the chart.

    To answer your indicator questions, you would need to also add a plot to be able to output the data. This is done through AddPlot() method described here: http://ninjatrader.com/support/helpG...s/?addplot.htm

    Then in the OnBarUpdate() method you would need to assign the DVOL data to the plot, something along these lines: Value[0] = Closes[1][0]; //send DVOL to plot
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Hi Paul,

      Thank you for the prompt reply.

      I have ES running in the price chart, and want to display DVOL at the bottom, in the indicator chart area -- both in the same window.

      Comment


        #4
        Hi Paul, here's a subsection of the code along with Plot settings:

        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;
        AddPlot(Brushes.Green, "DVOL");
        AddPlot(Brushes.RoyalBlue, "UVOL");
        }
        else if (State == State.Configure)
        {
        AddDataSeries("^DVOL", Data.BarsPeriodType.Minute, 1, Data.MarketDataType.Last);
        }
        }

        protected override void OnMarketData(MarketDataEventArgs marketDataUpdate)
        {

        }

        Comment


          #5
          Hello bigsurftrader,

          Thanks for your reply.

          I made a short video on how to add a dataseries to the chart: https://www.screencast.com/t/bp1vFi1APL
          Paul H.NinjaTrader Customer Service

          Comment


            #6
            Wow. So glad I migrated to NT!

            Thank you so much!

            Comment


              #7
              One last question on this topic.

              I'd like to learn how to do this programmatically. I used the Indicator wizard to create two plot series and two data series.

              //This namespace holds Indicators in this folder and is required. Do not change it.
              namespace NinjaTrader.NinjaScript.Indicators.Marks
              {
              public class MODVOLUVOL : Indicator
              {
              protected override void OnStateChange()
              {
              if (State == State.SetDefaults)
              {
              Description = @"DVOL and UVOL";
              Name = "MODVOLUVOL";
              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;
              AddPlot(Brushes.Orange, "DVOL");
              AddPlot(Brushes.Brown, "UVOL");
              }
              else if (State == State.Configure)
              {
              AddDataSeries("^DVOL", Data.BarsPeriodType.Minute, 1, Data.MarketDataType.Last);
              AddDataSeries("^UVOL", Data.BarsPeriodType.Minute, 1, Data.MarketDataType.Last);
              }
              }

              protected override void OnBarUpdate()
              {
              Values[0][0] = Closes[0][0];
              Values[1][0] = Closes[1][0];
              }

              #region Properties

              [Browsable(false)]
              [XmlIgnore]
              public Series<double> DVOL
              {
              get { return Values[0]; }
              }

              [Browsable(false)]
              [XmlIgnore]
              public Series<double> UVOL
              {
              get { return Values[1]; }
              }
              #endregion

              }
              }

              I'm still uncertain why this code is not outputing the DVOL and UVOL data.

              Thanks once again

              Comment


                #8
                Hello bigsurftrader,

                Thanks for your post.

                When you run the indicator, do you see any error messages listed in the "log" tab of the Ninjatrader8 control center related to the indicator?

                What is the charted dataseries? (ES 1 minute?)
                Paul H.NinjaTrader Customer Service

                Comment


                  #9
                  Yes. 1M @ES.D

                  Log:
                  Indicator'MODVOLUVOL": Error on calling 'OnBarUpdate' method on bar 0: You are accessing an index that is invalid since it is out-of-range.

                  Comment


                    #10
                    Hello bigsurftrader,

                    Thanks for your reply.

                    Please add this change in the OnBarUpdate() section as the first two lines.

                    if (CurrentBars[0] < 1 || CurrentBars[1] < 1 || CurrentBars[2] < 1) return; // do not process unless we have a bar in each dataseries.

                    if (BarsInprogress != 0) return; // only process on the chart bars timing

                    The first line makes sure you have data before trying to plot. The second line is to plot once per Bars In Progress 0 update (BIP0 = chart bars).

                    References:
                    http://ninjatrader.com/support/helpG...urrentbars.htm
                    http://ninjatrader.com/support/helpG...inprogress.htm
                    http://ninjatrader.com/support/helpG...nstruments.htm
                    Paul H.NinjaTrader Customer Service

                    Comment


                      #11
                      Hello bigsurftrader,

                      I just realized that another change will be needed in your code.

                      Please change:

                      Values[0][0] = Closes[0][0];
                      Values[1][0] = Closes[1][0];

                      to

                      Values[0][0] = Closes[1][0]; //Dvol
                      Values[1][0] = Closes[2][0]; //UVol
                      Paul H.NinjaTrader Customer Service

                      Comment


                        #12
                        Ah!!!!!!!

                        Thanks for your help. I've got over 4,000 lines of code to port to NT. And I see why my code didn't work. I'll add that.

                        Comment


                          #13
                          That makes sense, the "0" index reference would be for "ES".

                          Paul - thank you so much once again. I GREATLY appreciate your assistance. Now that I understand how data is stored and how to reference it, I can see more clearly how to manipulate the values to what i need.

                          THANK YOU!!!

                          Comment


                            #14
                            Paul - I wanted to let you know the code works now.

                            Once again, a thousand thank yous!

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by Javierw.ok, Today, 04:12 PM
                            0 responses
                            4 views
                            0 likes
                            Last Post Javierw.ok  
                            Started by timmbbo, Today, 08:59 AM
                            2 responses
                            10 views
                            0 likes
                            Last Post bltdavid  
                            Started by alifarahani, Today, 09:40 AM
                            6 responses
                            40 views
                            0 likes
                            Last Post alifarahani  
                            Started by Waxavi, Today, 02:10 AM
                            1 response
                            18 views
                            0 likes
                            Last Post NinjaTrader_LuisH  
                            Started by Kaledus, Today, 01:29 PM
                            5 responses
                            15 views
                            0 likes
                            Last Post NinjaTrader_Jesse  
                            Working...
                            X