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

Back testing and optimization - On Bar Update Error

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

    Back testing and optimization - On Bar Update Error

    Hello,

    I'm new to the NinjaTrader community and could use some assistance. I'm working on building an automated strategy with the strategy builder, but having some challenges. After building it in the strategy builder, enabling it, it seems to work just fine without errors. However, when I move to the strategy analyzer and try to either backtest and/or optimize I receive two OnBarUpdate Errors and it disables the analysis.

    Error 1: Indicator ":Error on calling 'OnBarUpdate' method on bar ): Object reference not set to an instance of an object
    Error 2: Strategy Error on call'OnBarUpdate' method on bar 2544: You are accessing an index with a value that is invalid since it is out-of-range.

    That said, I have attempted to edit the script multiple ways to eliminate the error.

    The original script from the builder: ( I received the above errors)

    if (BarsInProgress ! = 0)
    return;

    if (CurrentBars[0] < 1)
    return;

    Variation of the script 1: ( I received the above-forementioned errors)

    if (CurrentBar < 1)
    return;

    if (Close[0] > Close[1])


    The script as it stands now: ( I received the above-forementioned errors)

    if (Close[0] > Close[Math.Min(CurrentBar, 1)])

    Here's where I thought it got interesting, but still receiving an error; I added a line to test the range if you will, and the error code changed to state that the OnBarUpdate method on bar 10856.

    if (CurrentBar < 1)
    return;

    if (CurrentBars [0] < 10000)
    return;

    if (Close[0] > Close[1])

    To continue with that logic, I changed the value from incrementally from 10,000 working my way up to 50,000. At 50,000 the strategy error disappeared and I was left with just the indicator error.

    My question is this, is there a way I can get around these errors so that I can properly run the analyzer? I've attached a printed copy of my current script. Any help is much appreciated. Thank you
    Attached Files

    #2
    Hello Lowerlevel1,

    As a tip, 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


    In the script, there are some indicators being called. These indicators may be having errors. If the indicator encounters an error, it will be null in the strategy and cause an 'Object reference not set to an instance of an object' error.

    Also, below is a link to a forum post on indexing errors.
    https://ninjatrader.com/support/foru...13#post1048513

    And a link to a forum post that demonstrates using prints to understand behavior. You can use prints throughout the script too see where the code stops evaluating.


    What line of code in the indicator is causing the error?
    Last edited by NinjaTrader_ChelseaB; 02-09-2020, 03:24 PM.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Chelsea B.

      Thank you for your reply. Attached is the zip file from the export.
      Attached Files

      Comment


        #4
        Hello Lowerlevel1,

        I am providing the steps to export a script for you to use in the future.

        I was not able to confirm, what line of code in the indicator is causing the error in the indicator?


        Please note, while I can assist you while you debug your script, unfortunately, in the support department at NinjaTrader it is against our policy to create, debug, or modify, code or logic 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 Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like our business development follow up with you with a list of affiliate consultants who would be happy to create this script or any others at your request.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_ChelseaB View Post
          Hello Lowerlevel1,

          I am providing the steps to export a script for you to use in the future.

          I was not able to confirm, what line of code in the indicator is causing the error in the indicator?


          Please note, while I can assist you while you debug your script, unfortunately, in the support department at NinjaTrader it is against our policy to create, debug, or modify, code or logic 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 Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like our business development follow up with you with a list of affiliate consultants who would be happy to create this script or any others at your request.
          Hi ChelseaB. Thank you again for the help and I understand your position. That said, in your last response, you stated that "I am providing the steps to export a script for you to use in the future." To that end, I did not see a link to anything in your reply.

          Comment


            #6
            Hello Lowerlevel1,

            Oh, I was just referring to post #2. Just a tip for the future, as exporting means any dependencies will be included and any receiver can easily import it. I was able to just copy and paste from the pdf you posted.
            Chelsea B.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by WHICKED, Today, 12:56 PM
            2 responses
            15 views
            0 likes
            Last Post WHICKED
            by WHICKED
             
            Started by Felix Reichert, Today, 02:12 PM
            0 responses
            1 view
            0 likes
            Last Post Felix Reichert  
            Started by Tim-c, Today, 02:10 PM
            0 responses
            1 view
            0 likes
            Last Post Tim-c
            by Tim-c
             
            Started by cre8able, Today, 01:16 PM
            2 responses
            9 views
            0 likes
            Last Post cre8able  
            Started by chbruno, 04-24-2024, 04:10 PM
            3 responses
            49 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Working...
            X