• 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 ninjo, Today, 11:54 AM
      0 responses
      1 view
      0 likes
      Last Post ninjo
      by ninjo
       
      Started by deblanka, Today, 08:56 AM
      0 responses
      6 views
      0 likes
      Last Post deblanka  
      Started by Boonfly8, Yesterday, 12:30 PM
      7 responses
      18 views
      0 likes
      Last Post sledge
      by sledge
       
      Started by Sohal, Today, 05:02 AM
      2 responses
      13 views
      0 likes
      Last Post techmint  
      Started by danitralla, Today, 03:33 AM
      0 responses
      5 views
      0 likes
      Last Post danitralla  
      Working...
      X