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

Object reference not set to an instance of an object.... ERROR

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

    Object reference not set to an instance of an object.... ERROR

    Hello.

    I am creating an indicator that references another indicator. I got it working, and it did just what I wanted it to.

    Then I restarted ninja and BAM!!! I get the error shown in the picture.

    It compiles fine, but I get the error and the indicator just won't plot.

    The error I am getting seems to be related to THIS thread HERE. I really don't understand the problem?



    My code snippet is below, and it seems the problem lies in the initialization of the dataseries I have called "swingRelation." I've commented everything else out in the void onBarUpdate block, and the problem occurs when I get to that condition that deals with that data series.

    Code:
    namespace NinjaTrader.Indicator
    {
        /// <summary>
        /// Enter the description of your new custom indicator here
        /// </summary>
        [Description("This indicator kicks the market's ass")]
        public class FPCJTrend : Indicator
        {
            #region Variables
            //#####################################################################
            //Variables for PriceActionSwing
    	private int swingSize = 2;
            private SwingTypes swingType = SwingTypes.Standard;
            private int dtbStrength = 15;
            private IDataSeries swingRelation = null;
            private IDataSeries swingTrend;
            private bool seeRelation = false;
            private bool useOldTrend = true;
            private bool paintBars = true;
            private int oldTrend = 0;
            private Color upTrendColour = Color.Green;
            private Color dnTrendColour = Color.Red;
            private Color noTrendColour = Color.Gray;
    		
    	//Variables for IchiCloud
    	private int periodFast = 9;			// Default setting for PeriodFast
            private int periodMedium = 26;		// Default setting for PeriodMedium
            private int periodSlow = 52;		// Default setting for PeriodSlow
    		
    	//Variables independant to FPCJTrend
    	private bool blueCloud = false;
    	private bool redCloud = false;
    	private int ichiBuffer = 6;
    		
            //#####################################################################
            #endregion
    
            /// <summary>
            /// This method is used to configure the indicator and is called once before any bar data is loaded.
            /// </summary>
            protected override void Initialize()
            {
                
    	    Add(new Plot(new Pen(Color.Firebrick, 20), PlotStyle.Square, "DoubleTop"));
                Add(new Plot(new Pen(Color.Red, 20), PlotStyle.Square, "DownTrend"));
                Add(new Plot(new Pen(Color.Gold, 20), PlotStyle.Square, "NoWhere"));
                Add(new Plot(new Pen(Color.Green, 20), PlotStyle.Square, "UpTrend"));
                Add(new Plot(new Pen(Color.Lime, 20), PlotStyle.Square, "DoubleBottom"));
    			
                CalculateOnBarClose = true;
                Overlay				= false;
            }
    
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {	
    			
    			
    	//if (CurrentBar < swingSize)		
             //return;							//Do we have enough bars for PriceActionSwing
    			
    	//if ((CurrentBar < periodMedium) || (CurrentBar < periodFast))
            //return;							// Do we have enough bars for Ichi Calculation
    			
    	if (CurrentBar < 1)
                {
                    if (swingRelation == null && seeRelation)
                        swingRelation = PriceActionSwing(Input, dtbStrength, swingSize, swingType).SwingRelation;
    				
                    if (swingTrend == null && !seeRelation)
                        swingTrend = PriceActionSwing(Input, dtbStrength, swingSize, swingType).SwingTrend;
    				
                }
    			
    			
    		double spanA = IchiCloud(Input, periodFast, periodMedium, periodSlow).SenkouSpanA[0];
    		double spanB = IchiCloud(Input, periodFast, periodMedium, periodSlow).SenkouSpanB[0];
    						
    		if(spanA > spanB)
    			{
    				blueCloud = true;	
    				redCloud = false;
    			}
    			
    		if(spanA < spanB)
    			{
    				redCloud = true;
    				blueCloud = false;
    			}
    			/*
    		if(redCloud == true)
    			{
    				DrawArrowDown("arrow"+CurrentBar, true, 0, Low[0]+12*TickSize, Color.Red);	
    			}
    		//Print(redCloud);
    			*/
    			
    			///*
                if (swingRelation[0] == 1 && blueCloud == true && Low[0] > spanA-ichiBuffer*TickSize)
    			{
    				//UpTrend.Set(Close[0]);
    				//DrawArrowUp("arrow"+CurrentBar, true, 0, Low[0]-12*TickSize, Color.Green);
    				//Print("hi");
    			}
                
    			else if (swingRelation[0] == -1 && redCloud == true && High[0] < spanA+ ichiBuffer*TickSize)
    			{
    				//DownTrend.Set(1);
    				//DrawArrowDown("arrow"+CurrentBar, true, 0, Low[0]+12*TickSize, Color.Red);
    			}
    			
    			else
    			{
    				//NoWhere.Set(1);	
    			}
    
    ............
    Attached Files

    #2
    I may have figured something out.

    I will post back if I need further help.

    Thanks!

    Comment


      #3
      forrestang, sounds good. If you'd like additional information about this error, please see this link - http://www.ninjatrader.com/support/f...ead.php?t=4226.
      AustinNinjaTrader Customer Service

      Comment


        #4
        Your dataSeries are wrongly declared.

        IDataSeries is an interface. The dataSeries object is declared simply as DataSeries thus:

        Code:
        private [COLOR="Red"][B]DataSeries[/B][/COLOR] swingRelation = null;

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by judysamnt7, 03-13-2023, 09:11 AM
        4 responses
        57 views
        0 likes
        Last Post DynamicTest  
        Started by ScottWalsh, Today, 06:52 PM
        4 responses
        36 views
        0 likes
        Last Post ScottWalsh  
        Started by olisav57, Today, 07:39 PM
        0 responses
        7 views
        0 likes
        Last Post olisav57  
        Started by trilliantrader, Today, 03:01 PM
        2 responses
        19 views
        0 likes
        Last Post helpwanted  
        Started by cre8able, Today, 07:24 PM
        0 responses
        9 views
        0 likes
        Last Post cre8able  
        Working...
        X