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 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