Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Converting Limit to Market

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

    Converting Limit to Market

    I've written code using a custom timer object to convert limit orders to market orders if not filled within 'x' seconds of being hit. However when I'm trying to test this code running NinjaTrader's simulator, the order is filled immediately upon the price being hit, so none of my code is executing. Is there a way to debug this aside from going live?

    #2
    Use real-time feed, trade in Sim101, set simulator (Tools > Options) to enforce partial fills, test on an illiquid market so you don't get a lot of trades so the simulator will not fill fast.
    RayNinjaTrader Customer Service

    Comment


      #3
      I'm testing this and my order is getting double filled. It seems that the limit order fills once the price is hit, then the timer submits another order causing a second fill. Here is the code I'm using:

      Code:
      protected override void OnBarUpdate()
      {
      //Send Order:
      LE = EnterLongLimit(amt,price,"LE");
      
      //Track if Price has been touched:
      if (LE!=null && Low[0]<=LE.LimitPrice)
          pricetouched=ToTime(DateTime.Now);
      }
      Then I have a timer object which calls this method.

      Code:
      private void MyCustomHandler(object state)
      {
      if (LE!=null && LE.OrderState==OrderState.Working && pricetouched!=0 && ToTime(DateTime.Now)-convertseconds>pricetouched)
          {
              LE=EnterLongLimit(amt,Close[0]+4*TickSize,"LE");
          }
      }
      I also reset pricetouched to 0 in the OnExecution() method.

      Comment


        #4
        toptrader,

        Not sure I follow. If your limit price is touched and you get part filled on the limit order this is expected no? You want to go ahead and check for such a PartFilled order state if you don't want to submit market order any more after a part fill.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Well whether I am part filled or not, I want to amend the limit order 'x' number of seconds after the price is hit. I thought sending an order with the same order name would simply amend the working order, but it appears to be submitting a completely separate order. I read in another thread that it is faster to amend the order as opposed to cancel and submit a market order, however from what I've seen and your comments below it seems like I should check for a partial fill, cancel the current order and submit a new order for the balance. Does this sound correct?

          Comment


            #6
            You need to use TraceOrders = true to figure out what it is doing. If your order was filled for sure you will end up submitting a new order.
            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
            576 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            334 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
            553 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            551 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X