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

  • pstrusi
    replied
    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

    Leave a comment:


  • pstrusi
    replied
    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

    Leave a comment:


  • NinjaTrader_Lance
    replied
    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.

    Leave a comment:


  • pstrusi
    replied
    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.

    Leave a comment:


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

    Leave a comment:


  • NinjaTrader_Lance
    replied
    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.

    Leave a comment:


  • pstrusi
    started a topic Weird behavior of this simple Exit Long order

    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?

Latest Posts

Collapse

Topics Statistics Last Post
Started by leunating, Today, 12:56 AM
2 responses
17 views
0 likes
Last Post leunating  
Started by tmk-c, 07-19-2017, 11:29 PM
6 responses
1,687 views
0 likes
Last Post Brightredmegaphone  
Started by Trader4Life, Today, 09:20 PM
0 responses
5 views
0 likes
Last Post Trader4Life  
Started by WileCoyote, Today, 08:26 PM
0 responses
8 views
0 likes
Last Post WileCoyote  
Started by madankumars, 11-18-2019, 11:12 AM
10 responses
176 views
0 likes
Last Post ulisesguerrero  
Working...
X