• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

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 chartish, Today, 04:43 PM
        0 responses
        7 views
        0 likes
        Last Post chartish  
        Started by Trader17, Today, 04:07 PM
        0 responses
        4 views
        0 likes
        Last Post Trader17  
        Started by GussJ, Today, 01:30 PM
        2 responses
        19 views
        0 likes
        Last Post GussJ
        by GussJ
         
        Started by GARZONJ, Today, 12:25 PM
        3 responses
        17 views
        0 likes
        Last Post NinjaTrader_PaulH  
        Started by RandanAL, Today, 11:53 AM
        1 response
        13 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Working...
        X