🍂 Autumn Savings 🍂 Autumn Savings 20% OFF Sitewide – Up to 50% OFF Select Products View Promotions Ends in Wednesday, November 11 🏆 Compare Trade Copiers →
Support

How to Resolve NinjaScript Errors

By Affordable Indicators· December 12, 2024·7 min read
How to Resolve NinjaScript Errors

NinjaTrader compiles every NinjaScript file on your PC together, so a single file with a programming error blocks all of them. Until it is fixed, NinjaTrader will not import, update or remove add-ons, and you cannot create or edit strategies. This guide shows how to find the file causing it and how to clear the most common errors.

You will usually see one of these messages:

  • “Import failed. This NinjaScript Archive File may contain duplicate method names that already exist on your PC, modify a method signature that other scripts were dependent on, or be missing a required file on either your PC or in the import archive.”
  • “You have custom NinjaScript files on your PC that have programming errors. These errors must be resolved before you can import a NinjaScript Archive File.”
  • “Remove failed. You have custom NinjaScript files on your PC that have programming errors. These errors must be resolved before removing a NinjaScript assembly.”
  • “NinjaTrader must be in a compilable state to create or edit Strategies. Please use the NinjaScript editor to resolve compilation errors.”
  • “Unhandled exception: Could not find a part of the path ‘X/NinjaTrader 8/tmp/Import/Backup.”

Errors While Importing or Updating an Indicator

If an import fails, please don’t unzip the download or copy the .cs and .dll files into NinjaTrader by hand. Work through these in order:

  1. Run Fix & Optimize (formerly the NinjaTrader Repair Tool). It comes with every one of our products and their free trials, in Members Area > Fix NinjaScript Errors. It fixes the usual causes of these errors: copied files, a missing import folder, broken references and OneDrive.
  2. Import the zip again, exactly as you downloaded it: Control Center > Tools > Import > NinjaScript Add-On.
  3. Still missing from New, or “An item with the same key has already been added”? Remove it and import it fresh:
    • Back up Documents > NinjaTrader 8 > bin > Custom (copy the whole folder somewhere safe).
    • Download a fresh copy from NinjaScript Downloads.
    • In NinjaTrader go to Control Center > Tools > Remove NinjaScript Assembly, remove ours, and restart NinjaTrader.
    • Import the fresh zip, click Yes when it asks to authorize, and restart NinjaTrader again.
  4. Check that it worked: open a chart, right-click it, choose Indicators and look for the indicator in the list. The Accounts Dashboard opens from Control Center > New > Affordable Indicators.

Microsoft OneDrive is the most common cause of NinjaScript errors. If your NinjaTrader 8 folder sits in a location OneDrive manages, start with our guide:

Resolving NinjaTrader Desktop Issues With Microsoft OneDrive

NinjaTrader compiles all of your indicators and strategies in one pass instead of one at a time, which is why one broken file holds up the rest. The usual causes are an add-on whose reference to a .dll file is missing, a reference that still points at an old file location, or two copies of the same file that define the same thing twice.

Find the Compile Error That Is Blocking NinjaTrader

If you already know the error code, skip to it below. If not, find it like this:

  1. In the NinjaTrader Control Center, open New > NinjaScript Editor. It can take a few seconds to appear.
  2. Right-click anywhere in the editor and choose Compile (or press F5).
  3. Watch the bottom-left corner: a loading icon shows while it compiles. If it finishes with a chime and no errors are listed, your NinjaScript compiles cleanly and your add-ons work normally.
  4. Otherwise the errors are listed in orange at the bottom of the editor. Each one names the file, the error code and a description. These must be fixed, or the file excluded (see below), before you can import or remove add-ons, and some add-ons will not work correctly until then.

An error line names the file, the code and the problem, for example:

ExampleAssembly.cs CS0006 Metadata file 'ExampleAssembly.dll' could not be found

Common Compile Errors and How to Fix Them

Start with the errors below. Clearing them often clears the rest of the list too.

CS0006 – “Metadata file ‘example.dll’ could not be found”

What it means: an add-on refers to a .dll file that NinjaTrader cannot find on your PC.

How to fix it:

  1. Right-click inside the NinjaScript Editor and choose References.
  2. Select the reference to the .dll named in the error.
  3. Click Remove.
  4. Click OK and compile again.

NinjaTrader’s video walks through it: Metadata File Not Found

CS0246 – “The type or namespace name ‘exampleassembly’ could not be found (are you missing a using directive or an assembly reference?)”

What it means: NinjaTrader is looking for a reference to a .dll file that it cannot locate.

How to fix it:

  1. Right-click inside the NinjaScript Editor and choose References.
  2. Click Add.
  3. Browse to the .dll for the file named in the error and click Open.
  4. Click OK and compile again.

This also clears the CS0118 error that often appears just below CS0246. NinjaTrader’s video: Missing Assembly or Reference

CS0234 – “The type or namespace name ‘exampleindicator’ does not exist in the namespace ‘examplelocation’ (are you missing an assembly reference?)”

What it means: one of NinjaTrader’s own built-in indicators is missing from Documents > NinjaTrader 8 > bin > Custom > Indicators, or a file there is corrupt.

How to fix it:

  1. Close NinjaTrader.
  2. Open the Windows Control Panel from the Start menu. The Windows Settings app does not have this option.
  3. Go to Programs > Programs and Features.
  4. Select NinjaTrader in the list and click Repair. This replaces missing or damaged NinjaTrader files without changing your settings.
  5. Restart NinjaTrader and compile again.

NinjaTrader’s video: Resolving the Indicator is Missing or Corrupted Message

CS0101 – “The namespace ‘NinjaTrader.NinjaScript.Indicators’ already contains a definition for ‘example'”

What it means: two files on your PC define the same thing. Usually the same add-on is there twice: an old copy next to a new one, files copied in by hand, or a duplicate made by OneDrive.

How to fix it:

  1. In the NinjaScript Editor, expand the folder named in the error (for example, Indicators) and look for two files with the same or a very similar name, such as one ending in “- Copy” or with your computer’s name added.
  2. Exclude or remove the extra copy (see below), then compile again.
  3. Never remove a file whose name starts with @. Those are NinjaTrader’s own files.

If the duplicate is one of our add-ons, run Fix & Optimize and import the zip again, as described at the top of this guide.

“Unable to recover NinjaTrader custom assembly”

What it means: NinjaTrader builds one file, NinjaTrader.Custom.dll, from all of your NinjaScript. This message shows when NinjaTrader starts and cannot load that file, often after NinjaTrader did not close cleanly or after an update.

How to fix it:

  1. Close NinjaTrader. Open Windows Task Manager and check that no NinjaTrader process is still running; end it if one is.
  2. Start NinjaTrader again. If the message is gone, compile in the NinjaScript Editor to check that everything compiles.
  3. If it comes back, run Fix & Optimize.
  4. Still there? Close NinjaTrader, back up Documents > NinjaTrader 8 > bin > Custom, then delete NinjaTrader.Custom.dll from that folder. Start NinjaTrader and compile in the NinjaScript Editor, which builds a fresh copy.

Exclude the File With the Error From Compilation

If an error points at an add-on you do not need right now, you can leave its file out of the compile instead of fixing it, so the rest of your NinjaScript compiles and imports work again:

  1. Compile in the NinjaScript Editor and note the file named in the orange error at the bottom of the window.
  2. On the right side of the NinjaScript Editor, double-click the folder for that object type (for example, Indicators) to expand it.
  3. Left-click the file to select it, then right-click it.
  4. Select Exclude From Compilation, then compile again. From the same menu, Open lets you debug the file instead, and Remove deletes it.

An excluded add-on is not available in NinjaTrader until you include it in compilation again.

Resolving Uncommon Compile Errors

For any other error code, NinjaTrader’s Desktop Help Guide lists every documented compile error and its fix: Compile Error Codes

If the code is not listed there, contact the developer of the add-on named in the orange error. If the error is in a NinjaScript you wrote yourself and it is not documented, contact NinjaTrader support, who can pass it to their NinjaScript Engineering team.

If the error names one of our add-ons, contact our support team and we will help you clear it.

Trade with the right tools. Our NinjaTrader trade copier mirrors your trades across every prop-firm account, and our chart trader tools put one-click order management on your chart — lifetime licenses, free updates, live chat support.
See the trade copier →
Buy with Confidence · 🛡️ 8,000+ customers · ⭐ 4.8 Trustpilot · 🏆 18 years programming experience