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

Adding a user selectable data series via AddDataSeries

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

    Adding a user selectable data series via AddDataSeries

    I have a few indicators where the user may select to calculate indicator values from minute, tick or volume data. For that purpose I have used an enum which allows the user to select the input series. Simplified, the code looks like this

    Code:
    else if(State == State.Configure)
    {
          if(myEnum == enumValue1)
               AddDataSeries(BarsPeriodType.Minute, 1)
          else if (myEnum == enumValue 2)
               AddDataSeries(BarsPeriodType.Tick, barPeriod)
          else if (myEnum == enumValue 3)
               AddDataSeries(BarsPeriodType.Volume, barPeriod)  
    }
    There are public properties MyEnum and BarPeriod which hold user-selected values.

    This approach works fine, when the indicator is applied to a chart. However, it does not work, when I add the indicator to the market analyzer or the dynamic SuperDOM. In this case I am getting an error on calling OnStateChange(): "Object reference not set to an instance of an object."

    I am aware that I could add all three DataSeries (minute bars, tick bars and volume bars) and that this would fix the problem. However, adding three DataSeries when only one is needed slows down NinjaTrader for no valid reason.

    Could you suggest any other option to make that added DataSeries user-selectable?
    Last edited by Harry; 07-25-2017, 07:03 AM.

    #2
    Hello Harry,

    While dynamically adding data series is neither suggested nor supported, I found that if I add a plot within State.Configure, the plot value is not shown in the MA window. However, if you add the plot within State.SetDefaults, then the plots/values will be displayed in the window.

    After moving your AddPlot calls to state.setdefaults, do you get the behavior you expect?

    I look forward to your reply.
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_AlanP View Post
      Hello Harry,

      While dynamically adding data series is neither suggested nor supported, I found that if I add a plot within State.Configure, the plot value is not shown in the MA window. However, if you add the plot within State.SetDefaults, then the plots/values will be displayed in the window.

      After moving your AddPlot calls to state.setdefaults, do you get the behavior you expect?

      I look forward to your reply.
      Alan, my question was about AddDataSeries - adding secondary bars as input data - and not about adding a plot or a Series<double> both of which are used for output data.

      This has nothing to do with plots.

      The confusion is here, because in NinjaSpeak both bar series (input) and plots (output) are called DataSeries. With NinjaTrader 8 the terminology has changed and the output series are now called Series<double>.
      Last edited by Harry; 07-25-2017, 09:33 AM.

      Comment


        #4
        Hello Harry,

        I apologize for the confusion.

        Unfortunately dynamically adding a data series is not supported but I’ve submitted your vote to a feature request pertaining to dynamically adding data series.

        I would suggest adding all three data series as a solution for now.

        Please let us know if you need further assistance.
        Alan P.NinjaTrader Customer Service

        Comment


          #5
          Sft-882

          Alan,

          I have carefully read the comment by NinjaTrader Jim here



          and in fact the problem that I had was not related to adding secondary bars. If I go back to my original question, the answer is simple. It is possible to do what I have asked for and it works as expected. It is possible to let the user select which secondary bar shall be added. I did not want to load them dynamically as you have suspected.

          My real problem was that I had tried to access

          -> BarsArray[0].BarsPeriod.BarsPeriodType
          -> BarsPeriods[0].Value

          in State == State.Configure. Accessing these values in State.Configure works when the indicator is applied to a chart, but does not work when the indicator is called by strategy, the market analyzer or the SuperDOM. In that case the value can only be accessed in State.DataLoaded.


          Feature Request ID SFT-882

          I have seen that there is a feature request SFT-882, but this is about dynamically loading or removing secondary bars. I never wanted to do that.


          Feature Request: Accessing information on primary bar series in State.Configure.

          The only thing that would be needed to fix my problem is a possibility to access bar type and bar period of the primary bars in State.Configure.

          Currently this information is hidden until State.DataLoaded is reached - at least when the indicator is called. This is how it works per now

          -> indicator applied to a chart: information on bar type and bar period is available in State.Configure
          -> indicator used as input series by a strategy, market analyzer: information on bar type and bar period is only available in State.DataLoaded

          It is this second case, which causes the problem, as the information is not available when needed.
          Last edited by Harry; 07-25-2017, 04:03 PM.

          Comment


            #6
            Hello Harry,

            I will submit a feature request for Accessing information on primary bar series in State.Configure.

            Please let us know if you need further assistance.
            Alan P.NinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_AlanP View Post
              Hello Harry,

              I will submit a feature request for Accessing information on primary bar series in State.Configure.

              Please let us know if you need further assistance.
              Thank you very much.

              The difficulty here is that

              -> when an indicator is applied to a chart the chart bars - which are identical to the primary bars - can be already accessed in State.Configure

              -> when that same indicator is used as an input for another indicator, a strategy or the market analyzer, then it is the other indicator, strategy or the market analzyer that provides for the primary bars for this indicator, and they can only be accessed in State.DataLoaded

              The difficulty is to access information on BarsArray[0] and BarsPeriods[0] before they have been loaded. Maybe it is not even feasible.

              I have used the information to adjust the bar type and bar period of the secondary bars to match the requirements imposed by the primary bars. The missing link here is how to retrieve the information on the primary bars and build the secondary bars to match the primary bars to some extent (same bar type, but different bar period).

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by sofortune, Yesterday, 11:48 AM
              2 responses
              20 views
              0 likes
              Last Post NinjaTrader_BrandonH  
              Started by Zach55, 02-19-2024, 07:22 PM
              2 responses
              51 views
              0 likes
              Last Post lbadisa1  
              Started by JGriff5646, Today, 05:47 PM
              1 response
              9 views
              0 likes
              Last Post NinjaTrader_BrandonH  
              Started by AlphaOptions, 06-18-2013, 08:24 AM
              9 responses
              2,199 views
              0 likes
              Last Post NinjaTrader_Manfred  
              Started by ttrader23, Today, 09:33 AM
              3 responses
              22 views
              0 likes
              Last Post NinjaTrader_BrandonH  
              Working...
              X