Skip to main content

Ninjatrader has a database of files it maintains. These store every single trade, order update, charts and database cache, etc. As some users will have found, after a while, these can start to cause performance issues, especially if you do playback runs with automated sim trading, etc. NinjaTraders’ usual way to resolve this is – Delete everything and start again. Hmmm. This is a little drastic and I wanted something to simply remove the rubbish, keep the good data that I needed, and keep my platform in tip-top condition. So, I wrote this.

What this does

  • Removes orders, order updates, and executions older than X days from your database
  • Optimises the database to recover disk space and performance
  • Optionally removes the log and trace files
  • Optionally removes the database cache

Although I’d had to go through the ‘delete the database and start afresh’ approach once before due to performance issues (at the guidance of NT support), I certainly did not want to do this again! The first time I ran this, keeping 180 days of trade data, it removed over 250 thousand trade records and took around 10 minutes. Performance was noticeably better afterwards when NT was doing DB operations. All good 🙂 I now run this every week as part of preventative maintenance. I just have a batch file on my desktop with the command line in it and both clear flags set – regular maintenance is now a breeze. A typical run looks like this

All you need to do is extract the download to a folder and run the .exe per the above image from the command line. Instructions for usage will be shown, but it’s just a case of supplying the path to your Ninjatrader data folder along with the number of days of data you wish to keep, plus either or both of the 2 optional flags if you want.

It does back up your database prior to making any changes. You’ll find it in the DB folder with the date/time tagged on the end, so in the worst case, it should just be a matter to rename the backup and you are back in business. I’ve had no issues and it does work perfectly fine for me. Ninjatrader support might freak at the idea, but given their software lacks the features to do this, and because the performance issues this utility addresses are common, I’m happy.

Did this utility do its thing and clear hundreds or even gigabytes of data from your store? (the latter is not uncommon!). Let me know. Cheers.



Ninjatrader 8


This software is coffee ware. It is free to download and use, but, if you find it useful, please consider using the link in the app or the link on the right of this page to show the author you care and buy him a coffee. Just 1 coffee ( you can buy more if you want! ) – Or, consider it a beer! That’s not a lot for the time it saved you, is it? Without support, the author will neither maintain this product nor make new ones available publicly. Please be sure to check out some of my other Ninjatrader bits and pieces.  Remember, I’ve got to eat and keep the lights on too! Thanks for your support!


2023.02.12 fixed download link (again). Sorry!

Updated 2022.12.31 to support new DB type (SQLite) in the latest versions of Ninjatrader 8. Support for the old database is retained. If the util finds the old .sdf file, it will try and work with it. Please note that during a Ninjatrader upgrade, whilst your data is migrated to the new .sqlite db, the old database might still be in your db folder. It is suggested that once you have upgraded successfully, you remove (or backup and remove) that old .sdf file.


  • asraghu says:


  • Anand says:

    Paul, another great goodies from your side! Damn it why did i find your site before!

  • Ivan Maesepp says:

    Hi Paul,

    I downloaded this and extracted it to a folder. I then ran the NT8DBCleanup.exe and nothing happened. I then ran it as administrator and it asked me if I wanted to make changes and I said yes. I then saw something flash in the background and nothing else. I was expecting to be asked where the DB was and the number of days data I wanted to keep. Neither of these options were presented.

    Have I done the right thing or, what should I have done?

    • pjsmith says:

      Did you look at any of the screenshot examples above?

      • Felix says:

        Thank you for the tool ! I get an exception when i try to execute the exe :
        Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly ‘Microsoft.Data.Sqlite, Version=, Culture=neutral, PublicKeyToken=adb9793829ddae60’ or one of its dependencies. The system cannot find the file specified.
        at e.a()
        Seems like there is a file missing ? Thank you for the help .

        • pjsmith says:

          Hi – I have put all the DLL’s in a seperate download here – Extract those to the same folder. Hopfully that will resolve any dependancy issues.

        • pjsmith says:

          Apologies. A typo on my part. Fixed now

          • Felix says:

            Thank you for your effort,
            now it starts but throws an exception :

            Database path is C:\Users\Fx\Documents\NinjaTrader 8
            Remove transactions older than (days) 180
            This will remove all database orders/executions older than 18/04/2023
            You use this tool ENTIRELY AT YOUR OWN RISK
            Removing old data from the database may take a while, depending on the size of your data
            Are you sure you want to continue, and agree with the above?
            Y/N [ENTER]
            Could not find NinjaTrader.sdf at location C:\Users\Fx\Documents\NinjaTrader 8\db\NinjaTrader.sdf
            Backing up NinjaTrader.sqlite..
            Database copied to C:\Users\Fx\Documents\NinjaTrader 8\db\NinjaTrader.sqlite-20231015195728
            Data Source=C:\Users\Fx\Documents\NinjaTrader 8\db\NinjaTrader.sqlite;
            Setting up database connection..

            Hmmmm. Something went wrong. Some clues may be printed above,. Check your parameters, or pray to the code gods…
            The type initializer for ‘Microsoft.Data.Sqlite.SqliteConnection’ threw an exception.

            Any clue what could cause this ?
            Regards, Felix

  • Ivan Maesepp says:

    Hi Paul,

    I am not used to running command line stuff so, I apologise for my ignorance. I have tried several times to input the same as yours ( with the relevant changes according to my directories. I am obviously doing something wrong. I have extracted the zip folder to a directory as per this location: D:\Users\User\Documents\pjSmith

    Can you please detail exactly what I should be putting into the command line at the prompt mark. The current command line prompt is showing: C:\Users\User>

    What do Need to add after C:\Users\User>

    Thanks in advance.

  • Pierre says:

    Hi, I clicked on the download link and Google says there are no files available to download. Seems like the link is broken.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.