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 JonesJoker, 04-22-2024, 12:23 PM
          8 responses
          41 views
          0 likes
          Last Post JonesJoker  
          Started by timko, Today, 06:45 AM
          0 responses
          3 views
          0 likes
          Last Post timko
          by timko
           
          Started by Waxavi, 04-19-2024, 02:10 AM
          2 responses
          37 views
          0 likes
          Last Post poeds
          by poeds
           
          Started by chbruno, Yesterday, 04:10 PM
          1 response
          44 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by Max238, Today, 01:28 AM
          1 response
          25 views
          0 likes
          Last Post CactusMan  
          Working...
          X