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

cancel an order not filled after 30 secondes

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

    cancel an order not filled after 30 secondes

    Hi

    i'm running a strategy on 5 minutes close and i would like to cancel my entryorder if it is not filled after 30 secondes.

    How can i do this ?

    i know the method to cancel the order after x number of bar, but here this is a different approached... i'm running in 5 minutes and i want to cancel it after 30 secondes.

    #2
    Hello Thomas79,

    Thank you for your post.

    This would require adding another bar series such as the 30 seconds bar type and setting your strategy to CalculateOnBarClose = False and use the FirstTickOfBar to calculate your 5 minute bar close conditions.

    For information on using CalculatOnBarClose = False and FirstTickOfBar please visit the following link: http://www.ninjatrader.com/support/f...ad.php?t=19387

    For information on using multiple time frames in your code please visit the following link: http://www.ninjatrader.com/support/h...nstruments.htm

    Please let me know if I may be of further assistance.

    Comment


      #3
      quite complicated... it'a pity that

      elseif (entryOrder != null && CurrentBar > barNumberOfOrder + 0.1)
      {
      CancelOrder(entryOrder);
      }

      does not work.

      0.1 = 30 secondes within a 5 minutes bars...

      Comment


        #4
        Hello Thomas79,

        Thank you for your response.

        That would not work as the OnBarUpdate() is called on the close of the 5 minute bar as you currently have it set up. You would need to to use something like the following:
        Code:
                protected override void Initialize()
                {
        			Add(PeriodType.Second, 30);
        			CalculateOnBarClose = true;
                }
        		
        		protected override void OnBarUpdate()
        		{	
        			if(BarsInProgress == 0)
        			{
        				//Process items on 30 seconds close.
        			}
        			if(BarsInProgress == 1)
        			{
        				//Process items on the 5 minute close.
        			}
        		}

        Comment


          #5
          Originally posted by Thomas79 View Post
          Hi

          i'm running a strategy on 5 minutes close and i would like to cancel my entryorder if it is not filled after 30 secondes.

          How can i do this ?

          i know the method to cancel the order after x number of bar, but here this is a different approached... i'm running in 5 minutes and i want to cancel it after 30 secondes.
          As you are not working with COBC = false, you will have to use a different event handler that runs independently of OnBarUpdate(). OnMarketData() comes to mind.
          1. You will have to record the time of the order,
          2. then use OnExecution() to set a flag if the order is filled,
          3. then use OnMarketData() to cancel the order, if the flag is not set.

          Alternatively, you could cancel the order if Position.MarketPosition is still MarketPosition.Flat; in which case you do not need the tracking from OnExecution().
          Last edited by koganam; 04-30-2014, 06:18 AM.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by warreng86, 11-10-2020, 02:04 PM
          7 responses
          1,360 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by Perr0Grande, Today, 08:16 PM
          0 responses
          5 views
          0 likes
          Last Post Perr0Grande  
          Started by elderan, Today, 08:03 PM
          0 responses
          9 views
          0 likes
          Last Post elderan
          by elderan
           
          Started by algospoke, Today, 06:40 PM
          0 responses
          10 views
          0 likes
          Last Post algospoke  
          Started by maybeimnotrader, Today, 05:46 PM
          0 responses
          14 views
          0 likes
          Last Post maybeimnotrader  
          Working...
          X