Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Order Handling Rules: How can I switch sides with limit orders?

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

    #16
    now I am really confused. I am trying to have a simple strategy that would have an entry with lets say 2 targets and one stop. entry is with limit order. sometimes I would need to reverse the position before target 2 has been filled (could be before or after target 1 been filled).

    I am reversing with limit order as well.
    so far I have used 2 entry orders (naming entry1 and entry2) and got my exit via the SetProfitTarget( using entry name).

    now as far as I understand it, I can't reverse a position with a limit order unless I cancel the limit profit target. therefore I understand now that I can't use the setprofittarget at all.

    so if I want to use the exitlonglimit could I use the same functionality of setprofittarget xx ticks from entry, or do I need to start and maintain a set of vars that will keep entry price, etc'.

    I have also seen a sample on your refrance site to monitor the IOrder token of setstop and setprofit target, could i use this methood to cancel the orders?

    as stated in the begging I am evaluating your platform, I am a TS user, this reversal should be very simple to achive but so far I am getting problems achiving it. could you point me to some refrance code that simply reversing a position with a limit order?

    any indication to the best way to approach this "simple" logic would be highly appriciated.

    thx again for all your support.

    Nir

    Comment


      #17
      No reference code available.

      Entry price is maintained in Position.AvgPrice.

      Yes, you could use the method to cancel orders.
      RayNinjaTrader Customer Service

      Comment


        #18
        could you please advise which method is preferred:
        1. using SetProfitTarget() and cancel it before reversing - please clarify if possible, as far as I understand advantage is that target/stop order will be sent to the market as soon as the entry fills.
        2. using exitlonglimit() - here I am not sure if I need to cancel or just not resend when I want to reverse - will the stop and target orders be sent to the market as soon as I am getting a fill on the entry or just on the next bar update?

        thx for your support on this.
        Nir

        Comment


          #19
          1. No, you can't cancel orders generated by SetProfitTarget() or any other Set...() methods

          2.
          - Next OnBarUpdate() unless you send them on a fill of an order which you would find out about in OnExecution() - There are reference samples on this
          - You would resubmit if you did not use the "liveUntilCancelled" option. See the prior link for information on advanced order handling.
          RayNinjaTrader Customer Service

          Comment


            #20
            I still didn't manage to make it work.
            I am trying to create basic reverse strategy. using limit orders.

            I have removed all exit code, still when I am using 2 entries, when I am flat I can enter a position, however when I am trying to reverse I am getting eror and only one entry is getting reversed.

            to ilustrate the problem I have used your sampleMACrossOver code with modification to the entry as limit orders and using 2 entries. see attached:

            I would appriciate if someone can tell me what am I doing wrong.

            #region Variables
            private int fast = 10;
            private int slow = 25;
            #endregion

            /// <summary>
            /// This method is used to configure the strategy and is called once before any strategy method is called.
            /// </summary>
            protected override void Initialize()
            {
            SMA(Fast).Plots[0].Pen.Color = Color.Orange;
            SMA(Slow).Plots[0].Pen.Color = Color.Green;

            Add(SMA(Fast));
            Add(SMA(Slow));

            CalculateOnBarClose = true;
            }

            /// <summary>
            /// Called on each bar update event (incoming tick).
            /// </summary>
            protected override void OnBarUpdate()
            {
            if (CrossAbove(SMA(Fast), SMA(Slow), 1))
            { EnterLongLimit(1,Low[0],"Long1");
            EnterLongLimit(1,Low[0],"Long2");
            }
            else if (CrossBelow(SMA(Fast), SMA(Slow), 1))
            { EnterShortLimit(1,High[0],"Short1");
            EnterShortLimit(1,High[0],"Short2");
            }
            }

            #region Properties
            /// <summary>
            /// </summary>
            [Description("Period for fast MA")]
            [Category("Parameters")]
            public int Fast
            {
            get { return fast; }
            set { fast = Math.Max(1, value); }
            }

            /// <summary>
            /// </summary>
            [Description("Period for slow MA")]
            [Category("Parameters")]
            public int Slow
            {
            get { return slow; }
            set { slow = Math.Max(1, value); }
            }
            #endregion
            }
            }


            Nir

            Comment


              #21
              Please describe the error you are receiving. The way you have it coded will require you to have EntriesPerDirection set to more than 1. Also, if you managed to fill both longs before your reversal condition when the reversal hits 1 short order should be enough to force a closing of both your long positions simply because you can't be short unless you have closed your longs.
              Josh P.NinjaTrader Customer Service

              Comment


                #22
                the error is as follows:
                when I am flat and getting an entry signal both Long1 and Long2 are executed. however, lets say I am long with 2 contracts, and I am getting a reversal to the short, the longs will be closed and the system will get me short, however only on short1 and the short2 order is ignored.

                I am not sure that I am approaching it properly, my final aim is to have 1 entry with 3 exit targets. and during this time, I might have a reversal signal which means for me to close open position and reverse with full size again all done with limit orders.

                I did not manage to do so and was under the impression it is because of the order handling roles however, even when I am not using any exits I still don't manage to get a simple reverse to work when I have 2 entries.

                I understood that I need more than one entri in order to have the 3 separate exit, if there is a better way to do it, please let me know.

                Comment


                  #23
                  To scale out of a position please refer to the reference sample section for the Scaling Out sample.

                  In regards to the issue you have here it is most likely due to the internal order handling rules. Please type out the exact error as outputted by TraceOrders and in the Control Center logs. Otherwise I am just shooting out ideas in the dark.

                  The rule that you are most likely in contention with is this one:

                  Methods that generate orders (excluding market orders) to enter a position will be ignored if:
                  • The strategy position is flat and an order submitted by an enter method (EnterLongLimit() for example) is active and the order is used to open a position in the opposite direction
                  Josh P.NinjaTrader Customer Service

                  Comment


                    #24
                    thx Josh for trying to help me on this.

                    please find an extract from the ordertrace where the first instance of the reversing is failed:

                    30/06/2008 00:49:00 Entered internal PlaceOrder() method at 30/06/2008 00:49:00: Action=SellShort OrderType=Limit Quantity=1 LimitPrice=1281.25 StopPrice=0 SignalName='Short1' FromEntrySignal=''
                    30/06/2008 00:49:00 Entered internal PlaceOrder() method at 30/06/2008 00:49:00: Action=SellShort OrderType=Limit Quantity=1 LimitPrice=1281.25 StopPrice=0 SignalName='Short2' FromEntrySignal=''
                    30/06/2008 01:02:00 Entered internal PlaceOrder() method at 30/06/2008 01:02:00: Action=Buy OrderType=Limit Quantity=1 LimitPrice=1281.75 StopPrice=0 SignalName='Long1' FromEntrySignal=''
                    30/06/2008 01:02:00 Entered internal PlaceOrder() method at 30/06/2008 01:02:00: Action=Buy OrderType=Limit Quantity=1 LimitPrice=1281.75 StopPrice=0 SignalName='Long2' FromEntrySignal=''
                    30/06/2008 01:02:00 Ignored PlaceOrder() method at 30/06/2008 01:02:00: Action=Buy OrderType=Limit Quantity=1 LimitPrice=1281.75 StopPrice=0 SignalName=Long2' 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.'
                    30/06/2008 01:03:00 Cancelled expired order: BarsInProgress=0: Order='NT-00002/Back101' Name='Close position' State=Working Instrument='ES 09-08' Action=BuyToCover Limit price=1281.75 Stop price=0 Quantity=2 Strategy='ReversingSample' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='ae1514c4d5d6446091e6af0694d0e535' Gtd='01/12/2099 00:00:00'
                    30/06/2008 01:03:00 Cancelled expired order: BarsInProgress=0: Order='NT-00003/Back101' Name='Long1' State=Working Instrument='ES 09-08' Action=Buy Limit price=1281.75 Stop price=0 Quantity=1 Strategy='ReversingSample' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='a9124774c3544e4281046a6543555ac3' Gtd='01/12/2099 00:00:00'
                    30/06/2008 01:27:00 Entered internal PlaceOrder() method at 30/06/2008 01:27:00: Action=Buy OrderType=Limit Quantity=1 LimitPrice=1281.75 StopPrice=0 SignalName='Long1' FromEntrySignal=''
                    30/06/2008 01:27:00 Entered internal PlaceOrder() method at 30/06/2008 01:27:00: Action=Buy OrderType=Limit Quantity=1 LimitPrice=1281.75 StopPrice=0 SignalName='Long2' FromEntrySignal=''
                    30/06/2008 01:28:00 Cancelled expired order: BarsInProgress=0: Order='NT-00004/Back101' Name='Close position' State=Working Instrument='ES 09-08' Action=BuyToCover Limit price=1281.75 Stop price=0 Quantity=2 Strategy='ReversingSample' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='2fddb2ed711447528781ebe600f86dec' Gtd='01/12/2099 00:00:00'
                    30/06/2008 01:28:00 Cancelled expired order: BarsInProgress=0: Order='NT-00005/Back101' Name='Long1' State=Working Instrument='ES 09-08' Action=Buy Limit price=1281.75 Stop price=0 Quantity=1 Strategy='ReversingSample' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='9431b8bd74134807b1e261cb41870839' Gtd='01/12/2099 00:00:00'
                    30/06/2008 02:36:00 Entered internal PlaceOrder() method at 30/06/2008 02:36:00: Action=Buy OrderType=Limit Quantity=1 LimitPrice=1282.50 StopPrice=0 SignalName='Long1' FromEntrySignal=''
                    30/06/2008 02:36:00 Entered internal PlaceOrder() method at 30/06/2008 02:36:00: Action=Buy OrderType=Limit Quantity=1 LimitPrice=1282.50 StopPrice=0 SignalName='Long2' FromEntrySignal=''

                    the code is the code I posted earlier.

                    the first 2 short orders at 00:49 got filled, than there is the reverse order at 01:02 that being ignored. long2 has been ignored, and during the day everytime an order "2" is sent it is ignored (though I am not getting the error message again.

                    the entries per direction is set to 1
                    the entry handling to UniqueEntries

                    I followed the sample of the scaleout reference you provided this is why I am trying to use 2 entries.

                    my real objectives will be to have also exits but first I am trying to be able to reverse with simple limit orders, so far with no success.

                    I have tried to understand why you imposing the internal Order Handling Rules and have to admit that I am not sure why you impose them, it is very limiting to the type of strategy that I am trying to do which in other platforms that I am using (Tradestasion ) is very simple to do.

                    again the code I sent you was only a try on my side to have a simple limit order reversal when you have more than one entry. if you think it would be more approperiate to get this functionality in a diffrent way instead of finding why this code is not working I am more than happy to explore, I am intrestead in the logic (i.e. reverse via a limit order when you have a scaleout functionality)

                    again thx for your support on this.

                    Comment


                      #25
                      Have not followed the thread on all details but here is an issue:

                      >> the entries per direction is set to 1
                      >> the entry handling to UniqueEntries
                      This for sure is a problem, you would need to set 2 in order to enter on 2 different signals Long1 and Long2. Please make sure you read and understood the section in the docs on 'Internal Order Handling Rules'.

                      Comment


                        #26
                        Ok nfeldberg,

                        Basically in a nutshell why the Internal Order Handling Rules are required is because of the various "weirdness" cases that can happen if those rules are violated.

                        For instance, if you take two EnterShortLimit() orders while in a long position already this is what can happen. Problem is in order for any of these orders to actually bring you into the desired position of short they need to close position on your previous long. What could happen is say order 2 assumes order 1 will close long position for it so instead it just gets filled on 1 short. In actuality order 1 didn't close long position for it and order 1 was actually cancelled. Now you are stuck being flat.

                        Any combination of this scenario can happen. End up flat, end up with double the short amounts, end up in weird scenarios basically. It becomes a mess.

                        Your ultimate goal is still very viable. I suggest in your scenario to avoid Internal Order Handling Rules you explicitly exit your previous position. Check for Position.MarketPosition to be flat. Then submit your next position's orders. You can do this very cleanly with the OnOrderUpdate() and OnExecution() methods.
                        Josh P.NinjaTrader Customer Service

                        Comment


                          #27
                          Dierk, based on the sample of scaleout by Jose, it looks it should be set to 1. (unique for each entry signal). regardless when it set up to 2 the result is the same.
                          I have read many times your Order handling rules, what I am not clear is if it it possible to do what I am trying to achieve with the ninja platform.
                          I am new to the platform and evaluating it now, my aim is very simple, to have a position with 1 entry and several limit exits and one stop. following the sample on scaleout, I understood that I need to use 2 entries in the way I used them. (i.e. long 1 that eventually will get out at target 1, and long2 that will get out at target 2).

                          my strategy would also need to reverse with a limit order. the reverse is the part of functionality that so far I did not manage to do.

                          could you please tell me if it is possible to do it? or your platform internal rules are not allowing it? if it is possible please help me and tell me what method to use?

                          thx for all of you of trying to help me, however, it would be great if you would tell me what method I need to use to achieve what I am trying to do.

                          it is a very basic functionality and not relates to my program, I am trying to reverse a position that built from more than 1 entry (to enable scaleout) with limit order.

                          thx

                          Comment


                            #28
                            Josh,
                            following your suggestion would mean an advance programming, which I would need to explore, however, to try to simplify things, are there any other ways to scaleout of position with out more than one entry? (i.e. 1 entry, 3 exit, 1 stop) than I might be able to reverse without the need to manage the flattern of the position.

                            I understand your approach however, it is very complicated and advance to manage each order in this manner. this is even before I will need to probebly also cancel the limit and stop orders for the targets and stops....

                            thx again for your support.

                            Comment


                              #29
                              Originally posted by NinjaTrader_Dierk View Post
                              ...
                              >> the entries per direction is set to 1
                              >> the entry handling to UniqueEntries
                              This for sure is a problem, you would need to set 2 in order to enter on 2 different signals Long1 and Long2. ...
                              My apologies, I stand corrected on the meaning of "UniqueEntries"

                              Comment


                                #30
                                Curious: What would be the equivalent TS EL code? Thanks

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                                0 responses
                                620 views
                                0 likes
                                Last Post Geovanny Suaza  
                                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                                0 responses
                                359 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by Mindset, 02-09-2026, 11:44 AM
                                0 responses
                                105 views
                                0 likes
                                Last Post Mindset
                                by Mindset
                                 
                                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                                0 responses
                                562 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by RFrosty, 01-28-2026, 06:49 PM
                                0 responses
                                566 views
                                1 like
                                Last Post RFrosty
                                by RFrosty
                                 
                                Working...
                                X