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 NullPointStrategies, Yesterday, 05:17 AM
    0 responses
    65 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    139 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    75 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    45 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    50 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X