Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to Determine if Stop Loss or Profit Target is Hit

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

    How to Determine if Stop Loss or Profit Target is Hit

    How to Determine if Stop Loss or Profit Target is Hit first while in a position?

    Are there events in NT8 to do this?

    Thanks in advance.

    #2
    Hello geekodude, and thank you for your question.

    There are two events, OnOrderUpdate and OnExecutionUpdate, which will allow you to react to Stop Loss and Profit Target orders being triggered. I am including some code which demonstrates how to do so. Please let us know if there are any other ways we can help.
    Attached Files
    Jessica P.NinjaTrader Customer Service

    Comment


      #3
      Thank you, I will study your example.

      Comment


        #4
        I have this working excellently for individual trades. Is there a way to separate between two unique trades? I have my code shown:

        protected override void OnExecutionUpdate (
        Execution execution, string executionId, double price, int quantity,
        MarketPosition marketPosition, string orderId, DateTime time
        )
        {
        // This is the code I used to discover the Stop loss order's name
        Print("OOU: Trade 1: " + execution.Order);

        // Now that I know it is 'Stop loss', I can use this name here
        if (execution.Order.Name == "Stop loss")
        {
        excelSheet.Cells[rowCount,9] = "Fail";
        }

        Print("OOU: Trade 2: " + execution.Order);


        // Now that I know it is 'Stop loss', I can use this name here
        if (execution.Order.Name == "Stop loss")
        {
        excelSheet.Cells[rowCount,10] = "Fail";
        }
        }

        I have it set up to print to excel whenever the stop loss is hit, which it does. However, it will fill the order name for whichever hits the stop loss first. How can I set it to where the stop loss for trade 1 is stored separately from trade 2?

        Comment


          #5
          Hello tatir,

          In your conditions you have two of the same condition checking for the name Stop loss. To find the unique order you would either need to submit an exit order with a unique name so the name is something other than just Stop loss or you would need to check the FromEntrySignal name: https://ninjatrader.com/support/help...lightsub=Order

          I look forward to being of further assistance.

          Comment


            #6
            So there isn't a way to set execution.Order.Name as a function of the individual trades?

            I'm also a little lost on how to properly invoke FromEntrySignal for this example.

            Comment


              #7
              Hello tatir,

              The orders name is set when you submit the order however if you used the Set methods like SetStopLoss those have fixed names like Stop loss. You would need to submit an exit type order and provide a name when submitting the order. Alternatively if you use SetStopLoss you would need to use the entries name to know which stop it is. If you had two entries they could have two unique names which you could then see as the FromEntrySignal of the stoploss order.


              I look forward to being of further assistance.

              Comment


                #8
                Originally posted by NinjaTrader_JessicaP View Post
                Hello geekodude, and thank you for your question.

                There are two events, OnOrderUpdate and OnExecutionUpdate, which will allow you to react to Stop Loss and Profit Target orders being triggered. I am including some code which demonstrates how to do so. Please let us know if there are any other ways we can help.
                to access onExecutionUpdate or onPositionUpdate , we use

                account.ExecutionUpdate += OnExecutionUpdate;

                account.PositionUpdate += OnPositionUpdate;

                how do we invoke OnOrderUpdate ???

                Comment


                  #9
                  Hello abhay,

                  It would be the same as the overrides you just don't have "On" in the name, its account.OrderUpdate.

                  I look forward to being of further assistance.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by argusthome, 03-08-2026, 10:06 AM
                  0 responses
                  63 views
                  0 likes
                  Last Post argusthome  
                  Started by NabilKhattabi, 03-06-2026, 11:18 AM
                  0 responses
                  40 views
                  0 likes
                  Last Post NabilKhattabi  
                  Started by Deep42, 03-06-2026, 12:28 AM
                  0 responses
                  21 views
                  0 likes
                  Last Post Deep42
                  by Deep42
                   
                  Started by TheRealMorford, 03-05-2026, 06:15 PM
                  0 responses
                  25 views
                  0 likes
                  Last Post TheRealMorford  
                  Started by Mindset, 02-28-2026, 06:16 AM
                  0 responses
                  51 views
                  0 likes
                  Last Post Mindset
                  by Mindset
                   
                  Working...
                  X