Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Template not saving custom indicator settings

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

    Template not saving custom indicator settings

    Hi there,

    When I change the settings on my custom indicator (e.g plot colors, lookback parameters, etc) it doesn't save the new settings on saving a chart template or saving a workspace. NT resident indicators save fine, so it's clearly my code that's the problem. Do you know what might be causing this? Any areas I should have a look at?

    Many thanks.




    #2
    Hello Sparkyboy,

    Are you seeing an error on the Log tab of the Control Center when attempting to save the workspace or template?
    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 need serialization.

    An xml file stores information as text, stored in C# as a string; 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.

    While simple object types that are easily written as text (or are NinjaScript specific types) 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 any number type)
    • enum
    • SimpleFont
    • Stroke

    All other data types will need to have the [XmlIgnore] attribute applied to prevent the variable from being included from being saved in the xml file.
    Help guide: NinjaScript > Language Reference > Common > Attributes > XmlIgnoreAttribute 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 using custom code, 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.

    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

    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); } }
    Public variables that are not intended for the user to set or are not convertible to a string and then back, should not be serialized with custom code, but should still use the [XmlIgnore] attribute to prevent these from being saved in xml.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Fixed! Thanks for your help, Chelsea.

      Comment

      Latest Posts

      Collapse

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