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
    JesseNinjaTrader Customer Service

    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
        JesseNinjaTrader Customer Service

        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.
            JesseNinjaTrader Customer Service

            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?
                  JesseNinjaTrader Customer Service

                  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.
                        JesseNinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by rajeshks1988, 01-13-2021, 12:00 PM
                        10 responses
                        1,256 views
                        0 likes
                        Last Post konganda  
                        Started by M_ichel, 04-22-2025, 02:21 PM
                        7 responses
                        58 views
                        1 like
                        Last Post brucerobinson  
                        Started by michelz, 02-18-2025, 08:30 AM
                        33 responses
                        1,054 views
                        0 likes
                        Last Post MiCe1999  
                        Started by volIQ, 04-23-2025, 05:43 PM
                        4 responses
                        38 views
                        0 likes
                        Last Post volIQ
                        by volIQ
                         
                        Started by algospoke, 04-21-2025, 06:44 PM
                        2 responses
                        48 views
                        0 likes
                        Last Post MiCe1999  
                        Working...
                        X