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

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 rbeckmann05, Yesterday, 06:48 PM
      1 response
      12 views
      0 likes
      Last Post bltdavid  
      Started by llanqui, Today, 03:53 AM
      0 responses
      6 views
      0 likes
      Last Post llanqui
      by llanqui
       
      Started by burtoninlondon, Today, 12:38 AM
      0 responses
      10 views
      0 likes
      Last Post burtoninlondon  
      Started by AaronKoRn, Yesterday, 09:49 PM
      0 responses
      15 views
      0 likes
      Last Post AaronKoRn  
      Started by carnitron, Yesterday, 08:42 PM
      0 responses
      11 views
      0 likes
      Last Post carnitron  
      Working...
      X