Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.

        BertrandNinjaTrader Customer Service

        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.

            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 elirion, Today, 01:36 AM
                2 responses
                12 views
                0 likes
                Last Post elirion
                by elirion
                 
                Started by DJ888, 04-16-2024, 06:09 PM
                5 responses
                14 views
                0 likes
                Last Post NinjaTrader_Erick  
                Started by samish18, Yesterday, 08:31 AM
                4 responses
                14 views
                0 likes
                Last Post elirion
                by elirion
                 
                Started by funk10101, Yesterday, 09:43 PM
                1 response
                14 views
                0 likes
                Last Post NinjaTrader_Gaby  
                Started by TheWhiteDragon, 01-21-2019, 12:44 PM
                5 responses
                551 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Working...
                X