Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Lost connection dangers

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

    Lost connection dangers

    Hi,
    I seem to have boxed myself into a corner here. I added some code to my strat that says whenever the connection is lost, send an email so I know about it. I can then call my broker and get out.

    That works fine in most instances when the connection is lost because the feed from my broker (NT) went down. If the connection from my server is lost, I obviously can't send myself an email.

    It goes to a deeper problem. If my strat runs 24x7 I'm not up at 3 am monitoring it. If the connection is lost in the middle of the night I can end up with an open order/trade and potentially without a stop or target. This is a dangerous situation that I want to avoid. Just today I saw it happen and had to go in and flatten everything.

    One thing I thought of is having a strat that does nothing but monitor itself for a re-connection. When it connects, flatten everything (assuming there was an orphan). This may or may not do much to ameliorate the issue (if the reconnection come's on 5 hours later I could have lost my butt!).

    Is there a best practice (from a coding point of view) to deal with "orphan" trades? If there is a trade and no associated stop and target, then as far a I'm concerned, call the fire department!!! The problem is how to know at 3am or if I'm out running an errand. Is there a code solution (I can't see one)?

    I'm sure this is not a new issue. But I would love to hear other people's ideas on this subject. Otherwise, I am going to have to scale back my strat to on run when I am sitting there to monitor it. I can't tell you how much fun that sounds like!

    Thanks ... Ed

    #2
    Hi, Ed
    I have been there. and definitly I strong recomend you to set, an extra profit/stopLoss.
    when the connection lost, badly, and you are occupied (sleeping) there is nothing you could do.
    For example, I do this:
    1. Add a security profit/Stop that change, time to time ( automatically, depending your own criteria)
    2. the Strategy Sends screenshots to your email eachtime makes an "important change" ... for your own relief.

    Comment


      #3
      Hello Ed,

      The official response is that you should never walk away from active position or a working order.

      That said, one suggestion if you are experiencing many disconnections would be to use a VPS (virtual private server) that would be less likely to experience a disconnection. (Less likely, not impossible)

      When it comes down to it, if the computer has lost internet and could be down for the foreseeable future, an email would not be able to be sent from that computer to let you know this.
      Instead, an idea would be to use second computer in a different location on a different internet source that the main computer would send a message to every so often. If the second computer doesn't get its message, it would then trigger an email to be sent.

      This would be far outside of what is supported by NinjaTrader and is just an idea for you to think about.
      Chelsea B.NinjaTrader Customer Service

      Comment


        #4
        I think we need to have a discussion on this subject. I understand that we have to keep watching the trade and all of that. but bad things happen and we need to have a plan of action both mechanically and manually.
        Some scenarios are:
        1. I know that IB reboots between 11.45 to 12.45 midnight. Action=dont run my strategy during that period.
        2. ping pushmon every 15 minutes so I get notified when NT goes down.
        3. I have a entry order, and I lose my connection. what should I do to monitor so I can resubmit my order
        4. I have a exit order, and I lose my connection. what should I do to monitor so I can resubmit my order


        we could keep growing the list and as traders become aware of the pitfalls and come up with trading and programming decisions to mitigate the risk.
        Last edited by junkone; 06-01-2016, 01:58 PM.

        Comment


          #5
          If you lose your entire connection, kind of hard to get notified.
          You could get a router that supports rollover if main connection goes down and fall back to a 4g connection. Not sure how NT would respond in that situation. (I don't have this set up).

          Cradlepoint is one such company that sells these type of routers.

          Comment


            #6
            I have a main internet using cable and cheap backup internet using dsl. I use a tplink dual wan router(100$) which does automatic failover. its pretty simple. or worst case start the phone on a hotspot and you have a quick manual standby internet

            Comment


              #7
              Hello junkone,

              To answer your questions 3 and 4:

              If IB 24 hour forced logout causes NinjaTrader to become disconnected, this would not be an internet outtage and you would still be able to send emails.
              So in this situation you could still send an email to let you know that NinjaTrader was disconnected.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                my questions on based on how to continue the strategy and maintain the order issue after IB gets reconnected. what would be design pattern to use to hold the orders when the connection is lost and regained and reissue them

                Comment


                  #9
                  Hello junkone,

                  This seems to be a little off subject with this thread about sending emails.

                  To answer your question, if the strategy is disabled, it will re-calculate historical data and orders when restarting and will re-calculate the position.
                  If you want the position and orders to be the same, then the script needs to recalculate the same. Intra-bar granularity of 1 tick, is the best way to have a strategy calculate the same historically as it does in real time.

                  Below is my response for resuming a strategy.

                  NinjaTrader can try and resume your strategies when you restart them.
                  To do this, you will need to enable the following option before starting a new instance of a strategy:
                  • Click Tools -> Options... -> select the Strategies tab -> select the NinjaScript sub-tab
                  • Select the radio button option Immediately submit live working historical orders -> Click OK
                  • When starting a new instance of the strategy set the Sync account position parameter to True
                  • After running your strategy, be sure to save your workspace when you shutdown NinjaTrader


                  Below is a link to the help guide on Syncing Account Positions. Please see the section 'Immediately submit live working historical orders, Sync account position = true'


                  With these options the following will happen when the strategy resumes. (From the help guide
                  • Any active orders on the account previously generated by the strategy that does not match* an active strategy order will be cancelled. Should the strategy be unable to cancel and receive confirmation on the cancellation of these orders within 40 seconds the strategy will not start and an alert will be issued.

                    *A previously generated order is considered to match an active strategy order when the order action, order type, quantity, limit price, and stop price are exactly identical.
                  • The matching active orders on the account will then be mapped to the active strategy orders
                  • Any remaining active strategy orders that cannot be successfully paired will be submitted live and the strategy will then try to sync your Account Position to your Strategy Position through the process below.


                  As mentioned in the help guide, if the historical orders do not match realtime orders made previously they are cancelled. If you want to ensure that your strategy resumes the previously placed orders with the 'Immediately submit live working historical orders, Sync account position = true' setup, you will need to ensure that the historical trades match the real time trades.

                  Adding intra-bar granularity can help with this.

                  Below is a link to the help guide on Syncing Account Positions.


                  When in historical data, only the Open, High, Low, an Close will be available and there will be no intra-bar data. Intra-bar granularity adds a second data series such as a 1 tick series so that the strategy has finer granularity in the historical data in between the OHLC of the primary series. This allows for more accurate trades.

                  Below is a link to an official reference sample that demonstrates how to add intra-bar granularity.
                  You can submit orders to different Bars objects. This allows you the flexibility of submitting orders to different timeframes. Like in live trading, taking entry conditions from a 5min chart means executing your order as soon as possible instead of waiting until the next 5min bar starts building. You can achieve this by


                  Also, here is a link to the differences on real-time vs backtest (historical).


                  As well as a link to the help guide on the Add() method.


                  A link to the help guide on BarsInProgress.


                  And a link to the help guide on Multi-Time Frame & Instruments. Please see the section 'How Bar Data is Referenced', and 'Accessing the Price Data in a Multi-Bars NinjaScript'.
                  Last edited by NinjaTrader_ChelseaB; 06-01-2016, 02:46 PM.
                  Chelsea B.NinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Stanfillirenfro, Today, 07:23 AM
                  1 response
                  3 views
                  0 likes
                  Last Post NinjaTrader_Gaby  
                  Started by cmtjoancolmenero, Yesterday, 03:58 PM
                  2 responses
                  20 views
                  0 likes
                  Last Post cmtjoancolmenero  
                  Started by olisav57, Yesterday, 07:39 PM
                  1 response
                  9 views
                  0 likes
                  Last Post NinjaTrader_ChelseaB  
                  Started by cocoescala, 10-12-2018, 11:02 PM
                  7 responses
                  944 views
                  0 likes
                  Last Post Jquiroz1975  
                  Started by oviejo, Today, 12:28 AM
                  1 response
                  12 views
                  0 likes
                  Last Post NinjaTrader_Gaby  
                  Working...
                  X