Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Weird behavior of this simple Exit Long order

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

    Weird behavior of this simple Exit Long order

    Hi Ninjas,

    I got a situation here, which I've tried to discover the cause but still.

    It's a simple rutine of exit a long position and cancelling its StopLoss. The script uses the unmanaged approach.

    The order of exitLong:
    Code:
    xlEntryOrder = SubmitOrder(0, OrderAction.Sell, OrderType.Limit, Qty, priceEntry, 0, "", "Exit Long");
    The exit long rutine:
    Code:
    protected override void OnExecution(IExecution execution)
    {
    if (xlEntryOrder != null && xlEntryOrder== execution.Order )					
    			{					
    				if ( xlEntryOrder.OrderState == OrderState.Filled)				
    				{				
    					CancelOrder(slEntryOrder);	 // Cancel the stop order
    					
    					xlEntryOrder = null;		
    				}				
    				if ( xlEntryOrder.OrderState == OrderState.PartFilled )				
    				{				
    					ChangeOrder(slEntryOrder, Position.Quantity-xlEntryOrder.Filled, 0, (Position.AvgPrice-stop));	 // Change the Stop order accordingly
    				}				
    				if ( xlEntryOrder.OrderState == OrderState.Cancelled && xlEntryOrder.Filled > 0)				
    				{				
    					ChangeOrder(slEntryOrder, Position.Quantity-xlEntryOrder.Filled, 0, (Position.AvgPrice-stop));			
    					xlEntryOrder = null;			
    				}				
    			}
    }
    If I just set and let the instruction for "Filled" then everything works perfectly, BUT
    if I add the others PartFilled or Part.Filled and Cancelled, it just simple doesn't run, NT give the typical Run time error.

    So any ideas why this?

    #2
    My guess without debugging is that slEntryOrder is null at this point when its first called

    Consider adding && slEntryOrder!= null before every changeorder check.

    Let me know if I can further assist.
    LanceNinjaTrader Customer Service

    Comment


      #3
      Lance, I appreciate very much your help. As soon as I can code it again I´ll let u know.

      Comment


        #4
        Originally posted by NinjaTrader_Lance View Post
        My guess without debugging is that slEntryOrder is null at this point when its first called

        Consider adding && slEntryOrder!= null before every changeorder check.

        Let me know if I can further assist.
        Lance, following your suggestion I've just simply erase all instructions after the statement of Par.Filled and Part.Filled and cancelled, and the same error...so it's not slEntryOrder..it must be something else that fails to read these normal statements.

        What I think is that I must set these instructions filtering conditions first with the typical: Filled, PartFilled and PartFilled-Cancelled statement and then in a logic breakdown trying not to repeat or interrupt the logic flow. When solved, I'll post it
        Last edited by pstrusi; 12-20-2013, 02:21 PM.

        Comment


          #5
          In this case you'll need to add print statements before and after the different if checks to see where the code is breaking.

          Tips on debugging: http://www.ninjatrader.com/support/f...ead.php?t=3418

          Let me know if I can further assist.
          LanceNinjaTrader Customer Service

          Comment


            #6
            The snippet that solved

            Code:
            if (xlEntryOrder != null && xlEntryOrder== execution.Order )					
            			{					
            				if ( xlEntryOrder.OrderState == OrderState.Filled )				
            				{				
            					CancelOrder(slEntryOrder);			
            					sEntryOrder = SubmitOrder(0, OrderAction.SellShort, OrderType.Limit, quant, priceEntry, 0, "", "Enter Short");			
            				}				
            				else				
            				{				
            					ChangeOrder(slEntryOrder, Position.Quantity-xlEntryOrder.Filled, 0, (Position.AvgPrice-stop));			
            				}				
            				if (xlEntryOrder.OrderState != OrderState.PartFilled )				
            				{				
            					xlEntryOrder = null;			
            				}				
            			}
            Thanks

            Comment


              #7
              Originally posted by NinjaTrader_Lance View Post
              In this case you'll need to add print statements before and after the different if checks to see where the code is breaking.

              Tips on debugging: http://www.ninjatrader.com/support/f...ead.php?t=3418

              Let me know if I can further assist.
              Almost writing at the same time. As you can see in my earlier post, I redesigned the routine, and it was that when you set the main order = null, it shouldn't do more comparison, that's why it did that run time error

              Thanks pal

              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