Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Need help in Order Management

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

    #16
    Let me clarify. Before calling any exit method, you must currently be in a position. So yes, you "need an open position in market to set stop and profit limits. You need to wait until a position is established or else the stop/target orders will be rejected and you will receive error messages.

    This will work (with some additional filler code):
    Code:
    OnBarUpdate()
    {
        EnterLong("long entry");
    }
    OnPositionUpdate()
    {
        ExitLongStop("long stop", "long entry");
        ExitLongLimit("long target", "long entry");
    }
    And this will not work because there is a delay between when you submit an order and when it is actually filled - thus there is no position for the exit methods to reference:
    Code:
    OnBarUpdate()
    {
        EnterLong("long entry");
        ExitLongStop("long stop", "long entry");
        ExitLongLimit("long target", "long entry");
    }
    Lastly, the signal names will be preserved throughout the life of the order/position.
    AustinNinjaTrader Customer Service

    Comment


      #17
      Thankyou so much Austin.
      Appreciate your patience and extremely valuable guidance. I should be comfortable with this feedback.
      Thanks once again.
      Regards

      Comment


        #18
        I am looking for a feature to identify a closure of an Order/Position. The Order should have opened and closed.
        For instance if “Order1” is closed, set a trail stop to “Order2”
        Can we use the IOrder.Action Attribute? (Action.BuyToCover &Action.SellShort)

        Comment


          #19
          malmaa,

          No, you will have to track it yourself. If you open an order and you added some exit orders to it, just check the OrderState of the exit orders to know when your entry was closed.
          Josh P.NinjaTrader Customer Service

          Comment


            #20
            My Idea is to open the orders in OnBarUpdate, Set the stop limits in Onexecution, and trail the stop again in OnBarUpdate.
            Code:
            IOrder Order1, Order2;
            OnBarUpdate()
            {
            Order1=EnterLongLimit(20000,Orefl.op);
            Order2=EnterLongLimit(10000,Orefl.op);
            OnExecution(IExecution execution)
            {
            ExitShortStop(Stop1,Order1.FromEntrySignal);
            }
            Once the above Order1 is filled, should have to check the “Order1. OrderState”== OrderState.Filled?
            How can we identify between “Entry Buy order” fill and “Exit sell Order” fill?
            I want the Order below to have a trail stop with last bar low.
            ExitShortStop(Stop2,Order2.FromEntrySignal);
            Can some please guide me how to track this orders

            Comment


              #21
              malmaa,

              You need to set another IOrder for your exit stop, just like how you have one for your entry.
              Josh P.NinjaTrader Customer Service

              Comment


                #22
                What do we do after setting IOrder to exit stop?
                Do we compare the “Order1. OrderState”== OrderState.Filled?
                If we want to update Profit Limit and Stop Loss simultaneously, do we have to create two IOrder variables?
                Do you have any sample strategy that can give me better Idea?

                Comment


                  #23
                  We need an open market position to set the Stops and Limits. I used a market entry, but still it doesn't execute. Is their a problem in this code?


                  Code:

                  protectedoverridevoid OnBarUpdate()
                  { IOrder Enter1=
                  null,Stop1=null,Limit1=null;

                  Enter1= EnterLong(
                  10000, "Long1");Print(Enter1.ToString()); // Prints OK
                  Limit1=ExitLongLimit(Enter1.LimitPrice+0.0005, Enter1.FromEntrySignal);Print(Limit1.ToString());// No Print
                  Stop1=ExitLongStop(Enter1.LimitPrice-0.0005,Enter1.FromEntrySignal);Print(Stop1.ToString());// No Print

                  }




                  Output Window:

                  Initialise
                  Order='NT-00000/Sim101' Name='Long1' State=Working Instrument='$GBPUSD' Action=Buy Limit price=0 Stop price=0 Quantity=0.01M Strategy='ArrayStruct' Type=Market Tif=Gtc Oco='' Filled=0 Fill price=0 Token='0eec9225904c4416b61768f1f778d183' Gtd='12/1/2099 12:00:00 AM'

                  Comment


                    #24
                    Bit of improvement. When I print “Limit1” and “Stop1” I get a IOrder.Name as “Sell” I have never used this name. What is this value?
                    This Code works.
                    protectedoverridevoid OnBarUpdate()
                    {
                    Enter1= EnterLong(10000, "Long1");Print("Enter1");Print(Enter1.ToString()); // Prints OK
                    }
                    protectedoverridevoid OnExecution(IExecution execution)
                    {
                    Limit1=ExitLongLimit(Position.AvgPrice + 100 * TickSize, Enter1.FromEntrySignal);Print("Limit1");Print(Limit1.ToString());// Prints OK
                    Stop1=ExitLongStop(Position.AvgPrice - 100 * TickSize,Enter1.FromEntrySignal);Print("Stop1");Print(Stop1.ToString());// No Print

                    } // End of OnExecution

                    Output window:

                    Enter1
                    Order='NT-00000/Sim101' Name='Long1' State=Working Instrument='$GBPUSD' Action=Buy Limit price=0 Stop price=0 Quantity=0.01M Strategy='ArrayStruct' Type=Market Tif=Gtc Oco='' Filled=0 Fill price=0 Token='f5fe659b807d4f3d98f9b2811a6061a2' Gtd='12/1/2099 12:00:00 AM'
                    Limit1
                    Order='NT-00001/Sim101' Name='Sell' State=Working Instrument='$GBPUSD' Action=Sell Limit price=1.5895 Stop price=0 Quantity=0 Strategy='ArrayStruct' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='2fdb7c37323249f39b6e6443b76aa784' Gtd='12/1/2099 12:00:00 AM'
                    Stop1
                    Order='NT-00002/Sim101' Name='Sell' State=Working Instrument='$GBPUSD' Action=Sell Limit price=0 Stop price=1.5875 Quantity=0 Strategy='ArrayStruct' Type=Stop Tif=Gtc Oco='' Filled=0 Fill price=0 Token='7400cf24feab4d999131dc337ff76d63' Gtd='12/1/2099 12:00:00 AM'
                    Enter1
                    Order='NT-00003/Sim101' Name='Long1' State=Working Instrument='$GBPUSD' Action=Buy Limit price=0 Stop price=0 Quantity=0.01M Strategy='ArrayStruct' Type=Market Tif=Gtc Oco='' Filled=0 Fill price=0 Token='2a95191f0d4049f0abd1d32ef844d9ae' Gtd='12/1/2099 12:00:00 AM'
                    Limit1
                    Order='NT-00004/Sim101' Name='Sell' State=Working Instrument='$GBPUSD' Action=Sell Limit price=1.58985 Stop price=0 Quantity=0 Strategy='ArrayStruct' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='d6117d10f02b4e019eda8572d0a0c213' Gtd='12/1/2099 12:00:00 AM'
                    Stop1
                    Order='NT-00005/Sim101' Name='Sell' State=Working Instrument='$GBPUSD' Action=Sell Limit price=0 Stop price=1.58785 Quantity=0 Strategy='ArrayStruct' Type=Stop Tif=Gtc Oco='' Filled=0 Fill price=0 Token='ad13946f5068454e91fd47c70389b80c' Gtd='12/1/2099 12:00:00 AM'
                    Limit1

                    Comment


                      #25
                      Cont to previous question:
                      In the above Output of IOrders returned by EnterLong, ExitLongLimit and ExitLongStop,
                      1. I was told that IOrder.FromEntrySignal remain constant throughout the life of the Order/Position, But it changes. How do we use this Name? There are 3 functions accessing my Orders, OnBarUpdate, OnExecution and one user defined function. I need an attribute to identify the order within these function. Can you please tell me what attribute can I take as reference in all these functions for the purpose of identification?
                      2. Action.Long/Action.Sell is the action done by this statement (entry and Exit methods) and Action.BuyToCover/Action.ShortCover are the result of marketaction on our order(i.e. whether our open position is filled after setting the exit methods). Am I right?
                      3. When I set a Exitstop after ExitLimit, IOrder returned by the Exitstop shows the Limit price=0. Can’t we have an IOrder that shows “Limit price” and “Stop price”?
                      Regards
                      Last edited by malmaa; 01-14-2010, 06:24 AM. Reason: add extra information

                      Comment


                        #26
                        malmaa, I would suggest you first check into the sample codes we have on those topics in the 'reference examples' section of this forums -

                        The OnOrderUpdate() and OnExecution() methods are reserved for experienced programmers. Instead of using Set() methods to submit stop-loss and profit target orders, you can submit and update them manually through the use of IOrder and IExecution objects in the OnOrderUpdate() and OnExecution() methods. The OnOrderUpdate()


                        When using NinjaTrader's Enter() and Exit() methods, the default behavior is to automatically expire them at the end of a bar unless they are resubmitted to keep them alive. Sometimes you may want more flexibility in this behavior and wish to submit orders as live-until-cancelled. When orders are submitted as live-until




                        To get the unique identifiers for each order, you would need to work with the Token values - http://www.ninjatrader-support.com/H...V6/IOrder.html

                        Your printing of the Exit IOrder's return a 'Sell' as this is just the default name for exiting a long position, since you did not set a custom one.

                        Comment


                          #27
                          Bertrand,
                          Thankyou for referring me to the sample files. I have just studied “Sampleonorderupdate.zip”.
                          I want to crosscheck my understanding.
                          1. Ideally a market position is a combination of 3 IOrders, one for entry, one for stop and one for Profit limit. Each having three unique Tokens. These tokens are unique through out their life span. Equally these three IOrders can have three unique user defined “IOrder.Names”.
                          2. We can identify the orders either through “IOrder.Names” or “IOrderTokens”.
                          3. When either of the exit methods (Stop/Profitlimit) orders show an OrderState of “OrderState.Filled” we can confirm that the position is closed.
                          Am I in the right path?
                          As always any comment is highly appreciated?

                          Comment


                            #28
                            1. Correct. Each IOrder is independent of the other and have completely independent and order specific information.

                            2. Correct.

                            3. Correct.

                            When one of the exits has reached a Filled state your position from the related entry order is effectively closed.
                            Josh P.NinjaTrader Customer Service

                            Comment


                              #29
                              Thankyou Josh for your help.
                              I am trying to submit 2 short Limit orders and 2 Long Limit orders. I am unable to execute the script.
                              Can we place both long and short limit orders simultaneously in NT? Can someone Please advice on probable solution.
                              My setting are:
                              On starting a real-time strategy = wait until flat before execution.
                              Order handling = By strategy position
                              Entries per direction =20
                              Entryhandling = UniqueEntries.
                              Mycode:
                              if(Rsdata.Count>0 && Tmcomp(((Reslh)Rsdata[Rf]).tm,Shortord)==false){
                              Print("Enter Short order");
                              Orefs.tm= ((Reslh)Rsdata[Rf]).tm;
                              Orefs.op= ((Reslh)Rsdata[Rf]).l; // Sell Entry limit
                              Orefs.st= ((Reslh)Rsdata[Rf]).h; // Stop limit

                              Ord=EnterShortLimit(0,true,20000,Orefs.op,"Short1" + Scon);Orefs.tk1=Ord.Token;Print(Ord.Token);// Ok
                              Ord=EnterShortLimit(0,true,10000,Orefs.op,"Short2" + Scon);Orefs.tk2=Ord.Token;Print(Ord.Token);// Ok
                              Orefs.or1=null;Orefs.or2=null;Orefs.or3=null;
                              Shortord.Add(Orefs);++Scon;
                              }

                              if(Ssdata.Count>0&& Tmcomp(((Reslh)Ssdata[Sf]).tm,Longord)==false){
                              Print("Enter Long order");
                              Orefl.tm= ((Reslh)Ssdata[Sf]).tm;
                              Orefl.op= ((Reslh)Ssdata[Sf]).h; // Sell Entry limit
                              Orefl.st= ((Reslh)Ssdata[Sf]).l; // Stop limit

                              Ord=EnterLongLimit(0,true,20000,Orefl.op,"Long1" + Lcon);Orefl.tk1=Ord.Token;Print(Ord.Token);// not getting executed
                              Ord=EnterLongLimit(0,true,10000,Orefl.op,"Long2" + Lcon);Orefl.tk2=Ord.Token;Print(Ord.Token);
                              Orefl.or1=null;Orefl.or2=null;Orefl.or3=null;
                              Longord.Add(Orefl);++Lcon;
                              }
                              Output window:
                              Initialise
                              Inside Order Management
                              0
                              1
                              Enter Short order
                              12/31/2009 7:15:00 PM Entered internal PlaceOrder() method at 12/31/2009 7:15:00 PM: Action=SellShort OrderType=Limit Quantity=0.02M LimitPrice=1.6222 StopPrice=0 SignalName='Short10' FromEntrySignal=''
                              76f6219f66d649c787da2bfb4d2f4405
                              12/31/2009 7:15:00 PM Entered internal PlaceOrder() method at 12/31/2009 7:15:00 PM: Action=SellShort OrderType=Limit Quantity=0.01M LimitPrice=1.6222 StopPrice=0 SignalName='Short20' FromEntrySignal=''
                              76b8d897dbab47f4ada555d49e32bcb0
                              Enter Long order
                              12/31/2009 7:15:00 PM Entered internal PlaceOrder() method at 12/31/2009 7:15:00 PM: Action=Buy OrderType=Limit Quantity=0.02M LimitPrice=1.6076 StopPrice=0 SignalName='Long10' FromEntrySignal=''
                              12/31/2009 7:15:00 PM Ignored PlaceOrder() method at 12/31/2009 7:15:00 PM: Action=Buy OrderType=Limit Quantity=0.02M LimitPrice=1.6076 StopPrice=0 SignalName=Long10' FromEntrySignal='' Reason='An Enter() method to submit an entry order has been ignore. Please search on the term 'Internal Order Handling Rules' in the Help Guide for detailed explanation.'

                              Comment


                                #30
                                malmaa, unfortunately this is not possible, as you can see from the trace output - you're running into NT's 'internal order handling rules' with this -

                                http://www.ninjatrader-support.com/H...verview36.html (bottom section of this link)

                                NinjaTrader 7 will offer also an unmanaged approach where you can self manage the order submission process completely in your code -



                                New Unmanaged Order Submission
                                In 6.5 some users were burdened with our "Internal Order Handling" rules. We have introduced unmanaged order submission which bypasses the convenience of our order handling layer. This lower level of programming allows you to do what you want relative to order submission/management without any limitations other than any imposed by your broker. There are only three methods, SubmitOrder(), ChangeOrder() and CancelOrder(). You then get the flexibility of managing your orders how you see fit and optionally handling rejections.

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                                0 responses
                                656 views
                                0 likes
                                Last Post Geovanny Suaza  
                                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                                0 responses
                                370 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by Mindset, 02-09-2026, 11:44 AM
                                0 responses
                                109 views
                                0 likes
                                Last Post Mindset
                                by Mindset
                                 
                                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                                0 responses
                                574 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by RFrosty, 01-28-2026, 06:49 PM
                                0 responses
                                577 views
                                1 like
                                Last Post RFrosty
                                by RFrosty
                                 
                                Working...
                                X