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

error message in OW

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

    error message in OW

    Hello,

    I get this error in the OW:

    Indicator 'MyCustomIndicator3': Error on calling 'OnBarUpdate' method on bar 0: Object reference not set to an instance of an object.



    Is it possible that if
    cant find any value equal it return the error message?
    Last edited by frankduc; 09-16-2019, 12:51 PM.

    #2
    Hello frankduc,

    Is it possible that if
    sofVdiv == fibo2 cant find any value equal it return the error message?
    No, == would make a true or false result.

    The error means that something being used is null, however from what is provided I couldn't say what that might be. I would need to know the types of sofVdiv and fibo2 to know if those would relate to this error.

    You can look in your code for any object being used, only an object being null can create this type of error. Other value types like an int or double would not be null.

    The solution is to surround the code with a null check for the object that fails:

    Code:
    if(objectThatFails != null)
    {
       // code here
    }
    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      They are both double. They work fine individually if i print() both of them they return what it suppose to return, but when in the if statement it fails.

      It seems to be related to index:

      i use index in a first for loop:


      It could be the {}

      thanks for your insights
      Last edited by frankduc; 09-16-2019, 12:51 PM.

      Comment


        #4
        Hello frankduc,

        Thank for you expanding on the prior inquiry, I still would have some questions surrounding what you provided.

        They are both double. They work fine individually if i print() both of them they return what it suppose to return, but when in the if statement it fails.
        Your working prints don't seem to be shown in this sample for me to compare, can you show how you had the prints when it was working?

        ....but when in the if statement it fails
        It seems to be related to index:
        These statements seem to conflict, which is it? Is it related to being in the condition or the index? I cant really tell from what you are providing as the sample is split.

        It could be the {}
        It could be, the sample provided does provide that kind of context. When providing a sample I don't recommend breaking it apart. I would suggest to copy/paste the code exactly as you have it, it really helps to see the full context.

        To test where the problem is, you can add prints inbetween statements:
        Code:
        Print("Here 1");
        for (int barIndex = ChartBars.FromIndex; barIndex <= ChartBars.ToIndex; barIndex++)
        { 
        Print("Here 2");
        if (Bars.GetLow(barIndex) < lowPrice)
        {
        ​​​​​​​Print("Here 3");
        lowPrice = Bars.GetLow(barIndex);
        ​​​​​​​Print("Here 4");
        index = barIndex;
        ​​​​​​​Print("Here 5");
        
        }
        }
        then look at the output for where it stops:

        here 1
        here 2
        here 3
        ...
        exception

        The print before the exception will be the last area before the bad code was called.



        I look forward to being of further assistance.



        JesseNinjaTrader Customer Service

        Comment


          #5
          Sorry i dont want to reveal the entire code on the forum.
          But i did remove the brackets surrounding the if statement and now it is working. I dont know if its bad practice to do that.

          index0 = 0 which is normal considering there is no equal numbers.

          The problem i still get the error message:
          Indicator 'MyCustomIndicator3': Error on calling 'OnBarUpdate' method on bar 0: Object reference not set to an instance of an object.




          It's like if the code was running throught all the index and when it reach bar 0 it cant process. (its not the end of the world)
          Maybe that's the reason, the for loop both start at index (bar X) and the starting point of the calculation cant divide by itself.

          By the way index0 give me bars ago or bar index "number" of 1708 …. i always get mixt up. I think its bar index?.


          Thank you
          Last edited by frankduc; 08-29-2019, 06:14 AM.

          Comment


            #6
            Hello frankduc,

            I wouldn't have a different answer here without seeing the whole context. If you don't want to share an example that is complete that is fine however your options become more limited and you will likely need to figure this out on your own. When working on the forum, we would need the code to be able to help with your questions. What you are providing is not enough information so you will need to explore this further or make a sample that shows the whole context.

            By the way index0 give me bars ago or bar index "number" of 1708 …. i always get mixt up. I think its bar index?.
            Based on the naming it looks like an index, if you are having trouble keeping track of variable or what they are for I can suggest adding comments to let yourself know its purpose.

            Code:
            // this is a comment

            I look forward to being of further assistance.

            JesseNinjaTrader Customer Service

            Comment


              #7
              When i Print() the result of my if statement i get all the result from the for loop.

              Is there a way i can Print() only the result of the equal? If each one = 0.87 the Print() only show 0.87
              I tried everything with or without brackets but it wont return the answer from the equal part. I know they are equal but not at what result.

              i

              I understand if there is not enough information.

              thank you
              Last edited by frankduc; 09-16-2019, 12:52 PM.

              Comment


                #8
                Hello frankduc,

                If you want to print only for a specific part of your loop you would need to form some kind of condition to check for that. Checking if two double numbers are equal will not often become true, you would need to use math to find the difference between the values and compare that. https://ninjatrader.com/support/help...arithmetic.htm


                I look forward to being of further assistance.
                JesseNinjaTrader Customer Service

                Comment


                  #9
                  problem solve

                  thank you
                  Last edited by frankduc; 08-30-2019, 09:10 AM.

                  Comment


                    #10
                    I have a new problem.

                    If i for exemple set a volume chart to 1000 bars, every time a new bar is create its adding one bar (1001), but in the data series bars to load there's only 1000 bars.
                    So the number on the chart is increasing to 1010 but in the data series window it still show 1000 bars.

                    Because the number of bars is not following in the data series my indicator stop working unless i update to the same number of bars in the chart, the data series.

                    Any explanation why?

                    thank you

                    Comment


                      #11
                      Hello frankduc,

                      If you have a new and unrelated question please make sure to make a new thread specific to that problem. I will reply once here to close this issue, if you have a follow up question, make a new thread and include all the details surrounding your specific question. It is confusing if the topic title does not match the post content for anyone viewing the context. As you are using the forum we recommend making specific new topics for new questions.

                      Because the number of bars is not following in the data series my indicator stop working unless i update to the same number of bars in the chart, the data series.
                      There is no expectation that a chart will always contain the same number of bars, if you load 1000 bars that will be how many it starts with. You will nearly always have more bars than you started with if you are also using realtime data.



                      I look forward to being of further assistance.
                      JesseNinjaTrader Customer Service

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by tradingnasdaqprueba, 05-07-2024, 03:42 AM
                      13 responses
                      49 views
                      0 likes
                      Last Post NinjaTrader_Jesse  
                      Started by bill2023, Yesterday, 08:21 AM
                      3 responses
                      18 views
                      0 likes
                      Last Post NinjaTrader_Jesse  
                      Started by DawnTreader, Yesterday, 05:58 PM
                      4 responses
                      19 views
                      0 likes
                      Last Post DawnTreader  
                      Started by lorem, 04-25-2024, 09:18 AM
                      10 responses
                      47 views
                      0 likes
                      Last Post lorem
                      by lorem
                       
                      Started by swjake, Today, 12:04 PM
                      1 response
                      9 views
                      0 likes
                      Last Post NinjaTrader_ChelseaB  
                      Working...
                      X