• 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

Using TimeSpan as a Parameter

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

    Using TimeSpan as a Parameter

    Hi,
    I'm have a input parameter that needs to be a time. I set it's type as a timespan object. In order to have it save it's values I added the following:

    Code:
    [NinjaScriptProperty]
    [Display(Name="OpenTime", Description="Open Time", Order=1, GroupName="Parameters")]
    public TimeSpan OpenTime
    { get; set; }
    
    [Browsable(false)]
    public string OpenTimeSerialize
    { 
    	get { return OpenTime.ToString(); } 
    	set { OpenTime = TimeSpan.Parse(value); } 
    }
    Is this the correct approach? I just kind of emulated what was done for brushes. I assume this is the approach for most parameters that are not base types?

    If this is correct you might want to consider adding a blurb into the documentation about this.

    #2
    Hello,

    That should do the trick for you. Are you running into any issues with that method? The serialization is the crucial component of exposing TimeSpans, and it looks like your method should cover that requirement.
    Dave I.NinjaTrader Product Management

    Comment


      #3
      Hi Dave,
      Seems to be working fine. I was just wondering if there are any general rules for when parameters need the extra serialization method? Also, what are the naming rules for the serialization method? Does it just always need to be PropertyName + Serialize ?
      Last edited by GrumpyTrader; 09-14-2015, 10:28 AM.

      Comment


        #4
        Adding "Serialize" to the end of the property name is considered a best practice, but is not strictly required. It can be helpful to immediately differentiate the serializable property from any others you may have with similar names.

        As I was searching the web for a concise answer to the question of "when should I serialize something?," the answer that I came across time and time again was "only when you need to!" Simply put, you will want to serialize something specifically when it cannot be set, re-loaded, shared between classes/apps, or stored in its native form. A timespan is a perfect example of this. Since there is not really a way for a user to define a TimeSpan per se in a UI input field, you need a way to translate the TimeSpan's parameters into something that can be obtained from user input. Serialization saves the day here. So the short answer could be "when you need to do something with an object that cannot be directly done with that object, but it can be done with string representations of the object's properties, then serialize."
        Dave I.NinjaTrader Product Management

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by seagraph, Today, 03:27 PM
        0 responses
        11 views
        0 likes
        Last Post seagraph  
        Started by dedouglas, Today, 02:54 PM
        1 response
        11 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by elkhatabi, 08-01-2019, 06:36 PM
        5 responses
        53 views
        0 likes
        Last Post NinjaTrader_RyanL  
        Started by mr_trade, Today, 01:01 PM
        4 responses
        19 views
        0 likes
        Last Post mr_trade  
        Started by Renorail, Today, 12:31 PM
        1 response
        14 views
        0 likes
        Last Post NinjaTrader_PaulH  
        Working...
        X