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 Mindset, 04-21-2026, 06:46 AM
    0 responses
    87 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    134 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    68 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    118 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    67 views
    0 likes
    Last Post PaulMohn  
    Working...
    X