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

Values of the List<t> property doubled

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

    Values of the List<t> property doubled

    Hi everyone!
    I got the custom type
    Code:
    [CategoryDefaultExpanded(true)]
    public class myType : ICloneable
    {
          public string Name { get; set; }
          public double Value { get; set; }
    
         ........
    }
    and I'd like to make an indicator property of type List<myType>

    Code:
    public class myIndicator : Indicator
    {
          [PropertyEditor("NinjaTrader.Gui.Tools.CollectionEditor")]
          public List<myType> MyTpyeListProperty { get; set; }
    
          protected override void OnStateChange()
          {
                if (State == State.SetDefaults)
                {
                         MyTpyeListProperty = new List<myType>();
                }
           }
         
    }
    this code works fine in all scenarios except one.
    I add indicator to chart, then saving chart template, then I switch to another template and getting back to first one.
    After this all the values in this list get doubled, so if I originaly have 3 values after this I got 6.
    Is there any workaround on this?
    This error may be repoduced with "SampleIndicatorTypeConverter" sample code from http://ninjatrader.com/support/forum...ad.php?t=97919
    Last edited by serialbug; 06-21-2017, 12:03 PM.

    #2
    Hello serialbug,

    If [XmlIgnore()] is added as an attribute tag, can the behavior still be reproduced?

    The collection editor is not a object that is serializable by default.

    The XmlIgnore() would prevent NinjaTrader from attempting to serialize and deserialize that object.

    It would be necessary to create a custom string from the object and way of creating the object from a saved string to serialize it. I'm not aware of something already written that would do this.
    Last edited by NinjaTrader_ChelseaB; 06-21-2017, 12:16 PM.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thank you NinjaTrader_ChelseaB!
      Sure XmlIgnore prevent doubling the values, but serialization is what I want for this property. And serialization works fine in all scenarios except this one, with chart templates.

      Comment


        #4
        Hello serialbug,

        Serialization will not work with all objects.

        If you create a custom class, this will not automatically be serializable. You would need to create a way for your custom class to be serializable.

        DateTime objects, Timespans, and Brushes are also not serializable objects, but these do have methods already created to turn the object to a string and from a string back to an object.


        Basically you need a YourClassToString and StringToYourClass method that would create a string and can read a string and build an object.

        However, since there is not a serialization error thats appearing, I will inquire our development to see if there is something behind the scenes that is causing the object to not properly deserialize.
        Last edited by NinjaTrader_ChelseaB; 06-21-2017, 12:59 PM.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Yes, I'm aware of what need class to be serializable, my custom type is serializable - that is not the question. The question is why the values get doubled in the List<t> when I apply template on chart, and how I can avoid this?

          Comment


            #6
            Hi! Any updates for this?

            Comment


              #7
              Here is the sample code to reproduce the problem.
              1. Apply indicator on chart ("List Property" contain 3 values)
              2. Save chart template
              3. Apply saved template to the chart

              After this go to indicator settings and you will see that now "List Property" contains 6 values

              Update: It seems that problem is in NinjaTrader.Gui.Tools.CollectionEditor when I remove this attribute, values do not got doubled.
              Attached Files
              Last edited by serialbug; 06-26-2017, 06:54 AM.

              Comment


                #8
                Hello serialbug,

                Thank you for your patience on this matter.

                After review with development we have updated our documentation on cloning, complex classes, and serializing such objects at the following link under "Cloning NinjaScript" and "Saving NinjaScript Properties to the Workspace via XML Serialization": http://ninjatrader.com/support/helpG...fecycle_of.htm

                The link will refer to the Facebook share service CopyTo function which can be found in the NinjaScript Editor > Share Services > Facebook and then line 45.

                Please let me know if you have any questions.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by alifarahani, Today, 09:40 AM
                4 responses
                20 views
                0 likes
                Last Post alifarahani  
                Started by gentlebenthebear, Today, 01:30 AM
                3 responses
                16 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Started by PhillT, Today, 02:16 PM
                2 responses
                7 views
                0 likes
                Last Post PhillT
                by PhillT
                 
                Started by Kaledus, Today, 01:29 PM
                3 responses
                11 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Started by frankthearm, Yesterday, 09:08 AM
                14 responses
                47 views
                0 likes
                Last Post NinjaTrader_Clayton  
                Working...
                X