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

Internet connection loss and BuyToCover problem

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

    Internet connection loss and BuyToCover problem

    The problem that occurs with my strategy seems to possibly be triggered by loss of internet connection when the internet cuts out for a short period of time.


    Order can't be submitted.. account is not connected.. affected Order: BuyToCover

    Can someone explain what is going on and how I can configure my strategy to not "BuyToCover" ?

    I believe this causes the problems I have in https://ninjatrader.com/support/foru...-per-direction
    Last edited by NinjaCustomer; 04-18-2019, 04:55 AM.

    #2
    Hello NinjaCustomer,

    The term BuyToCover is used in regard to the type of order being used in contrast to the position, seeing this is normal and not something you can change the wording of. Buy to cover generally means to close a short position, this is likely one of the exits or targets causing this message. This terminology is seen in the orders grid, errors, also if you use the unmanaged or addon order submission methods these begin to be used:
    Code:
    OrderAction.Buy
    OrderAction.BuyToCover
    OrderAction.Sell
    OrderAction.SellShort

    I reviewed the other post but I am not certain that would be related to this situation, this seems to be specifically related to the account not being connected at this point in time and not the EntriesPerDirection as you are discussing in the other post.


    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      It is not the wording that confuses me, rather why covering is being triggered. Can you think of anything that might cause this, given what I said about the internet connection cutting out? And how I could avoid this. I realize this is an error message but something is still happening, so maybe the error message occurs but then it tries again and succeeds?

      you know I think I didn't explain it well in the other thread.

      Although I have a hard limit of "EntriesPerDirection", I realize now that my code doesn't keep repeatedly calling EnterLong() or EnterShort()

      Instead it checks and compares to the current # of OpenTrades, which I have calculated from Position.Quantity as recommended in another thread before when I asked how to get the current # of entries and was told it is not directly possible.

      I do this because I must execute other code that happens if we will make a new entry but that I don't want executed if the entry is not going to be made.

      So somehow when this happens I assume the volume is getting changed - although I'm not totally sure what is going on because this kind of thing is hard to test, have to wait until it happens.

      But I've noticed the last 2 times that it has this dialog I described in my first post.

      i.e. the volume is at the EntriesPerDirection for some time because no more entries are being made, having reached the limit of "OpenTrades" (calculated from quantity)

      1. Then I hear a connection lost wav being played.
      2. Then I see the dialog pop up
      3. Then I see that my Strategy has now entered another entry in the direction of the Strategy, so i mean the quantity volume displayed on the chart trader has increased from a new entry





      Comment


        #4
        Hello NinjaCustomer,

        Without more context on what code was used at this time, I couldn't really say what may be happening here other than there is an error surrounding one of the orders being used. The error is specific in what occurred, we know that a disconnect happened and the account was not connected when this error was reported. However, without knowing what you are doing, I can only give the definition of the order in the error so that you can review where that may be happening in your logic.

        The mentioned order definition is to close a short position, so this is likely an exit order or target which triggered the error. We may be able to review the log file to see the orders and what happened prior to receiving the error if you would like to send the files to our standard platform support [at] ninjatrader.com address. Otherwise seeing what syntax that was used in this case may help hint at what occurred. Do you have a specific sample of what syntax was used when this error came up?

        And how I could avoid this. I realize this is an error message but something is still happening, so maybe the error message occurs but then it tries again and succeeds?
        Generally, order errors should stop the strategy, is this what you had seen occur when you received this message? The platform has specific settings in the options menu which you can configure for handling disconnects. Depending on what happened in this case and what settings you have chosen will delegate what the strategy does.

        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          hmm just happened again... yeah.. connection lost then bam , error dialog but also... executions tab has a BUY (because my position was short)

          just text like I wrote in the initial post in the dialog, no error code.

          ok, just found something in the output

          Strategy '▼ Sell/150123793' lost price connection for more than 10 seconds and will be restarted.

          Restarting explains why my logic gets reset. Is there a way to avoid this?

          I found some enum but it doesn't say anything about restarting

          https://ninjatrader.com/support/help...sshandling.htm

          apparently it is running Recalculate mode
          Last edited by NinjaCustomer; 04-18-2019, 11:01 AM.

          Comment


            #6
            Hello NinjaCustomer,

            If you wanted the strategy to keep running instead of restarting and recalculating, you would need to select ConnectionLossHandling.KeepRunning. This will leave the strategy alone as the connection is resumed. You can also look at the other connection handling settings if this is common for you to try and mitigate that better. Generally, if the connection becomes an ongoing problem the suggestion is to either try to address the connection being used or to use a private server to run NinjaTrader which has a dedicated connection.

            I look forward to being of further assistance.
            JesseNinjaTrader Customer Service

            Comment


              #7
              my strategies are semi-automatic so I can't put them on a remote server, eventually I will program some buttons for them and put them on the chart.

              Can I just ignore DisconnectDelaySeconds if KeepRunning is being used ?

              Comment


                #8
                Hello NinjaCustomer,

                No, the disconnect settings still apply and if the max restart attempts are exceeded, that will still stop the strategy even when using KeepRunning. If you have a poor connection which exceeds the max restart attempts and other connection settings which are set the platform will try to stop strategies as they may no longer have enough information to correctly work. If you are certain that the strategy will work under that use case you can increase the values here as needed to prevent this from happening.

                I look forward to being of further assistance.
                JesseNinjaTrader Customer Service

                Comment


                  #9
                  what are the max values for DisconnectDelaySeconds and NumberRestartAttempts ? I set them very high (9999999) but I'm wondering if I set them too high since I'm having some positions mysteriously close after connection loss even though I'm also on KeepRunning...

                  also, would there be some message printed if disconnnect is due to DisconnectDelaySeconds or NumberRestartAttempts?

                  I did not change RestartsWithinMinutes from the default.

                  Strategy appears to stay running though when this happens.

                  For the purposes of these questions, please ignore the previous descriptions I made since my strategy has been edited a lot since then.
                  Last edited by NinjaCustomer; 05-01-2019, 10:58 AM.

                  Comment


                    #10
                    Hello NinjaCustomer,

                    There are no documented maximums here, so I would not be certain if that is related to this situation.

                    You will see a notification that the strategy is being disabled in case you run into the rules surrounding max restart attempts, this will still disable the script even when using Keep Running. It does not sound like this happened based on the details provided.

                    What did you specifically see happen in regard to the position closing? Was this after you reconnected that the position was closed? Can you give more specific details on the situation surrounding the position? Also is this a live position or a sim position?

                    I look forward to being of further assistance.
                    JesseNinjaTrader Customer Service

                    Comment


                      #11
                      unfortunately these problems occur rarely - yes the position closed after reconnecting.. sim position as this strategy is still in development - I will keep my eye on output1 again next time this happens, but there is no logic in my strategy to actually close a position (other than stoploss setting which is disabled) but this happens immediately after reconnection - but it is hard to track down because still my strategy (due to my loss handling settings) generally weather a reconnection well.

                      I reduced by a few 9s now, hopefully that helps but I was just trying to guess what could be causing it from looking at my code.

                      I guess there's a chance I hit a file save (causing a recompile) that would trigger disabling of strategies and flattening positions around the same time that I also had connection loss/reconnect. I can't remember now, but I'm just saying this because I'm trying to come up with explanations.

                      I will put a termination message in onstatuschange - therefore next time it happens it would be clear if it is from connection loss or accidental disabling of strategy, since i will see a termination message and the absence of any connection status message above it would mean that it was not terminated by connection loss.

                      Comment


                        #12
                        Hello NinjaCustomer,

                        Yes the next time this happens, please email in when it does so that we can review the log and trace files for this time to observe the progress of the orders. Keep track of the time this happens in addition to the order information which opened the position so we can locate it. In the interm, you can try unplugging your LAN cable to simulate a disconnect while testing, however, this may or may not recreate the same problem.

                        I guess there's a chance I hit a file save (causing a recompile) that would trigger disabling of strategies and flattening positions around the same time that I also had connection loss/reconnect. I can't remember now, but I'm just saying this because I'm trying to come up with explanations.
                        This should not happen, or the strategies should not disable/reload when compiling. The only type which automatically reloads would be an Addon, for the most part everything else will require that you to refresh the chart/script/tool to see changes.

                        The test with Termination will be good as well, any additional debugging you can add to this script to address the situation would be helpful.

                        I look forward to being of further assistance.
                        JesseNinjaTrader Customer Service

                        Comment


                          #13
                          ah I see, I was used to my addon reloading so that's why I was thinking that way. I was just about to move my entire Custom folder for use for editing and copy all the modified files in when i wanted to view the changes, but if it is just addons then i could just work on a copy of the addon file - i mean the goal is to not trigger reloading every time I save.

                          So you're saying market analyzer columns, indicators, strategies - these are the other types of things I write in NS - their running instances should never be replaced affected by a file save, correct?

                          Is there a way to disable reloading of some (or all addons) via xml config?
                          Last edited by NinjaCustomer; 05-03-2019, 10:40 PM.

                          Comment


                            #14
                            Hello NinjaCustomer,

                            There is no way to disable the auto-reloading of certain types, this is part of how NinjaScript works. There is also not a specific list of items which reload automatically, you could address this question by adding a Print into the type in question's OnStateChange method. Add-ons will be reloaded after a compile due to the nature of the type, most other types will require directly reloading the instance.

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

                            JesseNinjaTrader Customer Service

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by Waxavi, Today, 02:10 AM
                            0 responses
                            3 views
                            0 likes
                            Last Post Waxavi
                            by Waxavi
                             
                            Started by TradeForge, Today, 02:09 AM
                            0 responses
                            8 views
                            0 likes
                            Last Post TradeForge  
                            Started by Waxavi, Today, 02:00 AM
                            0 responses
                            2 views
                            0 likes
                            Last Post Waxavi
                            by Waxavi
                             
                            Started by elirion, Today, 01:36 AM
                            0 responses
                            4 views
                            0 likes
                            Last Post elirion
                            by elirion
                             
                            Started by gentlebenthebear, Today, 01:30 AM
                            0 responses
                            4 views
                            0 likes
                            Last Post gentlebenthebear  
                            Working...
                            X