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 adeelshahzad, Today, 03:54 AM
        5 responses
        31 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Started by stafe, 04-15-2024, 08:34 PM
        7 responses
        31 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by merzo, 06-25-2023, 02:19 AM
        10 responses
        823 views
        1 like
        Last Post NinjaTrader_ChristopherJ  
        Started by frankthearm, Today, 09:08 AM
        5 responses
        19 views
        0 likes
        Last Post NinjaTrader_Clayton  
        Started by jeronymite, 04-12-2024, 04:26 PM
        3 responses
        43 views
        0 likes
        Last Post jeronymite  
        Working...
        X