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

Ninja cannot create strategy after recompilation

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

    Ninja cannot create strategy after recompilation

    Hello

    Steps to reproduce the issue
    1. Compile the strategy I attached
    2. Add the strategy to the chart and enable it
    3. Change source code of the strategy and recompile
    4. Disable strategy and enable it again
    5. There will be error "strategy no longer exists"

    The only solution I know is to restart Ninja. It slows down the development process drastically. I need to restart Ninja each time I change even 1 symbol in my source code

    I created a simple strategy to demonstrate the issue. The issue is related to collection class I used (see my CustomStrategyTimeWindowCollection).

    I run VS debugger and see the exception throws while strategy creation (see attachment)
    Attached Files

    #2
    Hello rfsettling,

    Thank you for your note.

    SetDefaults is only going to be ran once, even after a reload of ninjascript.

    If you were to move the following,

    Code:
    TradeTimeWindows = new CustomStrategyTimeWindowCollection();
    To State.Configure, does the issue still occur?

    I look forward to your reply.
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      If I move collection creation to Configure state, then this field is inaccessible in editor. So, it does not solve the issue

      Comment


        #4
        Hello rfsettling,

        It is suggested when making any changes to the strategy code that you remove the current instance of the strategy and add a new instance.

        There are no supported ways around this.

        Please let us know if you need further assistance.
        Alan P.NinjaTrader Customer Service

        Comment


          #5
          I tried. Removing and adding new instance do not help.
          As only I try to load strategy parameters from template, it drops with next error (see attachment)

          Steps to replicate:
          1. After recompilation remove strategy
          2. Add new strategy to chart and load parameters from template
          3. After clicking OK an exception appears

          So far only total Ninja restart helps. That's terrible
          Attached Files

          Comment


            #6
            Hello rfsettling,

            I am unable to to test the script.

            Did you write this strategy using the strategy builder then edit the file outside NinjaTrader?

            I look forward to your reply.
            Alan P.NinjaTrader Customer Service

            Comment


              #7
              I've attached newly created example. I created it via standard wizard and only added 1 class and 1 property for this class using stanard NT code editor

              The issue takes place with any custom class used for editing in Property Editor. After recompilation NT cannot copy values from old instance of this class to new instance
              Attached Files

              Comment


                #8
                Hello rfsettling,

                After a recompilation, you should remove the strategy from the strategies tab or chart and reapply a new instance.

                Please let us know if you need further assistance.
                Alan P.NinjaTrader Customer Service

                Comment


                  #9
                  Hello, Alan

                  I repeat once again - it does not help
                  After I remove and add new inctance of strategy I have to load my strategy settigns from tempate. As soon as I try to load parameters from template, new exception occurs, See my previous posts about this error

                  Comment


                    #10
                    Hello rfsettling,

                    If you place your MyPropertiesClass outside the strategy Namespace like the following example, does this resolve the issue?

                    The attached is similar to what you're trying to do.

                    I look forward to your reply.
                    Attached Files
                    Alan P.NinjaTrader Customer Service

                    Comment


                      #11
                      Unfortunately, not
                      The issue is not solved.

                      You showed example with indicator, but indicators have no such issue. If you try the same thing with a strategy, you will get error.

                      My steps are:
                      1. Add strategy to chart
                      2. Recompile
                      3. Remove strategy and add new instance (all is good so far)
                      4. In strategy propereties dialog click the link template->load and load any previously saved template
                      5. After pressing OK button error appears

                      Comment


                        #12
                        Hello rfsettling,

                        Please see Chelsea's forum post which provides a link that mentions how this can be done in a strategy.


                        Please let us know if you need further assistance.
                        Alan P.NinjaTrader Customer Service

                        Comment


                          #13
                          Still I do not understand how it might help me.

                          I already use type converters. As to serialization problem (which takes place here), there is no solution provided in that forum.

                          If I understand correctly, you suggest to change Ninja's standard serialization routine to custom implementation. I'm not aware how it is implemented in Ninja and how to change it. I see, that method CopyTo throws exception. But what I should do to prevent it?

                          I repeat, everything works fine if I restart Ninja. The problem occurs only after recompilation of the strategy. So, I am forced to restart Ninja every time I change even 1 symbol in my source code.
                          Attached Files

                          Comment


                            #14
                            Hello rfsettling,

                            Did you modify your code with the following, as mentioned at the provided link?

                            Note: The reference sample files on this page are written for an indicator using the IndicatorBaseConverter class, but the same key concepts are available to strategies by replacing the StrategyBaseConverter where noted in the sample code

                            The example has a example of how to serialize a collection, have you attempted to implement this?

                            I look forward to your reply.
                            Last edited by NinjaTrader_AlanP; 11-29-2017, 02:12 PM.
                            Alan P.NinjaTrader Customer Service

                            Comment


                              #15
                              I beg pardon, but it seems you're pushing me in all possible directions in a hope that something may help. Meanwhile time is ticking and the problem is not being solved.

                              Have you tried your own suggestion?

                              I tried it early before. And it does not work as always. I blocked serialization of my custom class and made serialization to string. The result is the same. Because the error occurs not during serialization/deserialization but at the moment of copying one strategy instance properties to another's

                              Modified source code in attachement
                              I ask you at least to replicate the issue and to see the problem on your side

                              I feel this is a dead-end and am searching for any other possible way to solve the problem. Maybe I can load template from my code. At least for testing it would be good solution. I found StrategyTemplate class which seems to be able to load strategy properties. My code would look something like that

                              Code:
                                          else if (State == State.Configure)
                                          {
                              #if __TESTING__
                                              StrategyTemplate.Load( here is the name of earlier saved template)
                              #endif
                                          }
                              If not, I appreciate any working solution which can save my time and spare me of restarting NT each time I change my code
                              Attached Files

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Christopher_R, Today, 12:29 AM
                              0 responses
                              9 views
                              0 likes
                              Last Post Christopher_R  
                              Started by sidlercom80, 10-28-2023, 08:49 AM
                              166 responses
                              2,235 views
                              0 likes
                              Last Post sidlercom80  
                              Started by thread, Yesterday, 11:58 PM
                              0 responses
                              3 views
                              0 likes
                              Last Post thread
                              by thread
                               
                              Started by jclose, Yesterday, 09:37 PM
                              0 responses
                              8 views
                              0 likes
                              Last Post jclose
                              by jclose
                               
                              Started by WeyldFalcon, 08-07-2020, 06:13 AM
                              10 responses
                              1,415 views
                              0 likes
                              Last Post Traderontheroad  
                              Working...
                              X