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

Verifying Full Fill of Exit Order

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

    Verifying Full Fill of Exit Order

    I need to verify whether or not my exitOrder has been fully filled before flipping trading direction (i.e. long->short and short->long). Otherwise my new entry order is intermittently being refused as the exit order is still waiting to get filled. Originally I was imagining to handle this in onExecution similar how it's done with entryOrder.

    HOWEVER I already had some logging code in there for the past few years and realized a while ago that it's never been called. So this is basically the extent of it inside of onExecution():

    Code:
    if (exitOrder != null && exitOrder == execution.Order) {
    	Print("###### EXIT ORDER #########");
    }
    I am keeping all my live logs and I parsed through them. That string is absolutely never produced - never ever in live tape either. So it's safe to say that it's not being called or that I'm doing something horribly wrong here.

    Anyway, I thought that this was the perfect place to set a flag signaling that my exit has been filled. However I suspect that the OBU->OOU->OE call sequence is not being followed for exit orders.

    Any input would be appreciated - thanks in advance.
    Last edited by molecool; 09-26-2015, 09:40 AM.

    #2
    Hello molecool,

    Thank you for writing in. This likely indicates that there is a logical issue in your code. If your exitOrder has a signal name, try the following directly inside your OnExecution method:
    Code:
    Print(execution.Name + ": " + execution.Order.OrderState);
    You will see your exit order print out along with all the other orders as they go through the different order states.

    It appears that you may be setting your exit order to null prior to it reaching the statement you provided.

    OnExecution is the correct place to check whether your order has been filled and you would check it using something like the following:
    Code:
    if(execution.Order.OrderState == OrderState.Filled && execution.Order == exitOrder)
    {
    //Fully filled. It not fully filled, the OrderState will return OrderState.PartFilled and will not meet the above condition
    }
    Another option would be that you did not name the IExecution object "execution" where you override the method. For example:
    Code:
    protected override void OnExecution(IExecution e){}
    instead of:
    Code:
    protected override void OnExecution(IExecution execution){}
    Please let me know if I may be of further assistance.
    Last edited by NinjaTrader_MichaelM; 09-27-2015, 12:14 PM.
    Michael M.NinjaTrader Quality Assurance

    Comment


      #3
      Spot on!

      Brilliant input Michael - you were exactly right, I had set exitOrder to null in OnOrderUpdate. Now per your suggestion I can get execution.Order.OrderState to show a fill on a stop or an an exit (per that first line you suggested). But it seems that when onExecution() gets called my own exitOrder or stopOrder objects have already been set to null.

      In any case, this allows me to track this problem more effectively should another rejection occur. In OnBarUpdate I am also making sure that exitOrder is either null or if it is not null that it has been fully filled.

      Let's see how that goes.

      Thanks a lot for chiming in - very helpful
      Last edited by molecool; 09-27-2015, 12:53 PM.

      Comment


        #4
        Hello molecool,

        Thank you for the update. I am glad to hear I was able to be of assistance and that you were able to resolve the issue.

        Please have a great rest of your weekend!
        Michael M.NinjaTrader Quality Assurance

        Comment


          #5
          Originally posted by NinjaTrader_MichaelM View Post
          Hello molecool,

          Thank you for the update. I am glad to hear I was able to be of assistance and that you were able to resolve the issue.

          Please have a great rest of your weekend!
          Thanks - I'm not sure it's resolved just yet but will chime in here if I run into any further problems.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by fx.practic, 10-15-2013, 12:53 AM
          5 responses
          5,403 views
          0 likes
          Last Post Bidder
          by Bidder
           
          Started by Shai Samuel, 07-02-2022, 02:46 PM
          4 responses
          94 views
          0 likes
          Last Post Bidder
          by Bidder
           
          Started by DJ888, Yesterday, 10:57 PM
          0 responses
          6 views
          0 likes
          Last Post DJ888
          by DJ888
           
          Started by MacDad, 02-25-2024, 11:48 PM
          7 responses
          158 views
          0 likes
          Last Post loganjarosz123  
          Started by Belfortbucks, Yesterday, 09:29 PM
          0 responses
          8 views
          0 likes
          Last Post Belfortbucks  
          Working...
          X