Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

TimeSpan property value is not persisted in workspace

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

    TimeSpan property value is not persisted in workspace

    I've added TimeSpan properties to my strategy to allow users to control when to start, pause, resume and finish trading. The values are interpreted by the strategy as a delta from the session start or session close. I was previously using a number of minutes but that is difficult to work with as a user of the script.

    The TimeSpan properties work nicely in the property sheet. But there's one problem: The values are not persisted in the workspace... or they're not restored from it when restarting NinjaTrader.

    The steps to reproduce:
    1. Import the attached strategy, MACrossOver, that has a TimeSpan property defined called StartMinutesTS ( Name = "Session Start" )
    2. Create a new workspace.
    3. Open a chart and add the MACrossOver strategy to it.
    4. Look at the properties in the Property Sheet. Note the "Session Start" is displayed as 08:50:00. This is the default setting set in OnStateChange() State == State.SetDefaults.
    5. Close NinjaTrader and choose Save when prompted.
    6. Restart NinjaTrader
    7. Edit the MACrossOver strategy to view the "Session Start" property. The value is 00:00:00.

    The Store / Restore bug is only when restarting NinjaTrader. It does not occur if you change steps 5 and 6 to
    5. Close the workspace and choose Save when prompted
    6. Open the workspace again

    The same store/restore issue happens with the Strategy Analyzer as well.
    I did not try indicators so I don't know if it's also an issue in the Market Analyzer.

    It's really a nice feature to have the TimeSpan property working. I hope this can be fixed soon.
    Attached Files

    #2
    Hello Brillo,

    This would likely take serializing the input.


    ​​​​​​​https://ninjatrader.com/support/foru...eter#post79414
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thank you Chelsea. I got it to work well.

      Code:
       [XmlIgnore, NinjaScriptProperty]
      [Display(Name = "Session Start", Description = "time span from beginning of session to begin trading", Order = 29, GroupName = "07. Trade Time")]
      public TimeSpan StartMinutesTS
      { get; set; }
      
      [Browsable(false)]
      public string StartMinutesTSSerialize
      {
      get { return StartMinutesTS.ToString(); }
      set { StartMinutesTS = TimeSpan.Parse(value); }
      }
      This implementation is better than the one suggested in the help guide:


      The guide is suggesting to make the property type bound to the UI a String and then converts it to a TimeSpan when serializing. Although it works it allows the user to type in anything they want and they might type in something that is not convertible into a TimeSpan object.

      The impl that I posted here binds the TimeSpan itself to the UI and consequently the UI enforces the nn:nn:nn format.

      Thanks for your help and guidance.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by NullPointStrategies, 03-13-2026, 05:17 AM
      0 responses
      86 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      151 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      79 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      53 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      61 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X