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 on calling "SetState" method : exception has been thrown

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

    Error on calling "SetState" method : exception has been thrown

    Hello,

    I have an error that I don't understand : Error on calling "SetState" method : exception has been thrown. Is it possible to have some helps ? Thanks

    Code:
    double Ouverture;
    double Cloture;
    private Series<double> Range2;
    double bup;
    double bdown;
    double inter;
    double sss;
    
    protected override void OnStateChange()
    		{
    			if (State == State.SetDefaults)
    			{
    				Description									= @"Enter the description for your new custom Indicator here.";
    				Name										= "VariabiliteAlpha";
    				Calculate									= Calculate.OnBarClose;
    				IsOverlay									= false;
    				DisplayInDataBox							= true;
    				DrawOnPricePanel							= true;
    				DrawHorizontalGridLines						= true;
    				DrawVerticalGridLines						= true;
    				PaintPriceMarkers							= true;
    				ScaleJustification							= NinjaTrader.Gui.Chart.ScaleJustification.Right;
    				//Disable this property if your indicator requires custom values that cumulate with each new market data event. 
    				//See Help Guide for additional information.
    				IsSuspendedWhileInactive					= true;
    				AddPlot(new Stroke(Brushes.Orange), PlotStyle.Bar, "Plot1");
    				AddPlot(Brushes.Orange, "Plot2");
    				AddPlot(Brushes.Orange, "Plot3");
    				 
    			}
    			else if (State == State.Configure)
    			{
    				Range2 = new Series<double>(this, MaximumBarsLookBack.Infinite);
    			}
    		}
    
    		protected override void OnBarUpdate()
    		{
    			Cloture = Close[0];
    			Ouverture = Open[0];
    			
    			Range2[0] = Cloture - Ouverture;
    			
    			if(CurrentBar>50) {
    			bup = Bollinger(Range2, 2, 20).Lower[0];
    			bdown = Bollinger(Range2, 2, 20).Lower[0];
    			}
    			
    			
    			Values[0][0] = Range2[0];	
    			
    		}

    #2
    Hello WalBen,

    What is the error message you are receiving?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      I also received this error log several time on NT8.0.4.0 & 8.0.5.0, never found on 8.0.3.1 and before with the same indicator.
      ERROR: Indicator '': Error on calling 'SetState' method: Object reference not set to an instance of an object.
      the error in trace file is the same, doesn't provide more detail.
      and my OnStateChange has no exception thrown. Really weird error.

      Comment


        #4
        Hello jjhou,

        The error indicates one of the variables has a null value.

        I've copied and pasted your code into a script and tested this and I was not able to produce an error.

        Are you able to reproduce an error using the test script I have exported and attached without making any modifications to this?

        As a tip, to export a NinjaTrader 8 NinjaScript to share to someone else (especially for testing) do the following:
        1. Click Tools -> Export -> NinjaScript...
        2. Click the 'add' link -> check the box(es) for the script(s) you want to include
        3. Click the 'Export' button
        4. Enter a unique name for the file in the value for 'File name:'
        5. Choose a save location -> click Save
        6. Click OK to clear the export location message

        By default your exported file will be in the following location:
        • (My) Documents/NinjaTrader 8/bin/Custom/ExportNinjaScript/<export_file_name.zip>


        Below is a link to the help guide on Exporting NinjaScripts.
        Attached Files
        Last edited by NinjaTrader_ChelseaB; 03-16-2017, 10:02 AM.
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by jeronymite, 04-12-2024, 04:26 PM
        3 responses
        43 views
        0 likes
        Last Post jeronymite  
        Started by frankthearm, Today, 09:08 AM
        4 responses
        9 views
        0 likes
        Last Post frankthearm  
        Started by yertle, Today, 08:38 AM
        5 responses
        15 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Started by adeelshahzad, Today, 03:54 AM
        3 responses
        16 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Started by bill2023, Yesterday, 08:51 AM
        6 responses
        27 views
        0 likes
        Last Post NinjaTrader_Erick  
        Working...
        X