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 SalmaTrader, 07-07-2026, 10:26 PM
        0 responses
        46 views
        0 likes
        Last Post SalmaTrader  
        Started by CarlTrading, 07-05-2026, 01:16 PM
        0 responses
        22 views
        0 likes
        Last Post CarlTrading  
        Started by CaptainJack, 06-17-2026, 10:32 AM
        0 responses
        14 views
        0 likes
        Last Post CaptainJack  
        Started by kinfxhk, 06-17-2026, 04:15 AM
        0 responses
        21 views
        0 likes
        Last Post kinfxhk
        by kinfxhk
         
        Started by kinfxhk, 06-17-2026, 04:06 AM
        0 responses
        23 views
        0 likes
        Last Post kinfxhk
        by kinfxhk
         
        Working...
        X