Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Filtering non-proper states of an order to work with

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

    Filtering non-proper states of an order to work with

    Hi ninjas,

    I'm coding under unmanaged approach, therefore it's necessary to think every tiny aspect of a logic flow in order to avoid errors. Sometimes weird time errors arise without any logic programming explanation. I suspect that this might be cause the order could be returned with certain error or "non-proper" state to work. At this moment I don't know which is the best method to call what the actual error status of an order is, thus I work just with all other general known states.

    I did this little snippet, which might be non very useful but my intention is filtering orders if they have a proper state to work with.
    Code:
    protected override void OnExecution(IExecution execution)			
    {			
    	if (lEntryOrder != null && lEntryOrder == execution.Order)		
    	{		
    		if (lEntryOrder.OrderState == OrderState.PendingCancel || lEntryOrder.OrderState == OrderState.PendingChange || lEntryOrder.OrderState == OrderState.PendingSubmit || lEntryOrder.OrderState == OrderState.Unknow)	
    		{	
    			return;
    		}	
    		if (lEntryOrder.OrderState == OrderState.Filled || lEntryOrder.OrderState == OrderState.PartFilled || (lEntryOrder.OrderState == OrderState.Cancelled && lEntryOrder.Filled > 0))	
    		{	
                          // Work
                    }
            }
    }
    1. Will "return" get back the flow control until a proper state is achieved ?

    2. Is there any method to know if an order has been returned with some error?

    #2
    Originally posted by pstrusi View Post
    1. Will "return" get back the flow control until a proper state is achieved ?
    Yes, this would prevent further action if the order was in any of the states you listed.

    Originally posted by pstrusi View Post
    2. Is there any method to know if an order has been returned with some error?
    Depending on what you're looking to, you may want to consider working in OnOrderUpdate which is guaranteed to be called before OnExecution and should always give you the correct states of the order.

    Since currently checking in OnExecution, this logic would only work if an order that was in pending submit, etc was executed, which is not possible.

    Of course if you only want to program logic to take action after an execution, it's best to work in OnExecution, however if your goal is for checking for order updates and states, it's best to then work in OnOrderUpdate first.
    MatthewNinjaTrader Product Management

    Comment


      #3
      Thanks Matthew for the clear answers. I'll will do the logic changes as you suggested, you're right

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by DeskTroll, Today, 12:09 PM
      3 responses
      23 views
      0 likes
      Last Post NinjaTrader_LuisH  
      Started by Pabulon, 12-02-2024, 03:42 PM
      14 responses
      90 views
      0 likes
      Last Post Pabulon
      by Pabulon
       
      Started by tfa2806trader, Today, 12:04 PM
      10 responses
      25 views
      0 likes
      Last Post tfa2806trader  
      Started by trdninstyle, 11-26-2024, 12:23 PM
      62 responses
      186 views
      0 likes
      Last Post trdninstyle  
      Started by lorien, 08-08-2021, 07:33 AM
      12 responses
      722 views
      0 likes
      Last Post AndyM871  
      Working...
      X