Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 sidlercom80, 10-28-2023, 08:49 AM
      171 responses
      2,274 views
      0 likes
      Last Post QuantKey_Bruce  
      Started by Irukandji, Yesterday, 02:53 AM
      2 responses
      17 views
      0 likes
      Last Post Irukandji  
      Started by adeelshahzad, Today, 03:54 AM
      0 responses
      3 views
      0 likes
      Last Post adeelshahzad  
      Started by CortexZenUSA, Today, 12:53 AM
      0 responses
      3 views
      0 likes
      Last Post CortexZenUSA  
      Started by CortexZenUSA, Today, 12:46 AM
      0 responses
      1 view
      0 likes
      Last Post CortexZenUSA  
      Working...
      X