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

Strategy builder code error

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

    Strategy builder code error

    Hello,

    I am trying to backtest a strategy I built fully within the strategy builder, but when I run the backtest I get this error:

    Strategy 'EnvelopeReversion': Error on calling 'OnStateChange' method: Object reference not set to an instance of an object.

    Not really sure what do to since it was all done in the SB?

    Thanks

    #2
    Very clear that some of the object is not called property / not declare with a value.\

    The most simple mistake that everyone will make is :
    private order stoplong;

    if (stoplong.OrderState == OrderState.working)

    This statement will be false.

    And you need to be add stoplong != null in the infront.


    Comment


      #3
      The answer that I posted maybe not your problem.

      With too less info you given, I just able to tell you what roughly idea is.

      If you mind to share your file to people.
      Then please double check with the variable you declare by your own.

      Comment


        #4
        Hello MisterGee,

        The error is stating one or more variables has a null value.

        If there are any indicators being called that are not able to load, this could cause this behavior.

        If there are any data series added that are no able to load, this could cause this behavior.

        Please provide the script causing the error.

        To export a NinjaTrader 8 NinjaScript so this can be shared and imported by the recipient do the following:
        1. Click Tools -> Export -> NinjaScript...
        2. Click the 'add' link -> check the box(es) for the script(s) and reference(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.
        http://ninjatrader.com/support/helpG...-us/export.htm

        Once exported, please attach the file as an attachment to your reply.

        (It is also helpful to make a copy of the script and remove all code that does not cause the error, to reduce the script to only containing the code that causes the error. Or to start a new test script, and build this one step at a time, testing after each step, to identify which step is causing the error)
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Thanks I'll get it sent over. I was just concerned because it was all done with the strategy builder! I thought that would remove all my own error producing ways!

          Comment


            #6
            For an update on this thread,

            The script was attempting to set indicator prices in State.Configure to the stop loss and profit targets before the indicators have begun processing data.
            https://ninjatrader.com/support/foru...tr#post1142942
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Oh my goodness. Doh! I will unlock the code and set the prices in main. Thanks!

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Waxavi, Today, 02:10 AM
              1 response
              17 views
              0 likes
              Last Post NinjaTrader_LuisH  
              Started by Kaledus, Today, 01:29 PM
              5 responses
              13 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Started by Waxavi, Today, 02:00 AM
              1 response
              12 views
              0 likes
              Last Post NinjaTrader_LuisH  
              Started by alifarahani, Today, 09:40 AM
              5 responses
              23 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Started by gentlebenthebear, Today, 01:30 AM
              3 responses
              17 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Working...
              X