Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OnOrderUpdate() vs OnOrderExecution()

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

    OnOrderUpdate() vs OnOrderExecution()

    Hi,

    I am new to Ninja Trader and also C#. I have experience with Java so I understand how to build conditions and the principles of OOP.

    I am in the process of writing a strategy and would appreciate it if someone could explain a scenario where you would use OnOrderUpdate()?
    I have looked up this topic but not really found anything that explains it.

    The API states...

    CRITICAL: If you want to drive your strategy logic based on order fills you must use OnExecution() instead of OnOrderUpdate(). OnExecution() is always triggered after OnOrderUpdate(). There is internal strategy logic that is triggered after OnOrderUpdate() is called but before OnExecution() that can adversely affect your strategy if you are relying on tracking fills within OnOrderUpdate().

    To me, that is saying use OnExecution() to check if an order has been filled and then create your stop and limit in this method. So, what would you do in OnOrderUpdate() if it's not the place to create a stop or a limit?

    So far my strategy entered a Long position in the OnBarUpdate() method when some indicator conditions where met

    Code:
    entryOrder = EnterLong(DefaultQuantity,"myLong");
    
    In the OnExecution() method I attempt to create my stop and limit

    Code:
    if (entryOrder != null && entryOrder.Token == execution.Order.Token)
    {
    if (execution.Order.OrderState == OrderState.Filled 
    || execution.Order.OrderState == OrderState.PartFilled)
    {
    if(execution.Order.FromEntrySignal == "myLong")
    {
    stopOrder = ExitLongStop(execution.Order.AvgFillPrice - (2 * TickSize), 
    "Stop Long", execution.Order.FromEntrySignal);
    targetOrder = ExitLongLimit(execution.Order.AvgFillPrice + (4 * TickSize), 
    "Target Long", execution.Order.FromEntrySignal);
    }
    }
    }
    
    When I tested the strategy (EUR/USD 10 minute chart) the Long entry order is placed but neither of the stop or limits are created and the position is closed on exit (I thought the Forex markets didn't close?)

    Where should I be creating the stops and limits in the first place? Any advice help would be appreciated.

    #2
    Welcome to our forums, correct you want to place stop and target orders in OnExecution(), OnOrderUpdate() for example is used if you would like to program your own rejection handling...

    Please work with the TraceOrders feature to debug your order behavior further - http://www.ninjatrader-support2.com/...ead.php?t=3627

    If you want to keep positions overnight, just set ExitOnClose = false as you start / backtest the strategy.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Thank for the response. I've seen on this the forum that responses are very quick and also very helpful.

      I will check into that link for the debugging.

      At least I know that my code is where it should be even if it's not quite doing what I expect at this moment.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by memonolog, Today, 03:30 AM
      0 responses
      2 views
      0 likes
      Last Post memonolog  
      Started by toughiee, Today, 12:04 AM
      0 responses
      4 views
      0 likes
      Last Post toughiee  
      Started by vdoan20, Yesterday, 08:30 PM
      0 responses
      8 views
      0 likes
      Last Post vdoan20
      by vdoan20
       
      Started by gupagoer, Yesterday, 07:42 PM
      0 responses
      10 views
      0 likes
      Last Post gupagoer  
      Started by Holligoly, Yesterday, 05:13 PM
      2 responses
      11 views
      0 likes
      Last Post Holligoly  
      Working...
      X