Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Analyzer
Collapse
X
-
Analyzer
I have a strategy that I runn successfully in playback mode, but when I run it through the strategy analyzer I get this message: "Error on calling 'OnStateChange' method: Object reference not set to an instance of an object.". Any thoughts? thanksTags: None
-
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Indicator here.";
Name = "MyNT8RangeBreakoutV2";
Calculate = Calculate.OnEachTick;
IsOverlay = true;
DisplayInDataBox = true;
DrawOnPricePanel = true;
ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
BandOpacity = 3;
EntriesPerDirection = 1;
EntryHandling = EntryHandling.AllEntries;
IsExitOnSessionCloseStrategy = true;
ExitOnSessionCloseSeconds = 30;
IsFillLimitOnTouch = false;
TraceOrders = true;
BarsRequiredToTrade = 10;
IsInstantiatedOnEachOptimizationIteration = false; // Disable this property for performance gains in Strategy Analyzer optimizations
IsUnmanaged = false;
OrderFillResolution = OrderFillResolution.Standard;
MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
Slippage = 0;
StartBehavior = StartBehavior.WaitUntilFlat;
TimeInForce = TimeInForce.Gtc;
RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
StopTargetHandling = StopTargetHandling.PerEntryExecution;
ClearOutputWindow();
}
else if (State == State.Configure)
{
AddDataSeries(BarsPeriodType.Minute, 1); // BarsInProgress 1 ... we use this as a '1 min timer' so that the OnBarUpdate function ... acts like a timer.
baseLine = new Series<double>(this, MaximumBarsLookBack.Infinite);
SetStopLoss(CalculationMode.Ticks, initialStopLevel);
// SetProfitTarget(CalculationMode.Ticks, 400*TickSize);
}
else if (State==State.DataLoaded)
{
instName= Instrument.MasterInstrument.Name;
sessionTxtwithSpacers = sessionTxt;
DirectoryInfo dir = new DirectoryInfo(NinjaTrader.Core.Globals.InstallDir + "sounds");
soundFileDir = dir.ToString()+"\\";
firstPasses = true;
if (runProgram)
{
if (Account.Name != "Sim101" && Account.Name != "Replay101" && Account.Name != "Playback101")
chartBackroundNoTrade = liveColor;
else
chartBackroundNoTrade = originalColor;
ChartControl.Properties.ChartBackground = chartBackroundNoTrade;
}
}
Comment
-
I believe this is happening because of your 'runProgram' if condition. Are you able to run the strategy when that is commented out?
Help Guide - Debugging your NinjaScript codeJosh G.NinjaTrader Customer Service
Comment
-
OK ... so that suggestion cleared up the error. Thank you! But know another issue has arisen. I ran the strategy for the same time period and for the same parameters as I ran in playback mode ... but received very different results. I checked time and time again to make sure all the settings are the same, but I'm clueless why the results are so different. Is there any place you can direct me to that may help me sort this out? Thanks in advance.
Comment
-
Hello pman777,
Thanks for the reply.
Just to confirm, you are running the strategy in Playback mode, and then you are running the strategy through the Strategy Analyzer and comparing the results?
If this is the case, and you are seeing different results, it is likely because you need to turn on Tick Replay in the strategy analyzer, this will process the data as it came in instead of on the close of every bar.
I look forward to assisting further.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Mindset, 04-21-2026, 06:46 AM
|
0 responses
91 views
0 likes
|
Last Post
by Mindset
04-21-2026, 06:46 AM
|
||
|
Started by M4ndoo, 04-20-2026, 05:21 PM
|
0 responses
137 views
0 likes
|
Last Post
by M4ndoo
04-20-2026, 05:21 PM
|
||
|
Started by M4ndoo, 04-19-2026, 05:54 PM
|
0 responses
68 views
0 likes
|
Last Post
by M4ndoo
04-19-2026, 05:54 PM
|
||
|
Started by cmoran13, 04-16-2026, 01:02 PM
|
0 responses
121 views
0 likes
|
Last Post
by cmoran13
04-16-2026, 01:02 PM
|
||
|
Started by PaulMohn, 04-10-2026, 11:11 AM
|
0 responses
72 views
0 likes
|
Last Post
by PaulMohn
04-10-2026, 11:11 AM
|

Comment