Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Sample code for OCO

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

    Sample code for OCO

    Hi,

    I am new to NT8 and I am reading managed approach and unmanaged approach for order management. Can somebody please share the code that do OCO using both approach?

    thanks

    laketrader

    #2
    Hello laketrader,

    OCO is only a programming task in the unmanaged approach, in the managed approach you use signal names. You can find an example that uses OCO strings here: https://ninjatrader.com/support/foru...926#post486926

    Comment


      #3
      Hi Jesse,

      Thank you for the quick response. I updated with UnmanagedOCOBracketExample.cs with onBarUpdate with the code from SampleMACrossover strategy. And it worked great. But I tried to put the same code in a NT8 addon. I got " Object reference not set to an instance of an object." error when I put the follwing statement:
      SubmitOrderUnmanaged(0, OrderAction.Buy, OrderType.Market, 1, 0, 0, "", "longStopEntry");

      Is there any restriction to SubmitOrderUnmanaged for NT8 addon?

      thanks

      laketrade

      Comment


        #4
        Hello laketrader,

        Addon's can't use the strategy frameworks, you would have to use the account directly to place orders from an addon. I would suggest looking at the addon sample here: https://developer.ninjatrader.com/do...pment_overview

        Comment


          #5
          Hello,

          Addon cannot use the strategy framework. How about indicator framework? Can an Addon call or use the indicators provided from ninjascript editor?

          thanks

          laketrader

          Comment


            #6
            Hello laketrader,

            Addons can only use the addon framework. There is not a way to use indicators from an addon because addons are not linked to a Series like indicators or strategies in a chart. Addons are mainly for creating custom tools with custom user interfaces.

            Comment


              #7
              Please see the next post with the correct cs file
              Last edited by laketrader; 03-23-2025, 08:16 PM.

              Comment


                #8
                Hi,

                I started to write my very first addon based on the sample that Jesse pointed out. I just would like to test how the order submission works. So the addon is just submmting a marker order every x seconds.

                The addon compiled and ran without any error. The timer was working but I cannot see the orders in "Order" tab of control center. The code was attched. Where did I do wrong?

                thanks

                laketrader​
                Attached Files

                Comment


                  #9
                  Hello laketrader,

                  That may be due to the timer, if you move your order placement code to just inside the button handler so when the button is clicked do you see it working?

                  Comment


                    #10
                    Hi Jesse,

                    I moved the code insider the button hanlder. But got the following error. (see the attachment)

                    thanks

                    laketrader
                    Attached Files

                    Comment


                      #11
                      the modified code attached as well
                      Attached Files

                      Comment


                        #12
                        You would have to check which part of the code is causing that. That error means an object you tried to use was null.

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                        0 responses
                        563 views
                        0 likes
                        Last Post Geovanny Suaza  
                        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                        0 responses
                        329 views
                        1 like
                        Last Post Geovanny Suaza  
                        Started by Mindset, 02-09-2026, 11:44 AM
                        0 responses
                        101 views
                        0 likes
                        Last Post Mindset
                        by Mindset
                         
                        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                        0 responses
                        547 views
                        1 like
                        Last Post Geovanny Suaza  
                        Started by RFrosty, 01-28-2026, 06:49 PM
                        0 responses
                        548 views
                        1 like
                        Last Post RFrosty
                        by RFrosty
                         
                        Working...
                        X