Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Close Positions after a CancelAllOrders() delay

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

    Close Positions after a CancelAllOrders() delay

    I need to do conceptually something like:

    Code:
    Order closeOrder;
    ​
    int quantity = 10;
    
    myAccount.CancelAllOrders(myInstrument);
    
    sleep(xx);
    ​
    closeOrder = myAccount.CreateOrder(myInstrument, OrderAction.Sell, OrderType.Market, OrderEntry.Automated, TimeInForce.Day, quantity, 0, 0, "myOCO", "closeOrder", Core.Globals.MaxDate, null);
    
    myAccount.Submit(new[] { closeOrder });
    ​
    The question is about the xx value.
    Do I need to place a delay between canceling all orders and place a new order ?

    Best
    Gio

    #2
    Hello Gio,

    For the NinjaTrader connection type, no, a delay would not be necessary.

    For the Rithmic and Interactive Brokers connection types, a delay may be benificial.

    We do not recommend sleeping any NinjaScript thread.

    We instead recommend using a timer.
    Provides a mechanism for executing a method on a thread pool thread at specified intervals. This class cannot be inherited.

    Join the official NinjaScript Developer Community for comprehensive resources, documentation, and community support. Build custom indicators and automated strategies for the NinjaTrader platforms with our extensive guides and APIs.


    Attached is an example that paces order submissions, which you could adapt to cancellations and modifications as well.
    PaceTradeCopyAddonExample_NT8.zip
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thank you Chelsea, your answer is very useful.
      Without any responsibility on your part, and this is Rithmic stuff anyway, have you heard that in experience of others, 50ms delay is beneficial (just to throw a number) or 10mS might be sufficient? I'll go by trial and error, but maybe you have an idea what a good number might work generally ok.
      Best
      G

      Comment


        #4
        Hello G,

        Unfortunately, I haven't had any feed back on this.

        I would like to know if this is particularly effective and at what delay.

        Please assign enableDebuggingPrints a value of true on line 118, then test assigning the timerInterval on line 121 values of 1ms, 2ms, 3ms, 5ms, etc, until the behavior can be avoided or until 50ms.
        Each time the code is changed and compiled, the addon window will need to be closed and a new window opened from the New menu > Account Order Examples > Pace Trade Copy Addon Example.
        Please report back and provide the output from the output window produced by the script saved to a text file (right-click the output window.
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Today, 05:17 AM
        0 responses
        19 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        119 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        63 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        41 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        45 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X