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!
See more
See less

Partner 728x90

Collapse

Error in OnStateChange: Object reference not set to an instance of an object

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    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:
    		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
    Last edited by ericson; 02-02-2017, 01:23 PM.

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

    Comment


      #3
      Here is a copy.
      Attached Files

      Comment


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


          #5
          Ok, i wont be needing a service at this time. Thank you.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by michi08, 10-05-2018, 09:31 AM
          5 responses
          741 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by The_Sec, Today, 02:29 PM
          0 responses
          2 views
          0 likes
          Last Post The_Sec
          by The_Sec
           
          Started by tsantospinto, 04-12-2024, 07:04 PM
          4 responses
          62 views
          0 likes
          Last Post aligator  
          Started by sightcareclickhere, Today, 01:55 PM
          0 responses
          1 view
          0 likes
          Last Post sightcareclickhere  
          Started by Mindset, 05-06-2023, 09:03 PM
          9 responses
          259 views
          0 likes
          Last Post ender_wiggum  
          Working...
          X