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 log "Unable to create instance of NinjaScript"

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

    error log "Unable to create instance of NinjaScript"

    Hello,

    When I run NT application and start a my strategy from the Strategy Control (right click->new) all my strategies are displayed.
    After updated or compilation of my strategy I try to start a my strategy from the Strategy Control (right click->new) the updated strategy disappeared.
    I log message Is:

    2020-12-04 08:12:57:710|3|4|Unable to create instance of NinjaScript 'KlFibLvl2Stg'. 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.
    at NinjaTrader.NinjaScript.StrategyBase.set_BarsRequi redToTrade(Int32 value)
    at NinjaTrader.NinjaScript.StrategyBase.CopyTo(NinjaS cript ninjaScript)
    at NinjaTrader.Gui.NinjaScript.StrategyRenderBase.Cop yTo(NinjaScript ninjaScript)
    at NinjaTrader.NinjaScript.NinjaScript.Clone()
    After closing NT App. and running it again every thing is OK. I tried to investigate this issue , and it seems that it happening in third instance of NinjaScript Lifecycle.

    Sincerely, Kobi
    Attached Files

    #2
    Hello levikNT,

    Are you seeing this only with your strategy or with all strategies?

    If this is in relation to something you programmed it may relate to the code being used. The error you are getting can happen for a variety of reasons, its possible this could relate to custom inheritance or complex public properties which cannot be recreated. If this is something you programmed we would likely need a sample of the code used to further address the question.

    I look forward to being of further assistance.

    JesseNinjaTrader Customer Service

    Comment


      #3
      Hello Jesse,

      Thank you for your response.

      I think that it related to public properties.
      I will check my code again.

      Sincerely, Kobi

      Comment


        #4
        Hello levikNT,

        Public properties are certainly an area where you can get this type of error. If you narrow down what property this is happening with we can take a look at that code if you are unsure why.

        Please let me know if I may be of additional assistance.

        JesseNinjaTrader Customer Service

        Comment


          #5
          Hello Jesse,

          Thank you for your response,

          I could not solve the problem.
          My code is made up from a lot of files so I have attached an example template of my strategy.


          1. Each indicator has a NinjaScriptProperty which is a class called IndCnfg.
          2. My strategy also has NinjaScriptProperty which is a class called StgCnfg that contains the IndCnfg for each indicator that the strategy uses.
          Each strategy inherits from a basic class that is responsible for managing the strategy
          4. The strategy creates StgCnfg in State == State.SetDefaults
          When the StgCnfg creates within it the IndCnfg of the indicators it uses.

          The scenario does not happen all the time, but when it does it come back.

          As I mentioned after updating the app and after strategy's compilation I try to start my strategy from the Strategy Control (right click->new) and my strategy disappeared.

          If I remark the StgCnfg public NinjaScriptProperty than my strategy appears again.
          if I do not remark StgCnfg public NinjaScriptProperty and close NT application and open it again there is no problem.

          Thread1131071.zip


          Sincerely,Kobi





          Comment


            #6
            Hello levikNT,

            The NinjaScriptProperty attribute should not be needed for those properties. I don't see you are using the indicator in the strategy to where you would need that to be in the constructor. That adds the property to the constructor on Indicator properties for the NinjaScript generated code. In the strategy it would mark optimization properties.

            if this is working when not using the NinjaScriptProperty I would suggest to go that route and just make a public property. The strategy could set the Indicators public property if it needs to when calling the indicator instead of passing the object to the constructor.

            I look forward to being of further assistance.



            JesseNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by ZenCortexCLICK, Today, 04:58 AM
            0 responses
            2 views
            0 likes
            Last Post ZenCortexCLICK  
            Started by sidlercom80, 10-28-2023, 08:49 AM
            172 responses
            2,280 views
            0 likes
            Last Post sidlercom80  
            Started by Irukandji, Yesterday, 02:53 AM
            2 responses
            17 views
            0 likes
            Last Post Irukandji  
            Started by adeelshahzad, Today, 03:54 AM
            0 responses
            4 views
            0 likes
            Last Post adeelshahzad  
            Started by Barry Milan, Yesterday, 10:35 PM
            3 responses
            13 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Working...
            X