Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Can you through programming check Order Connection Status?

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

    Can you through programming check Order Connection Status?

    Hi,

    I've managed to develop a strategy that is giving good results in backtesting, and I've been trying to forward trade it, and for the first time it's actually getting as good of results in live trading as it was in backtesting, which means I might really have an automated trading vehicle for the first time.

    However, a critical snag has come along due to the fact that MB Trading's forex order servers seem to disconnect on average about 4 times per day between 1am and 6:30am which is also the specific time of day that my strategy is doing the best for returns - IF it can keep running.

    What's happening is the MB Trading order server will disconnect for a minute at a time, and my strategy will try to either initiate a new position and get terminated (not so bad, just lose a chance for a gain is all)

    or it will try to close down a losing position (I must not use stop losses, but rather market orders and reverse direction) and this is very bad because the strategy will terminate with me in an open position and I've woken up to having my account 10% down from the night before because of this.

    Can someone please tell me if there's a way to simply have my strategy check if it is connected to the order server before trying to place an order? I've noticed in my log files that it will say "Disconnected from perm server" multiple times through the day, so Ninjatrader is aware of the disconnection -- so would using something like

    if(ConnectionStatus == ConnectionStatus.Disconnected)
    return;

    (then try to manage positions after a reconnection)

    Be starting in the right direction?

    Thank you for taking a look at this!

    Also, can anyone say whether Interactive Brokers has frequent disconnects like MB Trading does? I'm thinking of moving over to them if this keeps up because if I can't get a workaround for the connection - termination thing, I will have to either decide to stop trading it between midnight and 7am which is prime time for gainful trades, or changing brokers.

    Thanks!

    #2
    Hello RunnrX,

    For the Connection Status, you may check to see if the connection of the order server like in our Help Guide at the following link.



    With that said, could you let me know if the exact messages you get when your strategy is being disabled so that I may help you further?

    As for the Brokerage Providers, I believe using MBT there is only two different points where you would lose connection to their servers, and using the supported version of TWS (IB) there is a daily reset required as well.

    Happy to be of further assistance.
    JCNinjaTrader Customer Service

    Comment


      #3
      Thank you NinjaTrader_JC, that looks like exactly what I needed

      I can't remember the exact wording of the error messages but it was the same thing as what you'd get if you were to try to send an order at the 5pm rollover, it was something like "strategy terminated - order rejected for reason: no connection to order server" or something to that effect.

      I was actually getting that same error message at 6:30am, 1am, etc. I've found in the Log files that there were actually several points overnight at which the order connection went down from between one second to up to one minute at a time, and so this help file you sent me will be what I need to code a workaround - thank you!

      Comment


        #4
        Hello RunnrX,

        In doing a bit of research it looks like MBT server resets for MBT should only occur at 5:00PM Eastern and 12:00PM Eastern.

        Other disconnects, could be from a different result like ISP or something unexpected on the server side of things.
        JCNinjaTrader Customer Service

        Comment


          #5
          had similar issues with IB, where the server restart is once a day. The solution is to change the connection loss handling settings to a few minutes. The default settings are way to tight. Managed to get a strategy running for 2 weeks straight without a single restart.
          see post #8 in http://www.ninjatrader.com/support/f...ad.php?t=53136

          Marco

          Comment


            #6
            I just want to be alerted if my strategy stops running for any reason - what is the code to insert and where - thx

            Comment


              #7
              Hello hifreq,

              If your strategy is getting Disabled, you may want to use the "OnTermination()" method to either send an Alert or Email when this happens so that you can get notified of this when your strategy becomes disabled.



              Let me know if you have any questions.
              JCNinjaTrader Customer Service

              Comment


                #8
                thx, i had seen that what i wanted to know is that the only code i need to insert "OnTermination()" and it automatically send me an e-mail? I am not really a program guy

                Comment


                  #9
                  Hello hifreq,

                  You can use this an an example:

                  Code:
                  protected override void OnTermination()
                  		{
                  			SendMail("[email protected]","[email protected]", "Testing", "Disabled");
                  		}
                  Changing the "From" and "To" email address to the your own.
                  JCNinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Aviram Y, Today, 05:29 AM
                  1 response
                  6 views
                  0 likes
                  Last Post NinjaTrader_ChelseaB  
                  Started by cls71, Today, 04:45 AM
                  1 response
                  7 views
                  0 likes
                  Last Post NinjaTrader_ChelseaB  
                  Started by TradeForge, Today, 02:09 AM
                  1 response
                  22 views
                  0 likes
                  Last Post NinjaTrader_ChelseaB  
                  Started by elirion, Today, 01:36 AM
                  2 responses
                  14 views
                  0 likes
                  Last Post elirion
                  by elirion
                   
                  Started by DJ888, 04-16-2024, 06:09 PM
                  5 responses
                  14 views
                  0 likes
                  Last Post NinjaTrader_Erick  
                  Working...
                  X