Announcement

Collapse
No announcement yet.

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, 03: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 vantojo, Today, 09:32 AM
    1 response
    4 views
    0 likes
    Last Post NinjaTrader_Kate  
    Started by FelipeRXP, Today, 08:40 AM
    2 responses
    9 views
    0 likes
    Last Post FelipeRXP  
    Started by petedian, Today, 08:44 AM
    0 responses
    13 views
    0 likes
    Last Post petedian  
    Started by J0shTrader, Yesterday, 12:29 PM
    1 response
    2 views
    0 likes
    Last Post NinjaTrader_ChrisL  
    Started by bc24fl, Today, 08:07 AM
    1 response
    10 views
    0 likes
    Last Post NinjaTrader_ChrisL  
    Working...
    X