Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy template is saved empty from Strategy Analyzer

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

    Strategy template is saved empty from Strategy Analyzer

    Hi,

    When saving my strategy template from Chart, the file is correct. When saving the same template from Strategy Analyzer, the file is written with only the strategy header (1k vs 62k when not empty). See the empty header:
    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <StrategyTemplate>
      <StrategyType>NinjaTrader.NinjaScript.Strategies.BW4U.BWAAOTL</StrategyType>
      <Strategy />
    </StrategyTemplate>​
    When I copy only the properties to a new strategy skeleton, everything seems to work fine from both the chart and the Strategy Analyzer. Any ideas?

    #2
    Hello Shai Samuel,

    Do you see this happen with the SampleMACrossOver strategy? If so can you provide the specific steps to see that happen?

    Comment


      #3
      Thanks Jesse, this error only happened in my strategy. When I copy my strategy properties to a new strategy skeleton, this new strategy is saved OK from Strategy Analyzer,.

      I am using NT8 8.1.1.7.

      Can you give me ideas of which part of the code may affect this kind of behavior?

      Can this be connected to forum.ninjatrader.com/forum/ninjatrader-8/strategy-development/1263035-strategy-gui-categoryorder-is-not-always-respected ?​​

      Can you provide my code as a private message?

      Last edited by Shai Samuel; 08-04-2023, 12:47 PM.

      Comment


        #4
        Hello Shai Samuel,

        If you copy just the properties to a new strategy and it works that likely means one of the other parts of your strategy is causing the issue. You would need to further isolate what code is required to see that to get a better idea of what the problem is. I would suggest to use your original strategy and comment out all your logic and properties so you just have the strategy shell. Then uncomment the properties and make sure it now saves. If so you can then uncomment parts of the rest of your logic and test saving until you see the problem again. That would help to find the specific code and know what relates to the problem.

        You may also want to check the log tab or output window when you see the problem to see if any errors are being reported during the saving process.

        Comment


          #5
          Thank you Jesse. Nothing on the log. Switching off part of the code is a big task, as the strategy is over 2000 lines of code.

          Except the get and set properties, and the StrategyBaseConverter logic that I did copy to the new strategy, what kind of events and logic are fired when saving the template?

          Comment


            #6
            Hello Shai Samuel,

            Saving serializes the class so anything marked public will try to be saved. Without testing the code it would be a guess at what the problem is, the quickest way to test is going to be to comment out the code and check if it saves or not. The alternative would be to rebuild the script in a new empty script but that is an equal amount of work because you would have to bring parts of the script over and confirm if it works or not.

            Comment


              #7
              Jesse, if I understand correctly, the public classes that are saving serializes are the properties which are saved with no issue.

              I attache the new strategy that includes the properties and StrategyBaseConverter class to toggle the properties on and off. This copied strategy is saved with no issues.

              What other events are fired when the template is saved? I guess OnBarUpdate has nothing to do with it. So the relevant code should be a few OnStateChange events. Correct?
              Attached Files

              Comment


                #8
                Hello Shai Samuel,

                OnStateChange is run for saving, you can use a Print in each of the overrides to see which are called in various use cases.

                As I don't know what you programmed I can't make any suggestions on what to check other than commenting out your code and seeing which parts are related to the issue. Once you know what parts of the code relate to the problem you could make a small sample script using that part of the code if its not clear how to resolve it.

                Comment


                  #9
                  This was a tough one, but finally it's been solved.

                  The issue was, as you claimed, Jesse, a public variable at the strategy level. Solution: was changing it to protected/private. No public variable at the strategy level, which are not properties!

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by NullPointStrategies, Today, 05:17 AM
                  0 responses
                  44 views
                  0 likes
                  Last Post NullPointStrategies  
                  Started by argusthome, 03-08-2026, 10:06 AM
                  0 responses
                  124 views
                  0 likes
                  Last Post argusthome  
                  Started by NabilKhattabi, 03-06-2026, 11:18 AM
                  0 responses
                  65 views
                  0 likes
                  Last Post NabilKhattabi  
                  Started by Deep42, 03-06-2026, 12:28 AM
                  0 responses
                  42 views
                  0 likes
                  Last Post Deep42
                  by Deep42
                   
                  Started by TheRealMorford, 03-05-2026, 06:15 PM
                  0 responses
                  46 views
                  0 likes
                  Last Post TheRealMorford  
                  Working...
                  X