• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Time parameters

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

    Time parameters

    I want to use time parameters (like start time, end time, etc). I used TimeSpan, which works well, except for one thing. The parameter values are not saved between sessions.

    I am using something like this:
    Code:
            [Description("Start Time")]
            [GridCategory("Time Interval")]
            public TimeSpan StartTime
            {
                get { return strtTm; }
                set { strtTm = value; }
            }
    What am I doing wrong? How can I get the values saved between sessions?

    #2
    Hello Titus,

    Thanks for the note.

    The TimeSpan object needs to be serialized so it can be saved to an XML document. Changing the property like so allows saving to the workspace:

    Code:
     
            private TimeSpan strtTm;
            ...   
            [XmlIgnore]
            [Description("Start Time")]
            [GridCategory("Time Interval")]
            public TimeSpan StartTime
            {
                get { return strtTm; }
                set { strtTm = value; }
            }
    
            [Browsable(false)]
            [XmlElement(DataType="duration", ElementName="StartTime")]
            public string StartTimeString
            {
                get 
                { 
                    return XmlConvert.ToString(StartTime); 
                }
                set 
                { 
                    StartTime = string.IsNullOrEmpty(value) ?
                        TimeSpan.Zero : XmlConvert.ToTimeSpan(value); 
                }
            }
    Please let me know if I can assist further.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Thank you, Chris, it did the trick.

      One thing though, for anyone else who might need this.
      using System.Xml; has to be added to #region Using declarations for XmlConvert to work.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Irukandji, Today, 09:01 PM
      0 responses
      1 view
      0 likes
      Last Post Irukandji  
      Started by bdelorm73, Today, 07:04 PM
      2 responses
      15 views
      0 likes
      Last Post bdelorm
      by bdelorm
       
      Started by bdelorm73, Today, 06:51 PM
      0 responses
      13 views
      0 likes
      Last Post bdelorm73  
      Started by einstein, Today, 06:41 PM
      0 responses
      2 views
      0 likes
      Last Post einstein  
      Started by memonic, Today, 03:57 PM
      0 responses
      8 views
      0 likes
      Last Post memonic
      by memonic
       
      Working...
      X