protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
if (Instrument.MasterInstrument.InstrumentType == InstrumentType.Future &&
(Instrument.MasterInstrument.Name == "EMD"))
isGlobex = true;
else
isGlobex = false;
if (sessionType == anaSessionTypeVWAPD43.Trading_Day && isGlobex)
{
publicHoliday[0] = publicHoliday0;
}
else for(int i=0; i<42; i++)
publicHoliday[i] = NinjaTrader.Core.Globals.MinDate;
if (Instrument.MasterInstrument.InstrumentType == Cbi.InstrumentType.Forex )
isCurrency = true;
else
isCurrency = false;
//------------------------------------------------------
if (sessionType == anaSessionTypeVWAPD43.ETH || sessionType == anaSessionTypeVWAPD43.Trading_Day)
{
rthVWAP = false;
shiftAnchor = TimeSpan.Compare(sessionOffset, new TimeSpan(0,0,0));
if(shiftAnchor > 0)
applySessionOffset = true;
}
else
{
rthVWAP = true;
shiftAnchor = 0;
applySessionOffset = false;
if (sessionType == anaSessionTypeVWAPD43.RTH)
continueSession = false;
else
continueSession = true;
if (selectedSession == anaSessionCountVWAPD43.Auto)
{
if (isCurrency)
activeSession = anaSessionCountVWAPD43.Third;
else
activeSession = anaSessionCountVWAPD43.Second;
}
else
activeSession = selectedSession;
}
AddPlot(new Stroke(Brushes.Gold,1),PlotStyle.Dot,"Session VWAP");
AddPlot(new Stroke(Brushes.Gold,1),PlotStyle.Line,"Upper Band SD 3");
AddPlot(new Stroke(Brushes.Gold,1),PlotStyle.Line,"Upper Band SD 2");
AddPlot(new Stroke(Brushes.Gold,1),PlotStyle.Line,"Upper Band SD 1");
AddPlot(new Stroke(Brushes.Gold,1),PlotStyle.Line,"Lower Band SD 1");
AddPlot(new Stroke(Brushes.Gold,1),PlotStyle.Line,"Lower Band SD 2");
AddPlot(new Stroke(Brushes.Gold,1),PlotStyle.Line,"Lower Band SD 3");
innerAreaBrush = new SolidColorBrush(Color.FromArgb(75, 30,144,255));
middleAreaBrush = new SolidColorBrush(Color.FromArgb(0, 65,105,225));
outerAreaBrush = new SolidColorBrush(Color.FromArgb(75, 0,0,128));
Plots[1].Brush = OuterBandColor;
Plots[2].Brush = MiddleBandColor;
Plots[3].Brush = InnerBandColor;
Plots[4].Brush = InnerBandColor;
Plots[5].Brush = MiddleBandColor;
Plots[6].Brush = OuterBandColor;
Plots[0].Width = plot0Width;
Plots[0].PlotStyle = plot0Style;
Plots[0].DashStyleHelper = dash0Style;
Plots[1].Width = plot1Width;
Plots[1].PlotStyle = plot1Style;
Plots[1].DashStyleHelper = dash1Style;
Plots[2].Width = plot1Width;
Plots[2].PlotStyle = plot1Style;
Plots[2].DashStyleHelper = dash1Style;
Plots[3].Width = plot1Width;
Plots[3].PlotStyle = plot1Style;
Plots[3].DashStyleHelper = dash1Style;
Plots[4].Width = plot1Width;
Plots[4].PlotStyle = plot1Style;
Plots[4].DashStyleHelper = dash1Style;
Plots[5].Width = plot1Width;
Plots[5].PlotStyle = plot1Style;
Plots[5].DashStyleHelper = dash1Style;
Plots[6].Width = plot1Width;
Plots[6].PlotStyle = plot1Style;
Plots[6].DashStyleHelper = dash1Style;
gap0 = (plot0Style == PlotStyle.Line || plot0Style == PlotStyle.Square);
gap1 = (plot1Style == PlotStyle.Line || plot1Style == PlotStyle.Square);
if (Bars.BarsPeriod.BarsPeriodType == BarsPeriodType.Minute || Bars.BarsPeriod.BarsPeriodType == BarsPeriodType.Second)
tickBuilt = false;
else
tickBuilt = true;
if(ChartControl != null)
textBrush = ChartControl.Properties.AxisPen.Brush;
countDown = 2;
anchorBar = false;
IsAutoScale = false;
IsOverlay = true;
ArePlotsConfigurable = false;
ZOrder = 0;
BarsRequiredToPlot = 0;
}
//----------------------------------------
if (State == State.Configure)
{
}
//------------------------------------
if (State == State.Terminated)
{
//Bars.Dispose();
/*innerAreaBrush.Dispose();
middleAreaBrush.Dispose();
outerAreaBrush.Dispose();*/
}
}//onstatechange
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Error in OnStateChange: Object reference not set to an instance of an object
Collapse
X
-
Error in OnStateChange: Object reference not set to an instance of an object
Getting this error from a converted indicator from NT7. Tried hiding some code but didnt work. Indicator wont show in indicator list from chart. When i open indicator panel the error is thrown. No compile errors.
Code:Last edited by ericson; 02-02-2017, 01:23 PM.Tags: None
-
Hello Ericson,
Thank you for your note.
Without the full code, I’m unable to test on my end. If you’d like to upload a full copy of the code, I can take a look and see if anything stands out. Otherwise I’d suggest seeing the following post on conversion as well as reading through the code breaking changes while converting the script from NT7.
To export a NinjaScript from NinjaTrader 8 do the following:- From the Control Center window select Tools -> Export -> NinjaScript...
- Click Add>Select the indicator>OK>Export.
- Then attach that file you saved; under My Docs>NT8>Bin>Custom>Select the downloaded .zip file.
Please let us know if you need further assistance.Alan P.NinjaTrader Customer Service
-
-
Hello ericson,
I was unable to identify the issue exactly but was able to reproduce.
In the support department at NinjaTrader we do not create, debug, or modify code for our clients. This is so that we can maintain a high level of service for all of our clients as well as our partners.
You can also contact a professional NinjaScript Consultants who would be eager to create or modify this script at your request or assist you with your script. Please let me know if you would like our business development follow up with you with a list of professional NinjaScript Consultants who would be happy to create this script or any others at your request.
Please let us know if you need further assistance.Alan P.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
574 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
332 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
101 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
553 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
551 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment