Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Suddenly unable to save temaplates

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

    Suddenly unable to save temaplates

    For no known reason, when i save my templates in strategy analyzer, they all save as 1KB:

    <?xml version="1.0" encoding="utf-8"?>
    <StrategyTemplate>
    <StrategyType>NinjaTrader.NinjaScript.Strategies .S calpClass_Subclass_MCL</StrategyType>
    <Strategy />
    </StrategyTemplate>

    Why would this happen?​

    #2
    Hello Skifree,

    I don't experience this issue when I test it on my end. I assume the strategy settings are not saved in the template (because of the 1 KB size).

    Do you experience the issue if you test saving a template for the 'Sample MA crossover' strategy? If not, could it be the issue happens only for a certain strategy?

    When was the last time you were able to save a template successful? Were there any changes in NinjaTrader Desktop after this?

    Comment


      #3
      Did you check for errors in your trace file?

      Comment


        #4
        Fortunately I seem to have found it. It seems I can't declare this value? commenting it out solves the problem. Why doesn't saving a template just save the configurable parameters?

        private DateTime lastCalculationTime = Core.Globals.MinDate;

        Comment


          #5
          Hello Skifree,

          Thanks for your notes.

          What version of NinjaTrader are you using? Please provide the entire version number. This can be found under Help -> About (Example: 8.?.?.?)​

          I have created a copy of the SampleMACrossover strategy and added that line of code to the script.

          When testing creating a strategy template in the Strategy Analyzer, I see the template is successfully saved and loads with the saved values.

          Please provide us with a simple reduced test script that demonstrates the behavior you are reporting and the exact steps you are taking to reproduce the behavior using the test script.

          Note that a reduced copy refers to a copy of the script that contains the minimum amount of code needed to reproduce the issue. All other code is commented out or removed.

          To create a copy of your script to modify, open a New > NinjaScript Editor, select your script, right-click in the Editor, select 'Save as', name the script, and click OK.​

          To export the script, go to Tools > Export > NinjaScript AddOn.

          I look forward to assisting further.
          <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

          Comment


            #6
            This is happening yet again, and it's a monumental headache to debug because I didn't realize it for 3 days. Can you please add a feature request to at least present an error when the XML saves as 1 KB like this?

            <?xml version="1.0" encoding="utf-8"?>
            <StrategyTemplate>
            <StrategyType>NinjaTrader.NinjaScript.Strategies .O rganizedStrategy.General</StrategyType>
            <Strategy />
            </StrategyTemplate>

            Nothing will load, and nothing will save, and there are no errors!​

            Comment


              #7
              after a painful debug, this is the issue and I have NO idea why. With implementation code commented out, this custom series as public causes templates to save as empty xml

              public Series<double> bbWidthSeries;
              public Series<double> EMA3_roc_Series;
              public Series<double> EMA200_roc_Series;
              public Series<double> VWAP_EMA_Delta_Series;​

              This works fine as private? Why?

              private Series<double> bbWidthSeries;
              private Series<double> EMA3_roc_Series;
              private Series<double> EMA200_roc_Series;
              private Series<double> VWAP_EMA_Delta_Series;​

              Comment


                #8
                Hello Skifree,

                A Series<double> cannot be saved in xml. These must use the XmlIgnore() attribute.

                There will be an error on the Log tab of the Control Center when an xml file cannot be saved.

                An xml file stores information as text. This file type is a specially formatted file that uses markup language tags to organize the text in storage. Values used in an application that are not text, have to be converted from the original object type to text that can be saved in the text files, and then restored from text back to the original object. This process is known as serialization.

                NinjaTrader automatically attempts to save all variables using the ‘public’ access modifier to xml workspaces and templates. This saves the values the user has set for the inputs in the Indicator or Strategy window when restarting NinjaTrader, closing and opening workspaces, and when applying templates.

                NinjaTrader auto-converts, to text, simple object types and some NinjaScript specific object types which are automatically serialized by NinjaTrader. Object types that do not easily convert into text strings cannot be saved in the xml file as text, causing an error.

                Data types that do not need serialization
                • string
                • bool
                • int, double, float (or number type)
                • enum
                • SimpleFont
                • Stroke

                If the object type is in the list above, applying the XmlIgnore attribute and serializing is not required.

                Public variables of all other data types will need the [XmlIgnore] attribute applied to prevent the variable from being included from being saved in the xml file, resulting in an error.

                Help guide: NinjaScript > Language Reference > Common > Attributes > XmlIgnoreAttribute
                ERROR: Could not save indicator 'MyCustomIndicatorName:' There was an error reflecting type 'NinjaTrader.NinjaScript.Indicators.MyCustomIndica torName'


                This error appears on the Log tab of the Control Center when saving xml files, such as workspaces or templates, with a script that has public variables that are not easily converted to text and need the XmlIgnore() attribute applied. This error will prevent the indicator or strategy from being saved with the workspace or template. Serializing


                Some object types, such as Brushes, TimeSpans, and custom classes, can be converted to a string and then converted back to the original object type, which can be serialized into the xml file. Serializing means to convert the object into text that can be saved in a xml file, and then the text read back from the file as the workspace is opened or template applied and the value restored to the original object data type. This is done by using a secondary public string variable that can hold that converted value as text for saving in the workspace. In the ‘get’ of the secondary string variable, the object is converted to a string. Within the ‘set’ the string returned from xml is converted back to the original object.

                The help guide provides a detailed code sample on serializing Brush (color) inputs.

                Help guide: NinjaScript > Educational Resources > Tips > User Definable Color Inputs

                Help guide: NinjaScript > Educational Resources > Working with Brushes > Using brushes defined on the user interface

                It may be desired to make a variable public for the express purpose of accessing the object from a hosting script or window, that makes calls this indicator to return values or objects.

                Public variables that are not intended to be an input for the user to set, or are not convertible to a string and then back, cannot not be serialized with custom code. These still must have the [XmlIgnore] attribute applied to prevent errors when being saved in xml.

                Object types that cannot be serialized and restored:
                • Series<T>
                • Order
                • Execution
                • Trade
                • Position
                ​Serialize a Brush code sample
                Code:
                [XmlIgnore()]
                public Brush BorderBrush
                { get; set; }
                
                [Browsable(false)]
                public string BorderBrushSerialize
                {
                get { return Serialize.BrushToString(BorderBrush); }
                set { BorderBrush = Serialize.StringToBrush(value); }
                }

                Serialize a TimeSpan code sample
                Code:
                [XmlIgnore]
                public TimeSpan OpenTime
                { get; set; }
                
                [Browsable(false)]
                public string OpenTimeSerialize
                {
                get { return OpenTime.ToString(); }
                set { OpenTime = TimeSpan.Parse(value); }
                }

                Serialize a DateTime code sample
                Code:
                [XmlIgnore]
                public DateTime StartDateTime
                { get; set; }
                
                [Browsable(false)]
                public string StartDateTimeSerialize
                {
                get { return StartDateTime.ToString(); }
                set { StartDateTime= DateTime.Parse(value); }
                }

                Serialize an Instrument code sample
                Code:
                [XmlIgnore]
                [TypeConverter(typeof(NinjaTrader.Gui.Tools.Instrum entSelector))]
                public Instrument InstrumentInput
                { get; set; }
                
                [Browsable(false)]
                public string InstrumentInputSerialize
                {
                get { return InstrumentInput.FullName; }
                set { InstrumentInput = Instrument.GetInstrument(value); }
                }​
                Serialize an Account code sample
                Code:
                private Account selectedAccount;
                
                protected override void OnStateChange()
                {
                if (State == State.SetDefaults)
                {
                AccountName = “Sim101”; // optionally set a default account
                }
                else if (State == State.DataLoaded)
                {
                selectedAccount = Account.All.FirstOrDefault(a => a.Name == AccountName);
                }
                }
                
                [TypeConverter(typeof(NinjaTrader.NinjaScript.Accou ntNameConverter))]
                public string AccountName
                { get; set; }​
                Chelsea B.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                599 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                345 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                103 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                558 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                558 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X