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

IsValidPlot()

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

    IsValidPlot()

    Hi,

    within the OnBarUpdate()-method I use the following syntax.

    Print(Closes[1].IsValidPlot(CurrentBar));
    Print(Closes[1][0]);

    When the first bar is processed, it puts out true for the first line of the code but gives an error at the second line.

    The message:
    You are accessing an index with a value that is invalid since its out of range

    Does the first line of the syntax not work properly?

    #2
    Hi Stephan,

    Using the first line does not prevent the script from accessing invalid values. For intended usage of IsValidPlot, see the following link:


    You need an appropriate CurrentBars check to ensure you don't attempt to access invalid values. For multseries script, it would be something like this:

    if (CurrentBars[1] < 0) return;
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_RyanM View Post
      Hi Stephan,

      if (CurrentBars[1] < 0) return;
      Thanks, this works fine for checking of the beginning of a bar object.
      But how to check for the end of a bar object or a missing bar within a series?

      Comment


        #4
        You may want to look into ContainsValue() for this.

        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_RyanM View Post
          You may want to look into ContainsValue() for this.

          http://www.ninjatrader.com/support/f...ad.php?t=33061
          ContainsValue() is for indicator type data only, isn't it?
          I have to deal with a secondary chart - a bars object.
          I tried Closes[1].IsValidPlot(0) but it also gives false signals. It states true when it's false.
          Last edited by Stephan123; 06-01-2011, 08:58 AM.

          Comment


            #6
            There needs to be enough data for all series to load, but not sure what function you may need, if any. Can you please post a snippet we can use to see the problem?
            Ryan M.NinjaTrader Customer Service

            Comment


              #7
              I have a primary bars object containing a huge history of daily data.
              I added a second sereis with

              Code:
              Add(SecondInstrument, BarsPeriods[0].Id, BarsPeriods[0].Value);
              SecondInstrument is a string containing "^DAX".

              It contains less data history than the primary chart.
              History begins later and stops earlier than that of the primary chart.

              In OnBarUpdate() the indicator conducts calculations with both instruments
              using zero bars ago - values.
              To avaoid addressing invalid indices and throwing exceptions I need a command to check for valid entries
              to suppress calculations if there is no valid data in the second instrument.

              By using

              if (CurrentBars[1]<0)
              {return;}

              I can suppress calculations befor the data history of the second instrument is reached.
              It doesn't work if the end of the second instrument is reached.

              To check if the data is valid I use
              Print(Closes[1][0]);
              If it throws an exception it was invalid.
              I also print the checking condition (boolean) in the output window to see if it
              states what it should do.

              I just need something like IsValidPlot() or ContainsValue() in a way that works with
              my instrument type data (barsobject).

              Comment


                #8
                Maybe you could do a null check on BarsArray[]?

                if (BarsArray[1] == null)
                Ryan M.NinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by NinjaTrader_RyanM View Post
                  Maybe you could do a null check on BarsArray[]?

                  if (BarsArray[1] == null)
                  I tried

                  Code:
                  if (BarsArray[1] == null)
                                  {return;}
                                  
                  Print(BarsArray[1] == null);
                  Print(Closes[1][0]);
                  which resulted in a false and an error followed by it.
                  The error message was:
                  Error on calling 'OnBarUpdate' method for indicator 'Divergence3' on bar 0: You are accessing an index with a value that is invalid since its out of range.
                  Seems again like the data validity check doesn't work.

                  Comment


                    #10
                    Thanks for the reply. Sorry, that did not work for you. Unfortunately there isn't a built in method or property to check for this. It must be custom coded. You can work with time stamps possibly, or CurrentBars for each series.

                    If you only need to solve this one scenario, I would read off the time stamp of the last bar on the secondary series.
                    Ryan M.NinjaTrader Customer Service

                    Comment


                      #11
                      Thanks, after some hours of trial and error I finally figured something out
                      using a combination of reading timestamps and CurrentBars values.

                      Comment


                        #12
                        Great - thanks for the update, Stephan.
                        Ryan M.NinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by usazencort, Today, 01:16 AM
                        0 responses
                        1 view
                        0 likes
                        Last Post usazencort  
                        Started by kaywai, 09-01-2023, 08:44 PM
                        5 responses
                        602 views
                        0 likes
                        Last Post NinjaTrader_Jason  
                        Started by xiinteractive, 04-09-2024, 08:08 AM
                        6 responses
                        22 views
                        0 likes
                        Last Post xiinteractive  
                        Started by Pattontje, Yesterday, 02:10 PM
                        2 responses
                        20 views
                        0 likes
                        Last Post Pattontje  
                        Started by flybuzz, 04-21-2024, 04:07 PM
                        17 responses
                        230 views
                        0 likes
                        Last Post TradingLoss  
                        Working...
                        X