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

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 traderqz, Today, 12:06 AM
      2 responses
      3 views
      0 likes
      Last Post traderqz  
      Started by RideMe, 04-07-2024, 04:54 PM
      5 responses
      28 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Started by f.saeidi, Today, 08:13 AM
      1 response
      7 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by DavidHP, Today, 07:56 AM
      1 response
      6 views
      0 likes
      Last Post NinjaTrader_Erick  
      Started by kujista, Today, 06:23 AM
      3 responses
      11 views
      0 likes
      Last Post kujista
      by kujista
       
      Working...
      X