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 CarlTrading, 03-31-2026, 09:41 PM
    1 response
    43 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    20 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    29 views
    1 like
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    46 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    38 views
    0 likes
    Last Post CarlTrading  
    Working...
    X