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

Exception - while running backtest

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

    Exception - while running backtest

    When backtest is running and
    one load template, this error is thrown.

    Attached Files

    #2
    Hello misova,

    In what state is BarsRequiredToTrade being set?

    May I see the code for each instance where this is set?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Definitely only in State.SetDefaults.
      Nowhere else.

      I expect, that problem is not setting the property itserlf,
      but aplying template should not be possible, during running backtest.

      Comment


        #4
        Hello misova,

        It is possible to apply a template before running a backtest so that the settings do not have to be setup each time.

        The BarsRequiredToTrade, however, is not a property that is saved with the template as this must be hard coded.

        Are you able to reproduce this behavior using the SampleMACrossOver script included with NinjaTrader?

        If not, may I have an export of your script to test this on my end?

        To export a NinjaTrader 8 NinjaScript 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.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          I tested thoroughly now,
          but I can't reproduce it now.

          Probably- I did not evaluate cause of the error correctly.
          an it isn't caused by aplying template.

          It happened to me again, but now I see, it happens during my development work:
          during changes of code, compilations and backtesting together.
          Somewhere - in the mess of development work I see these exceptions in the Log.

          Unable to create instance of NinjaScript 'ReversalOfBigCandleStrategy'. Most likely either the implementation no longer exists, there is no default constructor defined, the default constructor does not work correctly, or the 'OnStateChange' implementation for State=SetDefaults is flawed: System.InvalidOperationException: 'BarsRequiredToTrade' cannot be set from this state. Please see the Help Guide article on 'BarsRequiredToTrade' for more information.

          And exactly here, the bug happens:

          When this happens, I see, that ReversalOfBigCandleStrategy is missing from the compiled strategies, despite, the file is physically there and compilation went fine.

          This explains, that something - after successful compilation goes wrong = some process, that follows successful compilation:
          • maybe some reloading of classes,
          • or maybe having old strategies running, while compiling their new version - where new version is not compatible... (just thinking about options)


          What fixes the problem:
          After I restart NT8, and compile again, everything is fixed and NT8 works just fine.

          I know,problem that happens, but exact conditions are tough to identify fow now.
          Lets see, If I can spot more helpful details during my next work
          Last edited by misova; 05-27-2017, 09:40 AM.

          Comment


            #6
            Hello misova,

            With the error:
            "System.InvalidOperationException: 'BarsRequiredToTrade' cannot be set from this state"

            This looks to be related with a collection editor.

            Do you have a collection editor in your script?

            Please create and export a reduced version of your script that only contains bare minimum code to reproduce this error and post the export with your next post.

            To export a NinjaTrader 8 NinjaScript 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.



            Regarding the behavior where the file is being excluded from the project, I would be highly interested in know the sequence of steps that led to this behavior as I am unable to reproduce.
            (I'm wondering if this may also be related to the error message and I would like to test with your reduced version script.)
            Chelsea B.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by jeronymite, 04-12-2024, 04:26 PM
            3 responses
            39 views
            0 likes
            Last Post jeronymite  
            Started by bill2023, Today, 08:51 AM
            2 responses
            15 views
            0 likes
            Last Post bill2023  
            Started by sidlercom80, 10-28-2023, 08:49 AM
            167 responses
            2,260 views
            0 likes
            Last Post jeronymite  
            Started by warreng86, 11-10-2020, 02:04 PM
            7 responses
            1,362 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by Perr0Grande, Today, 08:16 PM
            0 responses
            5 views
            0 likes
            Last Post Perr0Grande  
            Working...
            X