Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Time span values not saved when restarting

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

    Time span values not saved when restarting

    When I restart ninjatrader all the time span values I previously entered in my strategies default to 00:00:00 not even the default values. Any idea why this might be?

    #2
    Hello Conceptzx​,

    Thank you for reaching out.

    Is the automated strategy you are working with, a strategy coded by yourself using the Strategy Builder, or was it acquired from a 3rd party?

    If it is your own coded strategy, please contact our engineering team at

    [email protected]

    and they will be able to guide you in this matter.

    If it is a 3rd party strategy, you would want to contact the developer for assistance with their software.

    Please let us know if you have any other questions.​
    Erick P.NinjaTrader Customer Service

    Comment


      #3
      It's coded by myself. Is there a way I can retain the settings, or at least get them to go back to what's defined as default within the strategy?

      Comment


        #4
        Originally posted by Conceptzx View Post
        It's coded by myself. Is there a way I can retain the settings, or at least get them to go back to what's defined as default within the strategy?
        Thanks for your patience.

        I have moved this thread to the Strategy Development topic in the forum rather than Platform Technical Support. In the future, if you are requesting NinjaScript support for scripts that you have developed, please be sure to post in one of the development topics for the most timely and accurate assistance. Thank you for your understanding.

        With that said, I suspect there is an issue happening with the serialization of your TimeSpan inputs. A TimeSpan object may not be serialized normally, so you must make some changes in the Properties region of your script to ensure the values will be saved and restored properly from either the default values within State.SetDefaults or a saved template of the strategy/workspace. First, you must include the XmlIgnore attribute:


        Then, you must use a simple type with the NinjaScriptProperty attribute. The final example on this page demonstrates serialization of a TimeSpan input:


        This page covers serialization of brush colors that are user inputs, though the same ideas apply when using other object types that may not be serialized normally like TimeSpans:


        Please let us know if we may be of further assistance.
        Emily C.NinjaTrader Customer Service

        Comment


          #5
          So something like this?
          Code:
                  [XmlIgnore]
                  [Display(Name = "Trade End Time HH:mm:ss", Order = 2003, GroupName = "02.0. Time")]
                  public TimeSpan TradeEndTime
                  {
                      get { return tradeEndTime; }
                      set { tradeEndTime = value; }
                  }
          
          ​​

          Comment


            #6
            Originally posted by Conceptzx View Post
            So something like this?
            Code:
             [XmlIgnore]
            [Display(Name = "Trade End Time HH:mm:ss", Order = 2003, GroupName = "02.0. Time")]
            public TimeSpan TradeEndTime
            {
            get { return tradeEndTime; }
            set { tradeEndTime = value; }
            }
            
            ​​
            Not quite; please see the following example I mentioned from the NinjaScriptProperty Attribute page:
            Code:
            [XmlIgnore] // cannot serialize type of TimeSpan, use the BeginTimeSpanSerialize object to persist properties      
            [Browsable(false)] // prevents this property from showing up on the UI
            public TimeSpan BeginTimeSpan
            { get; set; }
             
            // users will configure this "string" as the TimeSpan which will be set as a TimeSpan object used in data processing
            [NinjaScriptProperty]
            [Display(Name = "Begin TimeSpan", GroupName = "NinjaScriptStrategyParameters", Order = 1)]
            public string BeginTimeSpanSerialize
            {
              get { return BeginTimeSpan.ToString(); }
              set { BeginTimeSpan = TimeSpan.Parse(value); }
            }​
            Thanks for your time and patience.
            Emily C.NinjaTrader Customer Service

            Comment


              #7
              Do you have an example script that contains this?

              The way you showed would require me to change the time span definitions to strings? Is there a better method for defining time frames?

              Comment


                #8
                Originally posted by Conceptzx View Post
                Do you have an example script that contains this?

                The way you showed would require me to change the time span definitions to strings? Is there a better method for defining time frames?
                Converting the TimeSpan object to a string is the idea behind Serialization. In an XML template, such as the workspace file or a strategy template file, a TimeSpan does not save properly due to its type. That is why you must use XmlIgnore on the TimeSpan object itself. Strings, however, do save into an XML template properly. By converting the TimeSpan object into a "string" it can be serialized when you save a template/workspace, and then when that template or workspace is opened again the string object gets converted back into its TimeSpan counterpart. The whole idea and explanation about why this is necessary is mentioned in the help guide resources I shared with you and yes, there is a sample script that serializes brush color inputs on the following page:


                The same idea behind serializing brushes, which can not be saved as-is into an XML document, applies to serializing TimeSpan objects and other objects that are not a simple type which saves into an XML file without issues.

                Thank you for your time and patience.
                Emily C.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by cbentrikin, Today, 03:49 PM
                0 responses
                10 views
                0 likes
                Last Post cbentrikin  
                Started by MiCe1999, 04-14-2025, 06:54 PM
                7 responses
                75 views
                0 likes
                Last Post b.j.d
                by b.j.d
                 
                Started by NISNOS69, Today, 02:20 PM
                0 responses
                13 views
                0 likes
                Last Post NISNOS69  
                Started by hunter7, Today, 01:09 PM
                0 responses
                25 views
                0 likes
                Last Post hunter7
                by hunter7
                 
                Started by pjsmith, 10-01-2019, 08:59 AM
                28 responses
                2,014 views
                0 likes
                Last Post nephew94  
                Working...
                X