Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Unmanaged Long Limit order fills immediately in Strategy Analyzer

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

    Unmanaged Long Limit order fills immediately in Strategy Analyzer

    I am writing a strategy using unmanaged orders. One of the orders is a long limit order that I'm setting up like this

    Code:
    this.LongOrder = SubmitOrderUnmanaged(0, OrderAction.Buy, OrderType.Limit, this.OrderQuantity, longPrice, 0, oco, "Long Order");
    If this is *not* the correct way to place a long limit order, please let me know.

    In my case, this.OrderQuantity = 1, longPrice = 4140.25 and was submitted at a current price of 4130 on a candle with a high of 4131.25. The problem is that the Strategy Analyzer is immediately filling the long limit order at the high of the current candle instead of waiting for the target price to hit.

    This is the dump of the order object from the above code:
    orderId='NT-00000-137' account='Backtest' name='Long Order' orderState=Working instrument='ES 06-23' orderAction=Buy orderType='Limit' limitPrice=4140.25 stopPrice=0 quantity=1 tif=Gtc oco='oco1120290241' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2023-04-13 09:30:00' gtd='2099-12-01' statementDate='2023-04-18'

    And this is the dump of the filled order from OnExecutionUpdate():
    orderId='NT-00000-137' account='Backtest' name='Long Order' orderState=Filled instrument='ES 06-23' orderAction=Buy orderType='Limit' limitPrice=4140.25 stopPrice=0 quantity=1 tif=Gtc oco='oco1120290241' filled=1 averageFillPrice=4131.25 onBehalfOf='' id=-1 time='2023-04-13 09:30:00' gtd='2099-12-01' statementDate='2023-04-18'

    Note the limitPrice of 4140.25 and the averageFillPrice of 4131.25 -- that is not correct as far as I can tell, I'm calling SubmitOrderUnmanaged correctly for a long limit order. The only way I can get it work correctly is to change it to a stop limit order and use the same price in the limitPrice and stopPrice parameters, like so:

    Code:
    this.LongOrder = SubmitOrderUnmanaged(0, OrderAction.Buy, OrderType.StopLimit, this.OrderQuantity, longPrice, longPrice, oco, "Long Order");
    To me, this feels like a hack -- I should be able to do a long limit order with my first code example, shouldn't I?



    #2
    Hello furman87,

    A limit order fills at the specified price or better. Meaning if the market price is better, it will fill at market.

    Below is a link to investopedia on how each order type works.



    A buy limit is placed below the current ask price.
    A sell limit is placed above the current bid price.

    If a buy limit (even when placed manually) is placed at or above the ask, it fill immediately at the ask, as the ask is a better price.

    If you want to place a working buy order above the ask, use a stop market order or stop limit order.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      I guess if I just right-clicked on the chart it would have told me which types of orders were valid -- duh on my part. Thanks for making me think more clearly!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by NullPointStrategies, Yesterday, 05:17 AM
      0 responses
      65 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      139 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      75 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      45 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      50 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X