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 Template Bug

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

    TimeSpan Template Bug

    Hello,

    There seems to be a bug in the template code when it comes to timespans and the TimeSpan variable.

    I have the following code in my properties:

    PHP Code:
    [NinjaScriptProperty]
    [
    Display(Name="Test Time"Description="Start of the daily trade time"Order=4GroupName="Debuging")]
    public 
    TimeSpan mTestTime
    getset; } 
    and set the value in

    PHP Code:
    protected override void OnStateChange()
    {
        if (
    State == State.SetDefaults)
        {
             
    mTestTime = new TimeSpan(21418);
        }

    Everything runs fine, but when I save a template of my strategy, and load it later, the template does not save the values of the TimeSpan. All values become 00:00:00
    Could this please be looked at?

    V/R,
    --Maxim S

    #2
    Hello Maxim,

    Thank you for your post.

    TimeSpan objects can not be serialized, so I suspect that when you are saving your template the TimeSpan value is not properly saved and this is why you see 00:00:00 when you load the template again. There is a way to prevent this, however. You could convert the TimeSpan into a simple type, such as a string, so that the proper information may be serialized. We have an example "Using a simple type as the NinjaScriptProperty against types which cannot be serialized" on our help guide page here:



    Another type of object that does not serialize well and needs to be converted to a string is a Brush. For another example of how to convert a non-serializable object into a simple type of object for serialization, please see the User Definable Color Inputs page here:



    The Microsoft C# documentation about Serialization may be found at the following publicly available page:

    This article provides information about .NET serialization technologies, including binary serialization, XML and SOAP serialization, and JSON serialization.



    Please let us know if we may be of further assistance.
    Emily C.NinjaTrader Customer Service

    Comment


      #3
      NinjaTrader_Emily You are right, the TimeSpan does not inherit System.Runtime.Serialization.ISerializable as DateTime does.
      Is there another way to expose the timespan of a time value of some sort that can be serialized? I am not married to using TimeSpan, but making it a string will prevent NT8 from doing optimization on it.

      Comment


        #4
        Hello DieSlower,

        Thank you for your response.

        The platform would still be able to run an optimization on your strategy with the TimeSpan, however, the TimeSpan would not be incremented. If you would like to optimize the period of time, you could use int input values and ToTime(Time[0]) to check if the bar is within the hour and minutes selected. There has been other discussion on this topic in our forums, including the following post which includes a sample reference file:

        Hi guys, how can I optimize a time period? I know how to optimize Stop and Take Profit sizes in the Strategy Analyzer Optimization (Variables), but I want to have the time period (it doesn't matter which Data Series or symbol I use) which is the most profitable with entry time and exit time. Example: I want to make an entry


        I appreciate your patience. Please let us know if we may be of further assistance.
        Emily C.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Johnny Santiago, 10-11-2019, 09:21 AM
        95 responses
        6,193 views
        0 likes
        Last Post xiinteractive  
        Started by xiinteractive, 04-09-2024, 08:08 AM
        2 responses
        11 views
        0 likes
        Last Post xiinteractive  
        Started by Irukandji, Today, 09:34 AM
        1 response
        3 views
        0 likes
        Last Post NinjaTrader_Clayton  
        Started by RubenCazorla, Today, 09:07 AM
        1 response
        5 views
        0 likes
        Last Post RubenCazorla  
        Started by TraderBCL, Today, 04:38 AM
        3 responses
        25 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Working...
        X