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

Indicator Calling Indicator Error

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

    Indicator Calling Indicator Error

    Hi,

    I am calling a custom indicator (indicator B) from within another custom indicator's (indicator A's) OnBarUpdate().I am getting an 'Object reference not set to an instance of an object.' error when I reference the called indicator (B). So there seems to be a null exception happening here. Is there a way to fix this? Any suggestions would be appreciated. Thank you.

    #2
    Hello,

    Thank you for the post.

    I wanted to see if you could post an example of the syntax where you are calling the indicator so I could get a better idea of what may be null.

    If you are creating an instance of the indicator, perhaps it is the syntax used, I would not be certain from the details so far.


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

    Comment


      #3
      Hi Jesse,

      The calling syntax is:

      Code:
      Print("=========== PB_RTS_RA().ExposedResults.BarValue = "+PB_RTS_RA(BarsArray[1], "Version 1", false, 12).ExposedResults.BarValue);

      Comment


        #4
        Hello,

        Thank you for the reply.

        Have you at this point checked which part of this is null?

        I see there are two sub objects which are used which could potentially be null :

        Code:
        PB_RTS_RA(BarsArray[1], "Version 1", false, 12).[B]ExposedResults[/B].[U]BarValue[/U]
        Could you check that calling only the indicator does not create the error?

        Code:
        PB_RTS_RA(BarsArray[1], "Version 1", false, 12)[0]
        This would entail you have 1 plot, otherwise, you would need to check that the object being used is not null:

        Code:
        if(PB_RTS_RA(BarsArray[1], "Version 1", false, 12).ExposedResults != null)
        Can you try these items and report the results?

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

        Comment


          #5
          Hi Jesse,

          So I have tried your suggestions and here are the results.

          1. As this is not a plot, I did
          Code:
          PB_RTS_RA(BarsArray[1], "Version", false, 12);
          This works and does NOT create the error message.

          2. Next I tried
          Code:
          if (PB_RTS_RA(BarsArray[1], "Version", false, 12).ExposedResults != null)
              Print(">>>>>>>>> NOT NULL <<<<<<<<<<<<<<<");
          This prints 'NOT NULL' but creates the error message.

          3. Finally I tried
          Code:
          if (PB_RTS_RA(BarsArray[1], "Version", false, 12).ExposedResults.BarValue != null)
              Print(">>>>>>>>> NOT NULL BarValue <<<<<<<<<<<<<<<");
          This prints NOT NULL BarValue but also creates the error message.

          Comment


            #6
            Hello,

            Thank you for the reply.

            I believe I would likely need to see the script in more detail to tell what is happening here. The test seems to be inconclusive as to what is null.

            I would suggest starting by checking the indicator to ensure that the items you are using are being created as they should be when called by using prints. Checking the prints when applied to a chart versus being called from the script would help to know if something is happening different or incorrect.

            You could also create a more simple using a simple type like an int to ensure you can pass the int property as expected. This would highlight other problems that may be related to the syntax used.

            If you have a small example of an indicator being called from another script like you are currently using that you can upload, I could take a look at that as well.

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

            Comment


              #7
              Hi Jesse,

              I think the issue is that the object 'ExposedResults' is not being instantiated in the calling indicator. Can you please show me how I might be able to instantiate the object 'ExposedResults' (which is part of another indicator) in the calling indicator? Your help would be greatly appreciated. Thank you.

              Comment


                #8
                Hello,

                Thank you for the reply.

                If the object is not being instantiated you may need to look into the indicator to see why that's happening, or why the logic to do this is not happening. Where do you currently have this property being initialized?

                From outside the indicator, you would need to create a new instance of that object for the type it is. for example :

                Code:
                PB_RTS_RA(BarsArray[1], "Version", false, 12).ExposedResults = new ExposedResultsObjectType();
                Although this may not be the correct solution in the case it should be initialized somewhere else already and that is not happening.

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

                Comment


                  #9
                  Hi Jesse,

                  When I do the initialization as you suggest, I get the error that
                  RA(BarsArray[1], "Version", false, 12) does not have a constructor that takes 4 arguments.

                  However, Intellisense shows that it does take 3 or 4 arguments depending on whether an input series is used. I am assuming the indicator constructors are public, right?

                  Comment


                    #10
                    Hello,

                    Thank you for the reply.

                    In this case, I couldn't really answer this question as I cannot see the source code generated.

                    The Indicators constructor is based on the public properties in the script that are exposed for NinjaScript. There is also an input constructor created.

                    For this item, I would suggest to either create a sample indicator that only contains the public properties being used so we can see what is being generated, or to reduce the script to find the problem.

                    The error is noting that there are not enough overloads for the parameters you provided, this can be the case if you have compiled and the NinjaScript generated code did not include one of your properties.

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

                    Comment


                      #11
                      Hi Jesse,

                      I am still having issues with this. I have solved the error issues but no data is being passed between the indicators.I have built a small sample code. Would you be able to have a look at it to see what's going on?

                      Comment


                        #12
                        Hello,

                        Yes, please feel free to upload a simple sample of the problem. If you have extracted the properties in question and formed a sample that would be best to review the situation with.

                        You can always upload samples to the forum, or if you have something you do not want to share you can use the platform support [at] ninjatrader.com email. I do want to note, if your code cannot be shared publically and is very large, you may instead want to reduce it to a simple sample for best results.


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

                        Comment


                          #13
                          Hi Jesse,

                          The code is relatively simple. I will email it to your attention.
                          It should work, but as it doesn't, I guess I am missing something. Thank you for having a look at it. Your input would be greatly appreciated.

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Barry Milan, Today, 10:35 PM
                          1 response
                          7 views
                          0 likes
                          Last Post NinjaTrader_Manfred  
                          Started by WeyldFalcon, 12-10-2020, 06:48 PM
                          14 responses
                          1,428 views
                          0 likes
                          Last Post Handclap0241  
                          Started by DJ888, Yesterday, 06:09 PM
                          2 responses
                          9 views
                          0 likes
                          Last Post DJ888
                          by DJ888
                           
                          Started by jeronymite, 04-12-2024, 04:26 PM
                          3 responses
                          40 views
                          0 likes
                          Last Post jeronymite  
                          Started by bill2023, Today, 08:51 AM
                          2 responses
                          16 views
                          0 likes
                          Last Post bill2023  
                          Working...
                          X