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 DannyP96, 05-18-2026, 02:38 PM
    1 response
    83 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 05-11-2026, 05:56 AM
    0 responses
    143 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 05-10-2026, 08:12 PM
    0 responses
    83 views
    0 likes
    Last Post CarlTrading  
    Started by Hwop38, 05-04-2026, 07:02 PM
    0 responses
    256 views
    0 likes
    Last Post Hwop38
    by Hwop38
     
    Started by Mindset, 04-21-2026, 06:46 AM
    0 responses
    334 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Working...
    X