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

Data Series question

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

    Data Series question

    For one of my indicators I am trying to access information from previous bars, but can't find a readily available way to do so. In strategies I could just go Close[5] but from what I can tell only Close[0] works in indicators. Currently I am just passing the value along a 5-variable daisy chain so I can have access to Close[5]. There has to be a better way of doing this. Any suggestions?

    I think I am using the data series thing wrong. Here is my awkward code

    Code:
    protected override void Initialize()
            {
                Add(new Plot(Color.Empty, PlotStyle.Hash, "RegCh[1]"));
                Add(new Plot(Color.Empty, PlotStyle.Hash, "RegCh[2]"));
                Add(new Plot(Color.Empty, PlotStyle.Hash, "RegCh[3]"));
                Add(new Plot(Color.Empty, PlotStyle.Hash, "RegCh[4]"));
                Add(new Plot(Color.Empty, PlotStyle.Hash, "RegCh[5]"));
            }
    Code:
    protected override void OnBarUpdate()
            {
                PriorRegCh.Set(currentRegCh);    
                PriorRegCh2.Set(RegCh1);
                PriorRegCh3.Set(RegCh2);
                PriorRegCh4.Set(RegCh3);
                PriorRegCh5.Set(RegCh4);    
                currentRegCh     =     RegressionChannel(60, 2).Middle[0];
                RegCh1            =    PriorRegCh[0];
                RegCh2            =    PriorRegCh2[0];
                RegCh3            =    PriorRegCh3[0];
                RegCh4            =    PriorRegCh4[0];
    Code:
            #region Properties
            [Browsable(false)]
            [XmlIgnore()]
            public DataSeries PriorRegCh
            {
                get { return Values[0]; }
            }
    
            [Browsable(false)]
            [XmlIgnore()]
            public DataSeries PriorRegCh2
            {
                get { return Values[1]; }
            }
    
            [Browsable(false)]
            [XmlIgnore()]
            public DataSeries PriorRegCh3
            {
                get { return Values[2]; }
            }
    
            [Browsable(false)]
            [XmlIgnore()]
            public DataSeries PriorRegCh4
            {
                get { return Values[3]; }
            }
    
            [Browsable(false)]
            [XmlIgnore()]
            public DataSeries PriorRegCh5
            {
                get { return Values[4]; }
            }
    For some reason I ended up with many plots for my Regression Channel. I was only aiming for one, but it seemed to want a plot for every dataseries I had. What I did was copy the way the PriorDayOHLC indicator stored values. It seems very inefficient.
    Josh P.NinjaTrader Customer Service

    #2
    The "barsAgo" logic like in Close[5] (meaning 5 bars ago) works in indicators as well as in strategies.

    Comment


      #3
      Hmm. When I put a very simple test it breaks my indicator for no apparent reason.

      Code:
      if (Close[1] != Close[0]) Print("Test Success");
      If that line is in there my indicator is completely broken. The indicator fails to load or something. It also doesn't print my message in my Output Window. Furthermore, in my Log I also get "Error on calling the 'OnBarUpdate' method for indicator 'BlackBelt90' on bar 0: Index was out of range. Must be non-negative and less than the size of the collection."

      I can't make any sense as to why this is happening.
      Josh P.NinjaTrader Customer Service

      Comment


        #4
        Close[1] references one bar back, On bar 0 there is no such bar -> crash

        You need to put in something like:
        if (CurrentBar < 1)
        return;

        Comment


          #5
          Genius! Thanks. Before I had the BarsRequired setting thinking it would do the job of preventing referencing to nonexistent bars.
          Josh P.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Christopher_R, Today, 12:29 AM
          0 responses
          9 views
          0 likes
          Last Post Christopher_R  
          Started by sidlercom80, 10-28-2023, 08:49 AM
          166 responses
          2,235 views
          0 likes
          Last Post sidlercom80  
          Started by thread, Yesterday, 11:58 PM
          0 responses
          3 views
          0 likes
          Last Post thread
          by thread
           
          Started by jclose, Yesterday, 09:37 PM
          0 responses
          8 views
          0 likes
          Last Post jclose
          by jclose
           
          Started by WeyldFalcon, 08-07-2020, 06:13 AM
          10 responses
          1,415 views
          0 likes
          Last Post Traderontheroad  
          Working...
          X