Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Finding SL/TP order linked to an EnterLong()

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

    Finding SL/TP order linked to an EnterLong()

    Hello,

    I'm trying to find the target price of a SL/TP order that I set inside the OnExecutionUpdate event handler, but I have no reference saved to it (declare an Order field for it, for example), I'm trying to make it robust to work on multiple scenarios.
    I think the only case this wouldn't work is if I have multiple Entries per Direction
    Just wondering if there's a better alternative when not using these automatic Sets() methods.

    Code:
    var findOrderOfAnEntry = Orders.
    FirstOrDefault(x => x.Name == "SL Buy" && x.FromEntrySignal == "Buy" && //Search for a SL or a TP of a Buy
    x.OrderUpdates.All(y => y.Filled == 0) && //Not Filled
    x.OrderUpdates.Any(y => y.OrderState == OrderState.Working) && //Currently Working
    x.OrderUpdates.All(y => !y.OrderState.ToString().Contains("Cancel"))); //Not Cancelled, CancelPending, CancelSubmitted
    Edit: Sorry I think this would have to be placed under the strategy development section

    #2
    Hello Waxavi,
    You can use OnOrderUpdate and OnExecutionUpdate to find orders. There is a sample of locating orders here: https://ninjatrader.com/support/help...and_onexec.htm

    You can technically do what you are doing now however it would not be a good practice, instead it is suggested to use the passed in variables from the events as they come in, that will work with all brokers.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    601 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    347 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    103 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    559 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    558 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X