Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

starting Ninja with no Account active -- problem with objects not instantiated

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

    starting Ninja with no Account active -- problem with objects not instantiated

    Hello,


    When I start Ninja without a Connection, and try to access, for example

    ChartControl.OwnerChart.ChartTrader
    ​ChartControl.OwnerChart.ChartTrader.Account

    in OnStateChange (DataLoaded thru Terminated)

    I get an error

    Error on calling 'OnStateChange' method: Object reference not set to an instance of an object.

    these errors don't occur when I Connect at startup.



    Question: How do I test when there is no active connection so that I know when to bypass this type of code?

    Thx.

    #2
    Hello llanqui,

    Thanks for your post.

    <Account>.Connection could be used to see if a specific account is connected.

    <Account>.Connection help guide: https://ninjatrader.com/support/help...connection.htm

    Or, you could view the forum thread below that details information about using OnConnectionStatusUpdate() to detect a connection's status.

    https://forum.ninjatrader.com/forum/...-data-provider

    OnConnectionStatusUpdate(): https://ninjatrader.com/support/help...atusupdate.htm
    ConnectionStatusEventArg: https://ninjatrader.com/support/help...seventargs.htm
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #3
      Probably I would have to loop through all the Accounts to see if any were connected?

      Does that seem right?

      Comment


        #4
        there would be no connection event because there is no account being connected...when Ninja starts with no "connect on startup"....yes?

        Comment


          #5
          Hello llanqui,

          Thanks for your notes.

          Yes, that is correct. You would likely need to loop through the accounts to see if they are connected.

          OnConnectionStatusUpdate() is only called when there is a change in connection status as stated in the help guide linked in post # 2.
          <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

          Comment


            #6
            this is a side note....how can I remove old inactive accounts from the internal ninja account list?

            the whole account, data, etc

            Comment


              #7
              Hello llanqui,

              Thanks for your notes.

              You could try to get the accounts directly from the connection in your script which would get connected accounts instead of using Account.All of which gives disconnected accounts.

              Code:
              foreach (var connection in Connection.Connections)
              {
                  foreach (var account in connection.Accounts)
                  {
                  }
              }
              Otherwise, you could try resetting your database file by following the steps below.

              You can reset your database file by following the steps below.
              • Shutdown NinjaTrader and Go to the Start Menu
              • Select My Documents--> NinjaTrader 8--> db--> "NinjaTrader.sqlite" file (may only say 'NinjaTrader' depending on your Windows File Explorer settings)
              • Right-click on NinjaTrader.sqlite and select "Rename." *Name it "OLDNinjaTrader.sdf."
              • Then restart the software and NinjaTrader will create a fresh database file to use.
              • Unfortunately, the following items stored in the old database will be lost - ATM Strategy templates, Session templates, Instrument Lists / Custom Instruments, historical trade execution data, saved Strategy Analyzer backtest results
              To prevent running into situations where you can potentially lose important data, we advise running regular backups via our inbuilt backup feature in NinjaTrader.​

              Creating a backup: https://ninjatrader.com/support/help...up_archive.htm
              <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

              Comment


                #8
                Thanks Brandon,

                That reminds me of a request I'd like to make...and that is a way to port (and backup and restore) the settings in the database to a new machine

                cause I have two machines, one for development and one for trading

                Comment


                  #9
                  Hello llanqui,

                  Thanks for your notes.

                  I have submitted your feature request to the Development team. This request is being tracked under the number SFT-6012.

                  As with all feature requests, interest is tracked before implementation is considered, so we cannot offer an ETA or promise of fulfillment. If implemented, it will be noted on the Release Notes page of the Help Guide.

                  Release Notes — https://ninjatrader.com/support/help...ease_notes.htm
                  <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                  0 responses
                  577 views
                  0 likes
                  Last Post Geovanny Suaza  
                  Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                  0 responses
                  334 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by Mindset, 02-09-2026, 11:44 AM
                  0 responses
                  101 views
                  0 likes
                  Last Post Mindset
                  by Mindset
                   
                  Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                  0 responses
                  553 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by RFrosty, 01-28-2026, 06:49 PM
                  0 responses
                  551 views
                  1 like
                  Last Post RFrosty
                  by RFrosty
                   
                  Working...
                  X