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

Cancelling the remained of a partial fill

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

    Cancelling the remained of a partial fill

    if i have an entry order which is only partially filled - which triggers stop/target orders upon execution

    how can you cancel the the remaining open porportion, without effecting the stop and target orders that are live for the filled proportion

    #2
    Hello,
    You can accomplish this through advanced order handling through checking within the OnOrderUpdate() event method when a partial fill has occurred for the entry IOrder object.
    For more information on OnOrderUpdate() please see the following link: http://ninjatrader.com/support/helpG...rderupdate.htm
    For more information on the IOrder objects please see the following link: http://ninjatrader.com/support/helpG...nt7/iorder.htm

    I would also recommend to review the following reference sample on cancelling orders and using the OnOrderUpdate() event method: http://ninjatrader.com/support/forum...ad.php?t=18890

    If we can be of any other assistance please let us know.
    Cody B.NinjaTrader Customer Service

    Comment


      #3
      thanks Cody, do you have an example of how this can be done?

      Comment


        #4
        Hello,
        I have provided an example of how you could do this below:
        Code:
        private IOrder entryOrder = null;
        
        protected override void Initialize()
        {
                CalculateOnBarClose = true;
        	SetStopLoss(CalculationMode.Ticks, 20);
        	SetProfitTarget(CalculationMode.Ticks , 10);
        }
        
        protected override void OnBarUpdate()
        {
        	if(Historical)
                	return;
        	if(Close[0] > Open[0])
        	{
        		entryOrder = EnterLong(10 , "myEntry");	
        	}
        			
        }
        protected override void OnOrderUpdate(IOrder order)
        {
        	if(entryOrder != null && entryOrder == order)
        	{
        		if(order.OrderState == OrderState.PartFilled) 
        		{
        			CancelOrder(entryOrder);
        		}		
        			
        	}		
        }
        Please let me know if you have any questions about the example.
        Cody B.NinjaTrader Customer Service

        Comment


          #5
          thanks for example.

          rather than cancel immediately if i only get a part fill in OnOrderUpdate, what i am trying to do is cancel an entry order (the whole order or the remaindering proportion if i have got a part fill ) if the bid gets above the entry price by a certain level ( ie to cancel the order if i missed an entry fill and market gets too far away)

          How do i check the orderstate of the entry order from within the OnBarUpdate section


          if (entryOrder != null
          && entryOrder == Orderstate.Working // dont think this is correct
          && LongOrder == true
          && GetCurrentBid() < EntryLine +.10)
          {
          CancelOrder(entryOrder);
          }

          Comment


            #6
            Hello,
            I have provided below an example on how you can check the order state of the entryOrder and if it is still working:
            Code:
            protected override void OnOrderUpdate(IOrder order)
            {
            	if(entryOrder != null && entryOrder == order)
            		if(order.OrderState == OrderState.Working 
                                //DoSomething
            	}
            }
            Please let me know if you have any questions on the example.
            Cody B.NinjaTrader Customer Service

            Comment


              #7
              Cody - can you provide example that would work in OnBarUpdate for each new tick

              the example you have provided is for the OnOrderUpdate which will not check the condition often enough as it would only work when their is a change in the order.

              i am having difficult applying your example to OnBarUpdate

              Comment


                #8
                Hello,
                You can check the orderstate of an IOrder object by checking its property. For more information on the IOrder properties please see the following link: http://ninjatrader.com/support/helpG...nt7/iorder.htm
                Please see the example below to check the order state in OnBarUpdate:

                Code:
                private IOrder entryOrder = null;
                
                protected override void OnBarUpdate()
                {
                	if(SMA(20)[0] > EMA(20)[0] && entryOrder == null)
                		entryOrder = EnterLong();
                			
                	if(entryOrder != null && entryOrder.OrderState == OrderState.Working)
                		//DoSomething
                }
                Cody B.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by helpwanted, Today, 03:06 AM
                1 response
                11 views
                0 likes
                Last Post sarafuenonly123  
                Started by Brevo, Today, 01:45 AM
                0 responses
                9 views
                0 likes
                Last Post Brevo
                by Brevo
                 
                Started by aussugardefender, Today, 01:07 AM
                0 responses
                5 views
                0 likes
                Last Post aussugardefender  
                Started by pvincent, 06-23-2022, 12:53 PM
                14 responses
                242 views
                0 likes
                Last Post Nyman
                by Nyman
                 
                Started by TraderG23, 12-08-2023, 07:56 AM
                9 responses
                387 views
                1 like
                Last Post Gavini
                by Gavini
                 
                Working...
                X