The attached image shows the relevant log lines for a script that was started at 7:30 in the evening and ran perfectly fine until about 11:30 at night when it crashed. It was restarted about 2am with everything left exactly the same and it's still currently running just fine.
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Trouble with random "Object reference not set to an instance of an object" errors
Collapse
X
-
Trouble with random "Object reference not set to an instance of an object" errors
So I am running across this issue from time to time it seems completely random and not reproducible but occasionally I will start a script and return to find it's disabled itself with the above error. I can then restart the script on the same data same everything and it will run fine. It seems to happen with different indicators both built in and custom and I'm confused on how to handle this.
The attached image shows the relevant log lines for a script that was started at 7:30 in the evening and ran perfectly fine until about 11:30 at night when it crashed. It was restarted about 2am with everything left exactly the same and it's still currently running just fine.Tags: None
-
Hello markdshark,
Just to confirm, the computer is not being allowed to sleep or hibernate and there have not been any connection losses, is this correct?
The error is stating there is a variable with a null value that was used.
What nullable types are you using in OnBarUpdate()?
Are you checking these are not null before using them?
Hello, I keep running into an error of "Object reference not set to an instance of an object." when I set the entryOrder to Null after it has been cancelled. Below is the block of code that I found in several of the example strategies. protected override void OnOrderUpdate(Order order, double limitPrice,Chelsea B.NinjaTrader Customer Service
- Likes 1
-
Thanks Chelsea. Yes computer won't sleep and no connection issues.
I don't know how to answer what nullable types I am using as this seems to be happening with various indicators, both built in and custom. MyLinReg in this case for example is a clean duplicate of the built in LinReg indicator.
Note the error is effectively a built in indicator crashing randomly on a bar and then when it's restarted it doesn't crash.
Thanks for that link. I will follow it and try and trap anything that looks suspicious.
Best,
Mark
Comment
-
Hello Mark,
Add prints before each condition, assignment, and method call.
For example:
Print("1");
if (Close[0] > Close[1])
{
Print("2");
CancelOrder(myOrder);
}
Print("3");
In this example output we would see "2" printed and then the error, but we would not see "3" as the myOrder variable is null.
This tells us the line of code under the Print("2") is causing the error.
Below is a link to a forum post on using prints to understand behavior.
Chelsea B.NinjaTrader Customer Service
- Likes 1
Comment
-
Thanks Chelsea. I'm familiar and I use a ton of prints in development. They are useful for trapping reproducible errors. Just a little bummed that it's built in indicators crashing like this. Also Print statements on tick replay gets overwhelming particularly when the problem may or may not show up for another week. I'm thinking I'll wrap the indicator logic in try/catch blocks and see if I can trap it that way.
A thought... Is there a way to redirect these print statements to another output tab so that I don't overwhelm the regular print output that I want to see when things are working properly?
Mark
Comment
-
Hello Mark,
If there is a lot of output, we suggest writing to a text file with a StreamWriter.
Below is a link to an example that does this.
Citizens of the NinjaTrader Community, A common question we hear from clients is 'why are results from backtest different from real-time or from market replay?'. Live orders are filled on an exchange with a trading partner on an agreed upon price based on market dynamics. Backtest orders are not using these market dynamics.
That said, yes, you can use PrintTo = PrintTo.OutputTab2;.
Chelsea B.NinjaTrader Customer Service
- Likes 1
Comment
-
So I ran into this problem again and I can't help but feel like this maybe is something that should be handled by the internal development team perhaps? I mean the error was LinReg last time. This time it's in the built in indicator SUM. I didn't write SUM. Is it wrong of me to expect the built in indicators to work without crashing?
Comment
-
Hello markdshark,
To report an issue, I will need to be able to reproduce the behavior.
What steps do I need to take to reproduce this error?
This could be a corrupted install, you may have a script with an error, or you may have imported a script that overwrote system indicators.
First try running the repair from the 8.1.1.7 installer.
Chelsea B.NinjaTrader Customer Service
Comment
-
Ok. Reproducing it will be a challenge particularly when it occurs randomly a few times a week and when I restart the script the error does not occur at the same place until the next random point. Let me try your suggestion first. I'll also wrap try/catch blocks in copies of whatever built in indicators are being used and see if I can pin it down a bit.
Comment
-
Although I had another thought which is in order to recreate it, could you not simply pass a null reference to the built in functions SUM and LINREG and see it break?
After all if it is expected that in the normal course of operations these indicators/functions might receive a null pointer reference as input, then I'd suggest that it's not ok for them to crash like this because then we are saying it's ok for the built in indicators to randomly crash in the course of normal operations.
That does seem like an unaddressed development issue to me, particularly because the behavior shown when the same indicator is simply re-run it doesn't break so therefore it could be an issue with the timing of the data or some such blip that we can expect to occur in the standard course of things, and therefore just like the documentation section that suggests checking for null references ( https://ninjatrader.com/support/help...references.htm ) the built in indicators should be built more robustly so that we don't have to fix the built in indicators / functions during development.
Would you agree?
Meanwhile I will still run the repair once current tests are done and try the other things I spoke of earlier too.
Mark
Last edited by markdshark; 10-12-2023, 08:28 AM.
Comment
-
Hello markdshark,
Supplying a null reference would be invalid code. No, scripts are not designed to be passed in null references.
Your script must check for null values before using any variable, including those passed to other indicators, or those used in conditions or methods calls, and prevent errors.
However, the SUM and LINREG use Series<double> as the input series if this is what you are referring to.
A double is a non-nullable type and defaults to 0.
If you don't set a bar value on a bar, that bar value will be 0 and will not be null.
The Series object itself could be null, and likely is, as there is nothing else in the SUM script that is a nullable type.
The SUM indicator only uses two nullable types Value and Input.
Value is being instantiated and assigned by AddPlot(). If this is not being created, this is likely an installation issue.
If the entire input series itself 'Input' is null, (I do not mean a bar slot having a value), then this error will occur. This means the series fed to the indicator was null.
This could be because a custom series was not generated properly and supplied to the LinReg, or could mean there was an issue loading data, or could mean you have a version of the SUM indicator or LinReg indicator that was overwritten and is not the factory default file.
The EventHandlerBarsUpdate error is telling me this is an issue with loading data, and is likely a corrupted installation.Chelsea B.NinjaTrader Customer Service
- Likes 1
Comment
-
Thank you for that detailed explanation. This is very helpful. I will continue to work on it.
I just want to add that I am genuinely in awe of the NinjaTrader framework and how it all hangs together. Software development is inherently a frustrating activity (for me anyway) and then coupled with working the markets it just exponentially multiplies that frustration.
But when all's said and done I'm truly grateful to have Ninjatrader to work with. So a huge thank you to you and everyone at Ninjatrader who makes this work.
MarkLast edited by markdshark; 10-12-2023, 09:24 AM.
Comment
-
I wrapped copies of the builtins LinReg and SUM in try/catch blocks in OnBarUpdate and OnStateChange and this morning although it encountered the error again sometime during the night, the system was still running in the morning. Here are the printouts from the error:
Enabling NinjaScript strategy 'A1GoatCLv1/308020338' : On starting a real-time strategy - StartBehavior=AdoptAccountPosition EntryHandling=All entries EntriesPerDirection=1 StopTargetHandling=Per entry execution ErrorHandling=Stop strategy, cancel orders, close positions ExitOnSessionClose=True / triggering 1800 seconds before close SetOrderQuantityBy=Strategy ConnectionLossHandling=Keep running DisconnectDelaySeconds=10 CancelEntriesOnStrategyDisable=True CancelExitsOnStrategyDisable=False Calculate=On each tick IsUnmanaged=False MaxRestarts=4 in 5 minutes
System.NullReferenceException: Object reference not set to an instance of an object.
at NinjaTrader.Data.BarsSeries.GetClose(Int32 index)
at NinjaTrader.Data.Bars.GetClose(Int32 index)
at NinjaTrader.NinjaScript.PriceSeries.get_Item(Int32 barsAgo)
at NinjaTrader.NinjaScript.Indicators.AMyIndicators.M yLinReg.OnBarUpdate()
System.NullReferenceException: Object reference not set to an instance of an object.
at NinjaTrader.Data.BarsSeries.GetClose(Int32 index)
at NinjaTrader.Data.Bars.GetClose(Int32 index)
at NinjaTrader.NinjaScript.PriceSeries.get_Item(Int32 barsAgo)
at NinjaTrader.NinjaScript.Indicators.AMyIndicators.M yLinReg.OnBarUpdate()Last edited by markdshark; 10-13-2023, 05:41 AM.
Comment
-
So if there's an issue with the data series... And this is from a live realtime data stream from Ninjatrader during market hours, and the installation has been repaired as recommended then what does that mean? It seems like the issue is pointing into a realm that I really have neither control over nor even access to.
It's running on 5000 tick bars.
Mark
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by NullPointStrategies, Today, 05:17 AM
|
0 responses
44 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
124 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
65 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
42 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
46 views
0 likes
|
Last Post
|
Comment