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.
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!
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
NinjaTrader
Indicator Calling Indicator Error
Collapse
X
-
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.Tags: None
-
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
-
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]
Code:PB_RTS_RA(BarsArray[1], "Version 1", false, 12)[0]
Code:if(PB_RTS_RA(BarsArray[1], "Version 1", false, 12).ExposedResults != null)
I look forward to being of further assistance.JesseNinjaTrader Customer Service
Comment
-
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);
2. Next I tried
Code:if (PB_RTS_RA(BarsArray[1], "Version", false, 12).ExposedResults != null) Print(">>>>>>>>> NOT NULL <<<<<<<<<<<<<<<");
3. Finally I tried
Code:if (PB_RTS_RA(BarsArray[1], "Version", false, 12).ExposedResults.BarValue != null) Print(">>>>>>>>> NOT NULL BarValue <<<<<<<<<<<<<<<");
Comment
-
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
-
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
-
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();
I look forward to being of further assistance.JesseNinjaTrader Customer Service
Comment
-
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
-
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
-
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
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by kaywai, 09-01-2023, 08:44 PM
|
5 responses
601 views
0 likes
|
Last Post Today, 12:32 AM | ||
Started by xiinteractive, 04-09-2024, 08:08 AM
|
6 responses
22 views
0 likes
|
Last Post Today, 12:31 AM | ||
Started by Pattontje, Yesterday, 02:10 PM
|
2 responses
19 views
0 likes
|
Last Post
by Pattontje
Yesterday, 11:49 PM
|
||
Started by flybuzz, 04-21-2024, 04:07 PM
|
17 responses
230 views
0 likes
|
Last Post
by TradingLoss
Yesterday, 11:45 PM
|
||
Started by agclub, 04-21-2024, 08:57 PM
|
3 responses
17 views
0 likes
|
Last Post
by TradingLoss
Yesterday, 11:42 PM
|
Comment