• 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 Erwin Beckers, Today, 01:23 AM
      0 responses
      2 views
      0 likes
      Last Post Erwin Beckers  
      Started by Mark Taylor, Yesterday, 11:36 PM
      0 responses
      3 views
      0 likes
      Last Post Mark Taylor  
      Started by Bluebeep, Yesterday, 08:38 PM
      0 responses
      7 views
      0 likes
      Last Post Bluebeep  
      Started by stokhastic, Yesterday, 07:08 PM
      0 responses
      3 views
      0 likes
      Last Post stokhastic  
      Started by jlkramer16, Yesterday, 04:29 PM
      1 response
      4 views
      0 likes
      Last Post jlkramer16  
      Working...
      X