Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to know when a partial order filled is a complete fill in OnExecutionUpdate

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

    How to know when a partial order filled is a complete fill in OnExecutionUpdate

    In my strategy I want to allow multiple attempts to take a trade from a specific unique signal. When a position is open for an attempt, the second attempt is NOT taken until I am flat again. I am only flat after the first position is closed when one of the Set methods is triggered (i.e. SetStopLoss/SetProfitTarget). I am keeping track of attempts by incrementing a counter whenever the a position is opened. However, I want to make sure the counter does NOT increment only if a partial fill occurred. I only want to increment the counter if all quantities are filled.

    Right now, I am using the OnExecutionUpdate method to know when the position that was opened. Below is my pseudo code. My question is:

    1) How do I know if that ordered that was filled is an order that filled all the positions. Like I want to make sure it was not a partials fill. Right now, I am checking by doing execution.Order.OrderState == OrderState.Filled. Is this a valid apporach?


    Code:
    protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time)
    {
    
    string order_name = execution.Order.Name;
    bool is_filled = execution.Order.OrderState == OrderState.Filled ? true : false;
    
    if (is_filled)
    {
    if (order_name == my_active_signal_label)
    {
    attempt_counter += 1;
    }
    }
    
    }
    ​​

    #2
    Hello wzgy0920,

    You can see an example of how to do that in the help guide page for OnExecutionUpdate https://ninjatrader.com/support/help...ghtsub=onexecu
    JesseNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Jesse View Post
      Hello wzgy0920,

      You can see an example of how to do that in the help guide page for OnExecutionUpdate https://ninjatrader.com/support/help...ghtsub=onexecu
      I have read that link. Let me clarify my question.

      Assuming my desired trade quantity is 5x. First time is a partial pill with quantity of 2x. The second fill results in completion of the partial fill with quantity of 3x. When the second fill occurs, what will be the value of execution.Order.OrderState and execution.Order.Filled? I know during the first partial fill, execution.Order.OrderState will equal OrderState.PartFilled and execution.Order.Filled will equal 2. But during the second partial fill, what will the values be?

      Comment


        #4
        Hello wzgy0920,

        You would need to do exactly like that sample shows to detect that. You would accumulate the quantities for all fills to a variable and then look for the last fill which has that total quantity. You technically don't need to even look for part fills but that also handles submitting targets based on the part fills to avoid mismatched targets.
        JesseNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by TraderYoda, 05-24-2019, 03:33 AM
        43 responses
        2,115 views
        1 like
        Last Post pwmmmm
        by pwmmmm
         
        Started by jb805, 02-04-2025, 12:34 PM
        5 responses
        163 views
        0 likes
        Last Post Swagpapifrio  
        Started by Newtrader101, Today, 11:27 AM
        1 response
        5 views
        0 likes
        Last Post NinjaTrader_Clayton  
        Started by mrmccraig, Yesterday, 05:13 PM
        2 responses
        20 views
        0 likes
        Last Post mrmccraig  
        Started by proptradingshop, Yesterday, 11:30 AM
        10 responses
        36 views
        0 likes
        Last Post proptradingshop  
        Working...
        X