Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Property persistence in Enable/Disable cycle

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

    Property persistence in Enable/Disable cycle

    Hello,

    I have a strategy and I would like to persist Properties of that strategy so that the Properties remain the same after a Disable - Enable of the very same strategy.

    As soon as I define a property as [Browsable(false)] this mechanism doesn't work any more.

    I would consider this a bug, and the correct way to disable persistence would be the [XmlIgnore] attribute and not the [Browsable(false)] attribute.


    The idea behind non - visible persistent properties is that one might persist hidden to the user state variables of the strategy in consecutive uses of the same strategy.


    Please enlight me further or just fix it,
    thank you

    Andreas Langhoff


    P.S. It looks like overriding Clone() one can fix the above behaviour, but shouldn't it work right from the beginning?




    NOT working:, will work removing [Browsable(false)

    [Browsable(false)]
    public List<string> ExecTokens
    {

    get;
    set;
    }
    Last edited by zweistein; 09-27-2017, 04:06 AM.

    #2
    Hello,

    Thank you for the post.

    The [Browsable(false)] would control if the property is displayed in the user interface or not. Properties that are displayed, if a user-defined value is entered that would be persisted while the instance is still applied to the control center but is not directly saved in the template system.

    The properties in a script would not be serialized between a disable and enable as this is not a template saving action. It would only be expected that exposed public properties are saved when a template is being saved, this can occur when saving the workspace or saving a template. I do see that a property with only [Browsable(false)] is saved in the template when saving the workspace/template:

    Code:
    <ExecTokens>
         <string>test1</string>
         <string>test2</string>
    </ExecTokens>
    If you wanted to save items between a disable and enable that are not user-defined inputs or have [Browsable(false)], you would instead need to implement your own serialization for those items using the state system.

    One example would be in State.Historical, set a bool to true to know the script was enabled. Load your settings and apply them to your properties. In State.Terminated check that the bool is true, and if so, resave the properties while the strategy is being disabled.

    An alternative would be to use the Addon namespace to define a static class, this can be used to store data between enable/disable cycles. You could also make a method to save/load your data to a specific file if you wanted. https://ninjatrader.com/support/foru...24&postcount=3

    I will put in a feature request for persisting properties with [Browsable(false)] similar to user inputs if it is possible.


    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Belfortbucks, Today, 09:29 PM
    0 responses
    3 views
    0 likes
    Last Post Belfortbucks  
    Started by zstheorist, Today, 07:52 PM
    0 responses
    7 views
    0 likes
    Last Post zstheorist  
    Started by pmachiraju, 11-01-2023, 04:46 AM
    8 responses
    150 views
    0 likes
    Last Post rehmans
    by rehmans
     
    Started by mattbsea, Today, 05:44 PM
    0 responses
    6 views
    0 likes
    Last Post mattbsea  
    Started by RideMe, 04-07-2024, 04:54 PM
    6 responses
    33 views
    0 likes
    Last Post RideMe
    by RideMe
     
    Working...
    X