Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 ageeholdings, Today, 07:43 AM
      0 responses
      7 views
      0 likes
      Last Post ageeholdings  
      Started by pibrew, Today, 06:37 AM
      0 responses
      4 views
      0 likes
      Last Post pibrew
      by pibrew
       
      Started by rbeckmann05, Yesterday, 06:48 PM
      1 response
      14 views
      0 likes
      Last Post bltdavid  
      Started by llanqui, Today, 03:53 AM
      0 responses
      6 views
      0 likes
      Last Post llanqui
      by llanqui
       
      Started by burtoninlondon, Today, 12:38 AM
      0 responses
      12 views
      0 likes
      Last Post burtoninlondon  
      Working...
      X