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

    #31
    Dierk,

    In TS you don't have to specify the exit from entry, therefore you can just go long 2 contracts, and send to exit orders at two different limit prices. the platform will know if one order been filled and will not sent it again.

    when reversing just send an order to sell 2 contracts at limit, the platform will flatten you and then get you short 2 contracts.

    the user/programmer don't need to handle all this process manually.

    looking forward to learn if it possible to scale out without reference to entry and without the need for 2 entries.

    thx
    nir

    Comment


      #32
      Thanks for clarification. You need to proceed as per Josh's post #26. There is no way around.

      Comment


        #33
        Hi Josh,

        It been a while, but I need your advise on this issue again.
        I followed your advise on this order management issue, and when I have a reversal signal, I am first closing the position. than so far I have tried to send the new position on the OnExecution() of the closed position with condition of marketposition = flat.

        it been tested and worked fine until today.... when I got in real-time the Order entry error.

        I guess it is because the order cancel confirmation for my original exit from the exchange have not arrived before I have tried to send a reversal order. I am checking for the position to be flat, do I also need to check the status of the exit and stop orders to be cancelled? will the rules limitations work on both of them or only on the exit limit?

        I have a multi entry approach (i.e. entry1, entry2, ...) when I am reversing I need to make sure that I am flat but also that all my stops and targets been cancelled, how would I know where to put my new orders? (I want them in the market as soon as possible, how will I know which cancel to monitor?

        is there any way to check that there are no orders in the market before I am sending the limit order?

        any help would be appriciated.

        reagrds,
        Nir

        Comment


          #34
          Nir,

          I'm not sure what error you are running into. It may be advisable to wait for all your old unwanted orders to be dealt with to a terminal state before proceeding with new orders. To check that there are no orders left in the market you would just need to know how many you sent and check them out inside OnOrderUpdate(). Keep a tally of when you get the Cancelled OrderState on all relevant IOrders. When you get them all you should be good to go again.
          Josh P.NinjaTrader Customer Service

          Comment


            #35
            Hi Josh,

            Thx for your response.
            As my entry check to be flat before sending the new entry order I assume that the only rule I can have problem with is this one: "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 "

            not sure I understand it, but let me explain what I have. lets say I was long 3 contracts, I have in market the following exit orders:
            1. stop order bellow the market
            2. target limit order above the market
            3. another target limit order way above the market to be used as a close order to enable reversal (I am doing it to overcome the bug you have with terminal exit order... that prevent me from submitting and cancelling the exit order more than one time)

            now I am getting a reversal signal, I am doing the following
            1. Changing the price of order number 3 above to close the open position.
            2. monitoring the onexecution to make sure the order has been fully closed.
            3. Sending my short limit order after checking again that the market position is flat.

            on this scenario I received on Friday the error of Order Handling Rules.
            Could it be that I have tried to send the short limit order before the other two open orders (limit target and stop market) been cancelled and confirmed as cancelled as the position was closed?


            Following your advise I changed the location of the monitoring to the cancelation of all the orders (i.e. When all open orders been confirmed as cancelled I would send my short limit), when checking it with your simulator feed real-time it is working as expected, however when I look at historical times (back testing or on the chart but for previous trades) the system never manage to get into the opposite position (position is closed but the short limit signal is not sent by the strategy).

            It is important to know that I am monitoring 16 iOrders for the cancel (as I have 4 different entry names) to make sure I am sending my short limit only once, I added a condition that all 16 iOrders are null and that I am flat, maybe in back testing this condition never met, while in real life it should always happen (when the last cancelation confirmation is returned from the exchange)?

            Or could it be that in back test you are not monitoring the cancel of orders therefore my orders are not send?

            It would be great if you could explain more on the Order Handling Rules and confirm if my scenario I am using caused the problem as I suspect?
            Also please let me know if I should change my code and monitor the iOrder in a different manner to avoid this problem.

            Thx for your response,
            Nir

            Comment


              #36
              Nir,

              The condition is there to prevent placing two opposite entry orders. I believe you should not have any problem submitting entry orders even with exit orders active.

              A condition in which you will hit that specific rule would be if you say had an EnterLongLimit() active for your 3rd contract. Reversal signal comes. If you submitted an EnterShortLimit() immediately you would get the Internal Order Handling Rule.

              As far as for why it doesn't seem to work in backtesting, please try simplifying your strategy. You will want to try and debug it. See the changes in IOrder states and compare it to when you are submitting your orders. Then layer on additional levels of complexity.

              I am not sure what the exact code you have for monitoring is right now, but essentially you just want to make sure that you don't have two EnterLongLimit()/ShortLimit()/etc. orders active at the same time.
              Josh P.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              599 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              344 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              103 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              558 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              557 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X