Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OCO Orders

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

    OCO Orders

    Hello,

    I am trying to code a simple one cancels the other (OCO) order. I want to submit a long and a short order (with set profit target and a set stop loss) and once one of them gets executed, the other should be cancelled and there should not be any more orders for the day (execute only once per day).

    I would sincerely appreciate any help on how to code this in NinjaScript.

    Thanks.

    #2
    questforconsistency,

    I am happy to assist you.

    You could submit a short limit and a long limit, then if one of them is filled you simply cancel the other.

    You would need to use the unmanaged order approach however : http://www.ninjatrader.com/support/h...d_approach.htm

    You could do all your opposite order cancellation in the OnExecution method. For more information, please see the link below.



    Please let me know if I may assist further.
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      Adam,

      How do I code to see if the stop limit order is filled or not? I want to only take one trade per day so I have a counter which needs to be updated but only after the stop limit order is filled. How can I code a condition that checks weather or not an order was filled? Also, once the order is filled, I want to set profit target and stop loss but how do I do this in unmanaged order approach?

      Thanks.

      Comment


        #4
        questforconsistency, you can check for the fillstate directly in the OnExecution(), which is the topic of the reference sample Adam referred you to. This would also be the earliest possible point to submit your exits, you would do this with the SubmitOrder() method in the unmanaged approach, both exit orders could be linked together via the OCO string.

        Comment


          #5
          Bertrand,

          Thanks for reply. I am still trying to figure out how to code this correctly but meanwhile I have a related question. For profit target and stop loss, I want to use price points which are created by a third party (proprietary) indicator. This third party indicator draws lines on my charts everyday and I want to take those values and set profit targets and stop loss once the price reaches to or falls under one of these price levels. Is this possible and if so how?

          Thanks.

          Comment


            #6
            Hello,

            Thanks for the note.

            Is the strategy trying lines with the Plot() command or the DrawLine() command are you aware?

            Are you using the indicator output anywhere else in your strategy or would this be the first time accessing it?

            I look forward to assisting you further.
            BrettNinjaTrader Product Management

            Comment


              #7
              Since the Indicator is a third party proprietary, I am not sure if its drawing line with Plot() or Drawline(). I am not calling for the indicator output anywhere else in the program. This would be the first instance to call for the indicator output so that I can use its value as set profit target and set stop loss values.

              Comment


                #8
                You can tell if the indicator has plots from the right click > Indicators screen. Select the indicator and see if there are plots for the indicators parameters.

                Without having access to the indicator source code, plots are the only value type you could properly expose from it.
                Attached Files
                Ryan M.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                646 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                367 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                107 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                569 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                573 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X