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

Order Rejected

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

    Order Rejected

    My order is being rejected during market replay I presume because the Market moving so quick.
    So then NT disables and stops running the strategy. I guess what I would like to happen is if this scenario occurs, I would simply like to close the position. How can I accomplish this? What is your advice for this scenario?
    Attached Files

    #2
    Originally posted by reynoldsn View Post
    How can I accomplish this? What is your advice for this scenario?
    See this:


    Code:
     RealtimeErrorHandling = RealtimeErrorHandling.TakeNoAction;
    Then check for OrderState.Rejected in OnOrderUpdate(), and close position if found.

    Unfortunately, the popup message box from NinjaTrader cannot be disabled.

    Comment


      #3
      Your code running in market replay at 1x or 500x follows the same order of events and should work without issue.

      So does it happen in 1x also?

      Post some complete sample code that reproduces the problem and someone might be able to offer a fix/suggestion to your issue. There isn't enough to go on based on your post.

      Comment


        #4
        OK, I would like to implement your suggestion using OnOrderUpdate. Is there a more complete example I can see?

        Comment


          #5
          UPDATE:

          Here is my abbreviated, pertinent code. Does it look like a correct implementation as far as handling order rejection?
          My concern is that now I am using:
          Code:
          RealtimeErrorHandling = RealtimeErrorHandling.TakeNoAction;
          Are there other order problems I now need to manually check?
          Thank you!

          Code:
          private IOrder stopLossOrder = null;
          
          protected override void Initialize()
          {
          	RealtimeErrorHandling = RealtimeErrorHandling.TakeNoAction;
          	
          	SetProfitTarget(sENTRY1L, CalculationMode.Ticks, _profitTarget);
          	SetProfitTarget(sENTRY1S, CalculationMode.Ticks, _profitTarget);
          	SetStopLoss(CalculationMode.Ticks, _stopLoss);
          	
          	//Init order objects
              iOrderL1 = null;
              iOrderS1 = null;	
          
          	EntriesPerDirection = 100;
          	EntryHandling = EntryHandling.AllEntries;
          
          	CalculateOnBarClose = true;
          }
          
          protected override void OnBarUpdate() {
          if (_takeTrade) {
          	EnterShort(1, sENTRY1S);
          	if (stopLossOrder == null) 
          		stopLossOrder = ExitShortStop(Position.AvgPrice + _stopLoss * TickSize); 
          }
          }
          
          protected override void OnOrderUpdate(IOrder order) 
          { 
          	if (stopLossOrder != null && stopLossOrder == order) 
          	{
          		// Rejection handling 
          		if (order.OrderState == OrderState.Rejected) 
          		{
          			// Stop loss order was rejected !!!! 
          			// Do something about it here 
          			Print("Order Rejected at: " + Time[0]);
          		} 
          	}
          }

          Comment


            #6
            Looks like a good start.

            Right after you detect the OrderRejected, say, after your Print,
            exit your position and set your stopLossOrder to null.

            I think RealTimeErrorHandling documentation says this variable
            only deals with order rejected errors.

            Overfill processing, for example, is controlled by a different variable,
            called IgnoreOverFill.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by proptrade13, Today, 11:06 AM
            0 responses
            1 view
            0 likes
            Last Post proptrade13  
            Started by kulwinder73, Today, 10:31 AM
            1 response
            10 views
            0 likes
            Last Post NinjaTrader_Erick  
            Started by RookieTrader, Today, 09:37 AM
            3 responses
            15 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by terofs, Yesterday, 04:18 PM
            1 response
            24 views
            0 likes
            Last Post terofs
            by terofs
             
            Started by CommonWhale, Today, 09:55 AM
            1 response
            6 views
            0 likes
            Last Post NinjaTrader_Erick  
            Working...
            X