• 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 Dan_D_Trader, Today, 03:49 PM
      0 responses
      4 views
      0 likes
      Last Post Dan_D_Trader  
      Started by JohnAymin, Today, 02:38 PM
      1 response
      6 views
      0 likes
      Last Post NinjaTrader_Tyler  
      Started by Rmos22, Today, 02:20 PM
      2 responses
      23 views
      0 likes
      Last Post Rmos22
      by Rmos22
       
      Started by sawtooth500, Today, 12:59 PM
      1 response
      9 views
      0 likes
      Last Post NinjaTrader_Spencer  
      Started by Steve L, Yesterday, 09:36 PM
      1 response
      24 views
      0 likes
      Last Post NinjaTrader_Kate  
      Working...
      X