Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Save of Strategy Settings to Template Not Working

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

    Save of Strategy Settings to Template Not Working

    ​Hello Team,

    I have some custom strategies that I can't get the settings to save in a template. If I open the strategy new, and load the template (previously saved), it doesn't change the settings.

    I edit the "Levels" (in the attached screenshot) from zeros to relevant levels, then apply and save a template. When I reload the strategy and load the template it doesn't work.

    Click image for larger version  Name:	Snag_4ced9ffe.png Views:	0 Size:	51.1 KB ID:	1229219

    Click image for larger version

Name:	Snag_4d0557d4.png
Views:	401
Size:	13.8 KB
ID:	1229222Click image for larger version  Name:	Snag_4cfe0cd3.png Views:	0 Size:	40.9 KB ID:	1229221

    Here is a sample of the level Properties:
    region Properties

    [NinjaScriptProperty]
    [Range(double.MinValue, double.MaxValue)]
    [Display(Name="L1", Order=1, GroupName="Levels")]
    public double L1
    { get; set; }

    [NinjaScriptProperty]
    [Range(double.MinValue, double.MaxValue)]
    [Display(Name="L2", Order=2, GroupName="Levels")]
    public double L2
    { get; set; }



    Here is an error I see in the log when I load the strategy:
    2022-12-28 23:41:41:888|3|524288|Error on executing DB command: System.InvalidOperationException: There was an error generating the XML document. ---> System.InvalidOperationException: The type System.Windows.Media.MatrixTransform was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically. at Microsoft.Xml.Serialization.GeneratedAssembly.XmlS erializationWriterLevelsBotNoTrade.Write37_Transfo rm(String n, String ns, Transform o, Boolean isNullable, Boolean needType) at Microsoft.Xml.Serialization.GeneratedAssembly.XmlS erializationWriterLevelsBotNoTrade.Write40_SolidCo lorBrush(String n, String ns, SolidColorBrush o, Boolean isNullable, Boolean needType) at Microsoft.Xml.Serialization.GeneratedAssembly.XmlS erializationWriterLevelsBotNoTrade.Write41_LevelsB otNoTrade(String n, String ns, LevelsBotNoTrade o, Boolean isNullable, Boolean needType) at Microsoft.Xml.Serialization.GeneratedAssembly.XmlS erializationWriterLevelsBotNoTrade.Write42_LevelsB otNoTrade(Object o) --- End of inner exception stack trace --- at System.Xml.Serialization.XmlSerializer.Serialize(X mlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id) at System.Xml.Serialization.XmlSerializer.Serialize(S tream stream, Object o, XmlSerializerNamespaces namespaces) at NinjaTrader.NinjaScript.StrategyBase.ToXml() at NinjaTrader.NinjaScript.StrategyBase.DbAdd() at NinjaTrader.Cbi.DB.DBThread()



    I've researched regarding the XmlInclude attribute and found the following. However, I'm not sure if or how it should be applied.
    [XmlInclude(typeof(System.Windows.Media.MatrixTrans form))]
    public class MyClass
    {
    // Your code goes here
    }



    On a side note, I did try saving a Template for the SampleMACrossOver strategy, and it saves and loads just fine.

    Thank you for any guidance you can give me,
    Michael
    Last edited by md4866; 12-28-2022, 11:04 PM.

    #2
    Hello Michael,

    Thank you for your post.

    I suspect that this error could be related to your parameters for UpperBrush and LowerBrush; if they are not properly serialized then this can cause error messages when trying to load from an XML document like a workspace or template file. We have a page in the help guide about user-definable color inputs that includes a SampleBrushesInput script that you may review as an example of how to work with user-definable brush inputs. We also have a page about working with Brushes that offers more information about serialization. Both have been linked below:



    Please review those resources and then review your script to ensure that your brushes have been serialized properly in the properties region. Just to clarify, you should not need to add the attribute you mentioned for "[XmlInclude(typeof(System.Windows.Media.MatrixTrans form))]."

    Please let me know if I may be of further assistance or if the behavior persists after double-checking the serialization of your brush properties.

    Comment


      #3
      That was the issue. Thank you so much Emily! I can now save the settings of the other parameters. That takes care of my main issue.

      I did try to use the Serialize routines from the docs as well, but I couldn't get it working (not SolidColorBrush at all, but Brush partially). I don't need to save the colors, so I just left it out.

      For reference, here's what did (without the serialization routines).

      Code:
      // [NinjaScriptProperty]
      // [Display(Name="UpperBrush", Description="Color You want upper brush", Order=36, GroupName="Parameters")]
      // public SolidColorBrush UpperBrush
      // { get; set; }
      
      // [NinjaScriptProperty]
      // [Display(Name="LowerBrush", Description="Color You want lower brush", Order=37, GroupName="Parameters")]
      // public Brush LowerBrush
      // { get; set; }
      
      // 12/29/2022 - Used [XmlIgnore] attribute so class won't be saved in Workspace or Template XML and cause an error, making other settings to not save either.
      [XmlIgnore()]
      [Display(Name="UpperBrush", Description="Color you want upper brush", Order=36, GroupName="Parameters")]
      public Brush UpperBrush
      { get; set; }
      
      [XmlIgnore()]
      [Display(Name="LowerBrush", Description="Color you want lower brush", Order=37, GroupName="Parameters")]
      public Brush LowerBrush
      { get; set; }
      ​Thank you again for all your help,
      Michael

      Comment


        #4
        Hello Michael,

        Thank you for your reply.

        Although you added the [XmlIgnore()] attribute, I suspect there could still be potential serialization problems with your script. Whenever you need a brush as input for a script, I recommend adding it via the wizard on the "Input Parameters" page, as shown in the screenshots below:
        New indicator wizard - https://www.screencast.com/t/2OqhOSQQQ
        Adding a brush for input - https://www.screencast.com/t/hsU89lNaLq
        The properties are generated with the necessary serialization information - https://www.screencast.com/t/1Rgf9mgu

        You may want to start a new script just to add the proper brush inputs, then you can copy/paste the logic from your existing script to the new one. Alternatively, you could add the brush inputs to a new script and copy/paste the property information into your existing script to make sure you have it all correct.

        I appreciate your patience and I am glad to hear you were able to resolve the issue so that you may save your strategy in a template. Please let us know if we may be of further assistance.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Yesterday, 05:17 AM
        0 responses
        54 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        130 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        72 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        44 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        49 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X