Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to cancel unfilled orders at a certain time

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

    How to cancel unfilled orders at a certain time

    Hi all,

    Completely new to writing strategies but have put something together that is working how i want for the most part.

    The final issue's im contending with are that I want the strategy to perform as follows:

    - If time[0] = x time then close any unfilled orders
    - if time[0] = x time and an order is open then leave the associated stop loss and take profit orders open

    Not sure if this is info you need to help but all orders in my strategy are set using SetProfitTarget, SetStopLoss, EnterLongLimit, and EnterShortLimit.

    Additionally everything is currently done in onBarUpdate().

    Sorry if this has been answered elsewhere but I couldnt find anything.

    Thanks in Advance!

    #2
    Hello NewbieTrader91,

    Thank you for your post.

    If you are new to NinjaScript, please read through this forum post on getting started:

    https://forum.ninjatrader.com/forum/...040#post786040

    You can use ToTime() to calculate an integer representing a time to use in your comparison.

    https://ninjatrader.com/support/help...nt8/totime.htm

    Please see this example script in the Help Guide which demonstrates using time filters:

    https://ninjatrader.com/support/help...to_limit_t.htm

    For an example of how to cancel an order, please see the sample script from the Help Guide linked below:

    https://ninjatrader.com/support/help...thod_to_ca.htm

    Please note that set methods like SetStopLoss cannot be cancelled, you will need to use an exit method like ExitLongStopMarket() (with isLiveUntilCancelled as true).

    ExitLongStopMarket - https://ninjatrader.com/support/help...stopmarket.htm

    Additionally, orders are cancelled by calling CancelOrder() with the order object saved to a variable in OnOrderUpdate().

    Please let me know if I may assist further.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    47 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    23 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    33 views
    1 like
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    51 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    42 views
    0 likes
    Last Post CarlTrading  
    Working...
    X