No announcement yet.

Partner 728x90


Strategy Template no parameters?

  • Filter
  • Time
  • Show
Clear All
new posts

    Strategy Template no parameters?

    I attached a strategy template for your Sample MA Crossover strategy, which does save the parameter values into the XML template file. Notice in this file I changed Fast to 1 and Slow to 989. These values are stored in the <Strategy> group of the file.

    I have a strategy I created from the Strategy Wizard and added several parameters like they are in Sample MA Crossover. However, when I save the template for mine, there is no Strategy group... it simply looks like this:

    <Strategy />

    Which of course does not save any of the parameter values. What line(s) of code in the Sample MA Crossover causes it to store the <Strategy> group correctly so I can add that to mine?

    Attached Files
    NinjaTrader Ecosystem Vendor - Logical Forex

    Hello cassb, and thank you for your question. To answer it literally, these property tags

            [Range(1, int.MaxValue), NinjaScriptProperty]
            [Display(ResourceType = typeof(Custom.Resource), Name = "Fast", GroupName = "NinjaScriptStrategyParameters", Order = 0)]
    Are responsible for letting the serializer know to look at these values. This said, since none of your properties are exporting, I would take a closer look at your Xml serialization after reviewing this page of the help guide on the topic, as some values need a little more work to serialize than what's in the SampleMACrossover strategy. (the "Using brushes defined on the user interface" section)

    More general information on working with XML output is here,

    I recommend starting to debug this by commenting out all references to any property not a basic type like an integer, double, boolean, this sort of thing. Once you can get this minimal set exporting properly, you can work on serializing your more advanced types such as brushes.

    We are happy to help with any questions that come up.
    Jessica P.NinjaTrader Customer Service


      Thanks, Jessica. So here is an example that's not being saved to the XML file:

      [Range(1, int.MaxValue)]
              [Display(Name="Tick Target", Description="Ticks-of-Profit value to exit a trade", Order=10, GroupName="Parameters")]
              public int TickTarget
              { get; set; }
      Can you tell me what is wrong with this property and why it's not saved in the <STRATEGY></STRATEGY> group?

      NinjaTrader Ecosystem Vendor - Logical Forex


        Have you made sure that this is the only property in your script? If any of your properties are not serializing, it may be that none of your properties are serializing.

        In the attached script your code serializes on my end. We can see TickTarget in the attached template, retrieved from (My) Documents\NinjaTrader 8\templates\Strategy .

        I recommend, if you observe the same thing on your end, using the attached script as a debugging tool. You can add your properties one at a time until you can determine which is not serializing.
        Attached Files
        Jessica P.NinjaTrader Customer Service


          None of them are serializing. I have over 20 parameters and the <STRATEGY> group is empty. What code causes the STRATEGY group to populate?
          NinjaTrader Ecosystem Vendor - Logical Forex


            Since your platform and ours are behaving differently, since the code you sent us serialized as evidenced by the template we returned to you along with the code we returned to you, and we are assuming you tested the code sample I returned to you, we will need to determine what is occurring with your platform before we can proceed further. Can you send an e-mail to platformsupport[at]ninjatrader[dot]com so that we can investigate further?

            Alternatively, we recognize your time is valuable. Please follow these instructions to create a clean environment to test your code compiles in. Please let us know if your code is unable to serialize even in a clean environment :

            • Download a fresh copy of NinjaTrader 8 from
            • Close NinjaTrader 8
              • To ensure NinjaTrader is closed completely, please press the windows key (to the left of the space bar) and the letter r at the same time, and type in
                taskkill /f /im NinjaTrader.exe
                and press enter
            • Rename your (My) Documents\NinjaTrader 8\db\NinjaTrader.sdf file to something unique. I prefer names that include today's date
            • Rename your (My) Documents\NinjaTrader 8 folder to something else that is unique. I prefer names that include today's date.
            • Use the installer you downloaded to uninstall, and then reinstall, NinjaTrader 8
            • Copy these files and folders from your old, renamed (My) Documents\NinjaTrader 8 folder to your new folder. If asked to replace files, always select "yes"
              • Config.xml
              • UI.xml
              • db\NinjaTrader.sdf
            • Start NinjaTrader 8. You will receive some dialogs about Ninja being unable to start because it needed to recompile some dlls. OK out of these dialogs
            • Start NinjaTrader 8 once more
            Jessica P.NinjaTrader Customer Service


              Yes, the STRATEGY tag in your example code, which I saved a Default.xml template looks like this:

                  <Example1682071 xmlns:xsd="" xmlns:xsi="">
                    <Lines />
                    <Plots />
                      <Max xsi:type="xsd:int">0</Max>
                      <Min xsi:type="xsd:int">0</Min>
                      <Name />
                      <ParameterTypeSerializable>System.Int32, mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089</ParameterTypeSerializable>
                    <Template />
                    <TradingHoursSerializable />
              The STRATEGY tag in my strategy, with the same Property and several others, looks like this:

              <Strategy />
              So, what is in your example that causes it to save the run-time parameters that is apparently not in my code? Can you look at your Kernel or core NT8 code and find out what it's looking for when generating a strategy template file that causes it to populate the STRATEGY tag with run-time variables? I can't debug your internal code, so you'll need to let me know if you could, please.

              NinjaTrader Ecosystem Vendor - Logical Forex


                I am glad the example code I sent you compiled successfully, and serialized properly. If you examine the code, you will see that exactly the code you sent us was added to this indicator.

                This means that

                • NinjaTrader is capable of serializing properly
                • The code samples we traded work properly

                Since your code in your strategy is not serializing, we must conclude that the reason is in the code you have.

                I need to emphasize this. The reason is not that the code sample you sent us, or the majority of your code, was written incorrectly. The code you sent us was written correctly. We determined this already. Examining differences between our code and yours will not resolve this query.

                As I mentioned previously, serializing is "all or nothing" . Since your strategy template is completely empty, this means that a piece of your strategy is preventing the other parts of your strategy, which are correctly written and would otherwise work successfully (as we demonstrated to ourselves), from serializing.

                We would be happy to demonstrate the debugging process. I believe to most successfully do this, based on our conversation, it would be best if we had a copy of your code to demonstrate with. Code copies are not retained and this would only be used to produce a video sent to you privately. To send it privately, please contact platformsupport[at]ninjatrader[dot]com referencing attn:NinjaTrader_JessicaP and 1682701 in the subject line of your e-mail. This code would not need any trade logic; it would just need strategy parameters that are not serializing properly.
                Last edited by NinjaTrader_JessicaP; 03-24-2017, 08:36 AM.
                Jessica P.NinjaTrader Customer Service


                  OK, no problem. I'll play around and see if I can figure it out then. I was just hoping that you could search for <STRATEGY> in your core code set and see where/when/why/how it creates that tag in the XML.

                  NinjaTrader Ecosystem Vendor - Logical Forex


                    While I have this capability, the missing piece that we are unable to see, the way you are serializing all your variables, is critical to understanding why your code is not serializing. It is very easy to create a complicated object, like a Brush (which is why I linked the documentation for brush serialization), in a way which does not properly marshal this object. Since there are innumerably many ways to create objects that do not marshal correctly, we can not determine looking at our own code why your strategy will not serialize. And, since any incorrectly marshalled object will prevent serializing, looking at correctly serializing objects will not be useful to us.

                    Please let us know if there are any other ways we can help.
                    Jessica P.NinjaTrader Customer Service


                      OK thank you! I just sent you an email with my complete list of Properties in the code. Maybe you can see which one of them might be preventing serialization.

                      NinjaTrader Ecosystem Vendor - Logical Forex


                        Thank you Bryan. I have followed up via e-mail.
                        Jessica P.NinjaTrader Customer Service


                        Latest Posts


                        Topics Statistics Last Post
                        Started by nikorrriko, Today, 04:42 PM
                        0 responses
                        Last Post nikorrriko  
                        Started by sgordet, Today, 02:24 PM
                        0 responses
                        Last Post sgordet
                        by sgordet
                        Started by patricia70, Today, 01:00 PM
                        0 responses
                        Last Post patricia70  
                        Started by Guido 01, 07-17-2018, 02:30 AM
                        8 responses
                        Last Post pfsmedical  
                        Started by cjanau, Today, 11:07 AM
                        0 responses
                        Last Post cjanau
                        by cjanau