Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Connection lost when buy order is filled

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

    Connection lost when buy order is filled

    I am currently using the Unmanaged Order Methods Approach.
    When my long order gets filled, I submit a stop order.

    protected override void OnOrderUpdate(IOrder order)
    {
    if (entryOrder != null && entryOrder == order)
    {
    //Print("ORDER"+order.ToString());

    // Stoploss on fill

    if (order.OrderState == OrderState.Filled)
    {
    entryOrder = null;
    double stopLoss = (entry.m_exitType==ExitType.CHANDELIER) ? entry.m_stopLossCH: entry.m_stopLossSZ;
    Print("StopLoss "+stopLoss+" "+stopLoss);
    stopOrder = SubmitOrder(0, OrderAction.SellShort, OrderType.Stop, entry.m_tradeSize, 0, stopLoss, "", "PullBack");
    prevExit= stopLoss;
    }
    }

    ...

    (1) If the connection is lost when my long order gets filled, the stop order will not be submitted.
    How can I recover from this situation and submit the stop order when the connection is back ?

    (2) How does the managed approach deals with this situation ?

    Thank you for the help !

    #2
    Hello arnold.horvath,

    Thank you for your post.

    The behavior of the strategy during disconnect such as the number of restart attempts and the handling of the strategy can be controlled by going to the NinjaTrader Control Center > Tools > Options > Strategies > NinjaScript > On Connection Loss: http://www.ninjatrader.com/support/h...tegies_tab.htm

    You also have the ability to override the OnConnectionStatus() method in NinjaScript, this will give you additional control over the behavior of the strategy during connection loss and re-connect: http://www.ninjatrader.com/support/h...tionstatus.htm

    Managed and Unmanaged methods will react the same to a disconnect and re-connect based on the settings above.

    Please let me know if you have any questions.

    Comment


      #3
      Hi Patrick !

      Thank you for the answer.

      (1) Does this mean that according to the default settings if the disconnect is longer than
      20 minutes ( 4 restart attemps x 5 minutes restart ) and my buy order gets filled during the disconnect, the strategy will stop without placing a stop loss order ?

      (2) Can you please provide a code snippet how I can achieve, that after a successful reconnect before the above
      mentioned 20 minutes, the StopLoss order gets submitted ? It is still not clear how to do that.

      (3) I believe, that Order Handling section on Strategies/Ninjascript tab refers to the Managed approach.Am I right ?
      Arnold
      Last edited by arnold.horvath; 07-29-2013, 09:48 PM.

      Comment


        #4
        Hello Arnold,

        Thank you for your response.
        Originally posted by arnold.horvath View Post
        (1) Does this mean that according to the default settings if the disconnect is longer than
        20 minutes ( 4 restart attemps x 5 minutes restart ) and my buy order gets filled during the disconnect, the strategy will stop without placing a stop loss order ?

        (2) Can you please provide a code snippet how I can achieve, that after a successful reconnect before the above
        mentioned 20 minutes, the StopLoss order gets submitted ? It is still not clear how to do that.

        (3) I believe, that Order Handling section on Strategies/Ninjascript tab refers to the Managed approach.Am I right ?
        1. The 'Restarts within x minutes' is the time span for the restarts, meaning by default 4 restart attempts within 5 minutes.
          If you order is filled during disconnect (meaning no connection to your broker) then NinjaTrader has no way of knowing this and the stop will not be submitted. If the max restarts are attempted within the 'Restarts within x minutes' option's duration the strategy will be disabled.
        2. There is no need for a code snippet, if a successful connect is made during the 'Restart within x minutes' option and the order to enter was filled and NinjaTrader receives this update from the broker then the stop will be submitted. If there is no successful connection within the 'Restarts within x minutes' option then the strategy is disabled and no stop order is submitted.
        3. The Order Handling options directly refer to cancelling exit and/or entry orders when a strategy is disabled, the Order Method Approach whether Unmanaged or Managed has no factor on this setting.

        Please let me know if I may be of further assistance.

        Comment


          #5
          Hi Patrick !

          Thank you for the answer.

          There must be something that I misunderstand. Let me rephrase my question.

          "If you order is filled during disconnect (meaning no connection to your broker) then NinjaTrader has no way of knowing this and the stop will not be submitted. "

          This is very true, however when the connection is back, NinjaTrader somehow has to know, that an order got filled during the disconnect, otherwise the strategy could wreak havoc.
          E.g. After a disconnect, NinjaTrader could ask the status of the orders and it can realize, that an order got filled during the disconnect and act accordingly and also set the stop loss.
          I am not at all familiar with the brokerage protocol, and there are several alternatives to recover from error scenarios like this. The question is how Ninjatrader can support such a recovery.

          Or is there something wrong with my reasoning and this is not an issue at all ?

          Thank you,
          Arnold

          Comment


            #6
            You are correct in noticing there could be problem when a strategy reconnects in this manor.

            First you will want to decide how you want your strategy to be handled when the connection is lost. This is the information Patrick provided before: http://www.ninjatrader.com/support/h...tegies_tab.htm

            Then when enabling/restarting the strategy you have other options to keep in mind as well. Such as, do you want your strategy to attempt to recognize the previously placed order or not. A complete description of these can be found here:http://www.ninjatrader.com/support/h..._positions.htm

            Video example: http://www.youtube.com/watch?v=US9cK...A140D7&index=5

            Keep in mind, automated system does not mean walk away. Connection or power loss can occur. When this happens you will have to manually handle your orders.
            LanceNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            599 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            345 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            103 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            558 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            558 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X