Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

IPosition - How do you target one of several similar positions?

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

    IPosition - How do you target one of several similar positions?

    I need to identify and track prior positions in a given instrument. For example:

    Position #1 - Long at 1.20
    Position #2 - Long at 1.19

    I've found some code here: http://ninjatrader.com/support/forum...ead.php?t=7499

    which has:

    if (Position.MarketPosition == MarketPosition.Long && ...



    This code seems to identify a single Long position. My question again is; How could I differentiate between multiple Long (or Short) positions? I was thinking about creating my own "Trade" object, Example:

    public class Trade {
    public int BarNum { get; set; }
    public string OrderType { get; set; }
    public double FillPrice { get; set; }
    }

    and tracking it using List<Trade> but then I came across IPosition. After looking at the NT Documentation, IPosition doesn't quite do what I need. Any ideas on how to accomplish this?
    Thank You!
    Last edited by exnihilo; 07-11-2016, 12:08 AM.

    #2
    Hello,

    Thank you for the question.

    Generally to track orders and base logic on those orders, you could utilize the IOrder object which is generated upon submitting the order.

    The sample you had provided shows this:

    private IOrder entryOrder

    The object entryOrder can be checked if the current Execution or OrderUpdate event was that order. If so, you could delegate logic based on the result of that order such as Filled or PartFilled. You could also store this object in a custom structure as you have shown as a type IOrder for later use. Using this information, you could populate your own custom variables as needed and later use these variables in logic where needed.

    The strategy its self will only report Long, Short or Flat along with a quantity. If you need further tracking you would need to develop the system that works with the logic you are currently using. As an example, if you needed to track what Bar the order was filled on, you could use the Execution override to find when it was Filled and populate the custom object with that information.

    I look forward to being of further assistance.

    Comment


      #3
      Originally posted by exnihilo View Post
      public class Trade {
      public int BarNum { get; set; }
      public string OrderType { get; set; }
      public double FillPrice { get; set; }
      }
      Yep, you're on the right track.

      Jesse's suggestion is a good one. I've done something similar in my own private framework, using a class I've called "OrderGroup".

      Code:
       public class OrderGroup
       {
           public int BarNum;
           public string OrderType;
           public double FillPrice;
           private IOrder EntryOrder;
           private IOrder StopOrder;
           private IOrder TargetOrder;
       }
      Then create an array of OrderGroups, with 2 elements.

      I've gone the extra mile in my own framework to handle multiple exits from a single entry order -- which means an array of target orders.
      Code:
       public class OrderGroup
       {
           public int BarNum;
           public string OrderType;
           public double FillPrice;
           private IOrder EntryOrder;
           private IOrder StopOrder;
           private IOrder[] TargetOrder = new IOrder[4];
       }
      Multiple exits implies using unmanaged orders.

      Design your class to handle all details of your orders. For example, my OrderGroup class contains additional details for my order's BreakEven stop, AutoTrail stop, and CustomTrail stop (all of which are separate classes).

      My container classes don't have a lot of methods, they just organize and group the order details more elegantly than separate variables. I think you get the idea.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      557 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      324 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      101 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      545 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      547 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X