Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Tracking orders from entry to exit

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

    Tracking orders from entry to exit

    Hello,
    New to the forum, and trying to figure out how to track a trade from entry to execution to exit. Does the Trades class do this? (see sample code below)... I'm trying to iterate through all open positions and close them if they meet certain criteria. Thanks.

    protected override void OnBarUpdate()
    {
    // Condition set 1
    if (Close[0] > Close[10]
    && Close[0] > Close[20] + 0.0005
    && Close[0] > Close[20])
    {
    EnterLong(100000);
    }


    for (int i=0; i < Performance.RealtimeTrades.Count; i++)
    {
    if(Performance.RealtimeTrades[i].Entry.Order.OrderState == OrderState.Filled
    && Performance.RealtimeTrades[i].Exit.Order.OrderState != OrderState.Filled)
    {
    if(Performance.RealtimeTrades[i].Entry.Price - Close[0] > .00025
    && Performance.RealtimeTrades[i].Entry.MarketPosition == MarketPosition.Long)
    {
    ExitLongLimit(Close[0] - .0001);
    }

    if(Performance.RealtimeTrades[i].Entry.Price - Close[0] < -.0005
    && Performance.RealtimeTrades[i].Entry.MarketPosition == MarketPosition.Long)
    {
    ExitLongLimit(Close[0] - .0001);
    }
    }
    }
    }
    Last edited by harri06665; 01-05-2009, 01:09 PM.

    #2
    Hi harri06665,

    Welcome to the NinjaTrader Support Forums. The Trades class will not do what you want. The Trades are available only after they have closed and completed. i.e. entry and exit.

    Instead I suggest you take a look at IOrder and IExecution objects along with the OnOrderUpdate() and OnExecution() methods. You can track your orders from there.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      I think it would be useful if NT allowed you to get a list of all active orders, rather than having to manually store references to each submitted order, and manually remove the order from your list of orders when the order closes or is canceled. NT already knows the list of active orders, so it would be great if there was an exposed API to get a list of them.

      Comment


        #4
        Thank you for the suggestion. I will forward it to development.
        Josh P.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        648 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        369 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        108 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        572 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        573 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X