Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OnExecution vs OnOrderUpdate?

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

    OnExecution vs OnOrderUpdate?

    I have a strategy that trades multiple instruments. I only want one active order at a time. So I am using this to make sure I do not have more than one active order:

    Code:
     
    protected override void OnBarUpdate()
    {
        if (entryOrder == null && Close[0] > Open[0])
    [SIZE=2]     entryOrder = EnterLongLimit(GetNumSharesToBuyViaAccountSize(Close[0]), Instrument.FullName);[/SIZE]
    }
    Will either of these work to clear out the object after the trade is placed?
    Code:
     
    protected override void OnExecution(IExecution execution) {
    if (entryOrder != null && entryOrder == execution.Order) {
    Print(execution.ToString());
    entryOrder = null;
    }
    }
     
    protected override void OnOrderUpdate(IOrder order) {
    if (entryOrder != null && entryOrder == order) {
    Print(order.ToString());
    if (order.OrderState == OrderState.Filled)
    entryOrder = null;
    }
    }
    I also need to keep track of how much money is in my account so I assume I will need to use IOrder.AvgFillPrice and IOrder.Quantiy
    Does it make a difference weather I use OnExecution or OnOrderUpdate for gathering this information?
    For the partial fill case will OnOrderUpdate and/or OnExecution get called mutiple times with
    OrderState.PartFilled and then one final time with
    OrderState.Filled or do I just agregate the values when I get OrderState.PartFilled?

    I will be using MB Trading so how does this effect the code:

    When using MBT and NinjaScript strategies in combo, please be aware of the disclaimer we added to the MBT account creation process -

    MB Trading position events are generated before orders are executed. Since NinjaTrader relies on execution events to come prior to position events, you will experience limitations with tracking positions from the Strategies tab of the Control Center and trying to rely on the standard sequence of events (order execution before position) in NinjaScript.
    Thanks,
    Erik

    #2
    Hello,

    It does not matter which method you use and the OnOrderUpdate() will be called multiple times for each order state. Please see order state definition here:



    Let me know if I can be of further assistance.
    BrettNinjaTrader Product Management

    Comment


      #3
      Is there a way to force partial fills in backtesting?

      In 6.5 there was an option for ByStrategyPosition vs PerEntryExecution in the script order handling section of options dialog. Is this still configurable if so where and what is the default?

      Thanks,
      Erik

      Comment


        #4
        Erik,

        Those options were only applicable in real-time in 6.5 likewise in 7. When you add a strategy, there is an option under the Order Handling section of the strategy parameters that lets you select ByStrategyPosition or PerEntryExecution. Default is PerEntryExecution.

        There is no way to force partial fills in a backtest. If the price is penetrated, it will fill you on the order completely. Partial fill testing needs to be done in real-time.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Josh,

          I did not notice when I was looking at ByStrategyPosition or PerEntryExecution before that it is only for Stop Losses and Profit targets. Does this mean for EnterLong and ExitLong calls I do not need to worry about incurring extra commisions?

          Thanks,
          Erik

          Comment


            #6
            Hello,

            Yes if there submitted as seperate orders, i.e. scaling in to a position.

            However if you get a partial fill your broker will not charge you double commission.

            Let me know if I can be of further assistance.
            BrettNinjaTrader Product Management

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            633 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            364 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            105 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            567 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            568 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X