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

Custom Classes and Lists of Objects

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

    Custom Classes and Lists of Objects

    I am curious, being able to track submitted orders (IOrder objects), in a list in a structured format is rather simple (conceptually), however, doesn't seem to work nicely here in NT. For example, from my experience with C# and MVC, I can do something like this:

    Code:
    public class APosition
    {
            public IOrder Entry { get; set; }
            public IOrder Target { get; set; }
            public IOrder Stop { get; set; }
            public int EntryId { get; set; }
            public Pro9Position() {}
    }
    
    APosition MyPositions = new List<APosition>();
    Which, of course, compiles without issue. And, when I submit orders I can actually add to my list with the necessary IOrder object, and all is well.

    However, when I try to enable this for strategies, etc, I of course, receive Serialization errors, due to the fact that IOrder is an interface.

    If I change it to 'Order', which technically isn't supported, and cast the SubmitOrder() methods to (Order), it also compiles without issue, but the Serialization errors crop up stating that Order.Account.Connection isn't serializeable due to the fact that Order.Account.Connection doesn't implement IConnection.

    Thus to me, it seems like we cannot have a LIST object of orders that we can quickly query and track.

    Is this correct?

    #2
    Originally posted by zackrspv View Post
    However, when I try to enable this for strategies, etc, I of course, receive Serialization errors, due to the fact that IOrder is an interface.
    Make the APosition class private?

    Comment


      #3
      Is MyPositions public or private?
      Is it declared inside your Strategy based class?

      Ultimately, what you need to do is tell the serializer to ignore the public property/variable that it is attempting to serialize.

      You'll do that by making it private (instead of public) or by adding [XmlIgnore()] attribute to the variable or property.

      Comment


        #4
        Originally posted by zackrspv View Post
        I am curious, being able to track submitted orders (IOrder objects), in a list in a structured format is rather simple (conceptually), however, doesn't seem to work nicely here in NT. For example, from my experience with C# and MVC, I can do something like this:

        Code:
        public class APosition
        {
                public IOrder Entry { get; set; }
                public IOrder Target { get; set; }
                public IOrder Stop { get; set; }
                public int EntryId { get; set; }
                public Pro9Position() {}
        }
        
        APosition MyPositions = new List<APosition>();
        Which, of course, compiles without issue. And, when I submit orders I can actually add to my list with the necessary IOrder object, and all is well.

        However, when I try to enable this for strategies, etc, I of course, receive Serialization errors, due to the fact that IOrder is an interface.

        If I change it to 'Order', which technically isn't supported, and cast the SubmitOrder() methods to (Order), it also compiles without issue, but the Serialization errors crop up stating that Order.Account.Connection isn't serializeable due to the fact that Order.Account.Connection doesn't implement IConnection.

        Thus to me, it seems like we cannot have a LIST object of orders that we can quickly query and track.

        Is this correct?
        Are you trying to serialize APosition objects?

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by DJ888, Today, 10:57 PM
        0 responses
        1 view
        0 likes
        Last Post DJ888
        by DJ888
         
        Started by MacDad, 02-25-2024, 11:48 PM
        7 responses
        158 views
        0 likes
        Last Post loganjarosz123  
        Started by Belfortbucks, Today, 09:29 PM
        0 responses
        7 views
        0 likes
        Last Post Belfortbucks  
        Started by zstheorist, Today, 07:52 PM
        0 responses
        7 views
        0 likes
        Last Post zstheorist  
        Started by pmachiraju, 11-01-2023, 04:46 AM
        8 responses
        151 views
        0 likes
        Last Post rehmans
        by rehmans
         
        Working...
        X