Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Data farm connection issue causes stop loss to fail (not execute)

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

    Data farm connection issue causes stop loss to fail (not execute)

    Hi,

    On 21-March-2016 I had data farm connection issues and this had unexpected results.

    A stop loss order for a short position at 5154 did not execute. Log shows order with state of Unknown. Position remained as 1 contract short.

    When the strategy (my code - not auto exit on close) next issued orders to close the position near the end of the session, the stop loss then executed at 5154 and then the market BuyToCover order (to close the position) took 1 contract long at 5152.

    Fortunately I was watching and closed the position a minute later (for a small profit - you gotta be lucky sometimes).

    My question is what can be done about this in the future? If a stop loss order (or any other order) results in the order state being unknown, what can be done. Is it up to the developer to write more advanced error handling or is NinjaTrader going to process????

    attached is the NinjaTrader log file from 21-March-2016 and an image of the market replay.

    Thanks in advance,
    Ivan
    Attached Files
    Last edited by AusTrader; 03-22-2016, 05:20 PM.

    #2
    Hello AusTrader,

    The errors are connection loss errors. If NinjaTrader loses the connection it is not able to send and importantly receive messages back and forth from the brokerage connecetion. These messages are important as they track the state of the orders and allow progression of orders. Further if data stops and the strategy is no longer receiving data, it will not be able to perform any logic such as issuing or modifying orders.

    I'm finding very frequent disconnections occurring in your log and this will disrupt NinjaTrader's ability to track orders.

    My recommendation would be to use a VPS with a steady internet connection to prevent this behavior.

    Manually disconnecting and then reconnecting will cause NinjaTrader to disable the strategies and then poll the orders on the account on reconnect. When re-enabling this should allow the strategies to begin working correctly.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi Chelsea,

      thanks for your response.

      I understand that connection loss errors restrict the ability of NT to send and receive message from the brokerage connection and that this is critical.

      I have a VPS with speedytradingservers.com in Chicago. I trade this strategy with Interactive Brokers TWS (connected in the region America - so it is close to Chicago).
      I have been running this strategy for 9 months. These connection errors may have been happening previously (I do not know for sure) but never before at a critical time for the strategy.

      So the situation was:
      The strategy had submitted a stop loss order to IB and was accepted and executed at the appropriate time (confirmed via IB Activity Statement). The strategy (because of broker connection issues) got an order state of Unknown for this order when it executed.
      The strategy has RealtimeErrorHandling set to the default (which I understand is StopStrategyCancelOrdersClosePosition), so why did the strategy not stop when the error was received. It continued on thinking there was a position and tried to "Close" it later (as I have coded it) - which just opened a new position in the opposite direction.

      Why did RealTimeErrorHandling not stop the strategy?

      More questions:

      If in the future I change to RealTimeErrorHandling = TakeNoAction and program exception handling, how do I test the code? Does NinjaTrader have and option to turn the broker connection on and off for the simulated accounts so you can test your exception handling code?

      Thanks for your help,
      Ivan

      Comment


        #4
        Hello AusTrader,

        The RealTimeErrorHandling would not stop the script if the order was in an unknown state. This setting is for rejected orders only.
        From the help guide:
        "Defines the behaviour of a strategy when a strategy generated order is returned from the broker's server in a "Rejected" state."
        http://ninjatrader.com/support/helpG...orhandling.htm

        If the order is not rejected, the script will not be stopped.

        With RealtimeErrorHandling set to RealtimeErrorHandling.TakeNoAction, you will be able to detect rejections in OnOrderUpdate when the IOrder.State == State.Rejected.


        Regarding disconnections and unknown states, once this happens you will need to manually disconnect and reconnect to repair the states of those orders.
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by adeelshahzad, Today, 03:54 AM
        4 responses
        24 views
        0 likes
        Last Post adeelshahzad  
        Started by merzo, 06-25-2023, 02:19 AM
        10 responses
        823 views
        1 like
        Last Post NinjaTrader_ChristopherJ  
        Started by frankthearm, Today, 09:08 AM
        5 responses
        16 views
        0 likes
        Last Post NinjaTrader_Clayton  
        Started by jeronymite, 04-12-2024, 04:26 PM
        3 responses
        43 views
        0 likes
        Last Post jeronymite  
        Started by yertle, Today, 08:38 AM
        5 responses
        16 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Working...
        X