Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Stop loss and Take profit for order created by Account.CreateOrder

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

    Stop loss and Take profit for order created by Account.CreateOrder

    Hello.

    In my strategy I use the Account.CreateOrder() and Account.Submit() methods to submit an order to the exchange. This approach is required by the logic of my strategy.

    Can you please tell me how to send Stop loss and Take profit when such an order is filled?​

    Thank you.

    #2
    Hello anton_tymoshchuk,

    Thank you for your post.

    For a stop loss and profit target, you would need to submit a stop market order and limit order with OCO using Account.CreateOrder.

    ProfitChaseStopTrailIndicatorExample_NT8 demonstrates submitting stop loss and profit target order tied to an entry with Account.CreateOrder():



    Please let us know if you have any further questions.

    Comment


      #3
      Thanks for the reply, Gaby.

      Previously, I tried to use the Account.OrderUpdate event to send Stop loss and Profit target. When I tested the strategy on Sim101 and Playback accounts, everything worked fine. But on a live account, there were cases when the Account.OrderUpdate event didn't work properly.​

      Maybe this problem is related to that:

      With NinjaTrader 8, order objects returned from an order method may not be an equal object to the order object for the same order in OnOrderUpdate.
      From the help guide:
      // Assign entryOrder in OnOrderUpdate() to ensure the assignment occurs when expected.
      // This is more reliable than assigning Order objects in OnBarUpdate, as the assignment is not guaranteed to be complete if it is referenced immediately after submitting.​

      Comment


        #4
        Hello anton_tymoshchuk,

        Can you describe with more detail specifically how the event didn't work properly?

        I recommend studying the provided example. Are you assigning the name of the entry order as "Entry"?

        The example code notes that the name of the order must be Entry or the order will get stuck in the "Initialize" state, which would prevent further updates from the entry order in Account_OrderUpdate.

        Please let us know if you have any further questions.

        Comment


          #5
          Hello Gaby,
          I'm sorry I didn't get back to you yesterday.

          I tried to describe the problem in the TestStrategy_1.cs file below.

          But you were very fortunate to give me a link to a forum post.
          It said:
          With NinjaTrader 8, order objects returned from an order method may not be an equal object to the order object for the same order in OnOrderUpdate.
          From the help guide:
          // Assign entryOrder in OnOrderUpdate() to ensure the assignment occurs when expected.
          // This is more reliable than assigning Order objects in OnBarUpdate, as the assignment is not guaranteed to be complete if it is referenced immediately after submitting.​​

          And I had an idea how to make the code work properly.
          I did it in the TestStrategy_2.cs file below.

          I haven't tested this idea on a real account yet, only on a simulation account.

          Do you think it will help with my problem?

          Thanks for your patience.
          Attached Files

          Comment


            #6
            Hello anton_tymoschuk,

            Thank you for your post.

            I suggest debugging with prints to figure out why your "if (myEntryOrder == e.Order)" isn't evaluating as true. This will help determine what steps you should take to correct the problem.

            In order to better understand how the code is working, it will be necessary to use Print to see how the conditions are evaluating. Print out both the value of myEntryOrder and e.Order.

            Below is a link to a forum post that demonstrates using prints to understand behavior and includes a link to a video recorded using the Strategy Builder to add prints.


            Print the time of the bar and all values used in the conditions that submit entry orders. Include labels for all values and comparison operators.

            Let me know if you need any assistance creating a print.

            Save the output from the output window to a text file and provide this with your reply.

            I'll be happy to assist with analyzing the output.​

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by NullPointStrategies, Today, 05:17 AM
            0 responses
            32 views
            0 likes
            Last Post NullPointStrategies  
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            124 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            64 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            41 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Started by TheRealMorford, 03-05-2026, 06:15 PM
            0 responses
            46 views
            0 likes
            Last Post TheRealMorford  
            Working...
            X