Using the NinjaScript Editor
The NinjaScript Editor is where NinjaTrader 8 turns your code into a working indicator or strategy. This guide shows how to open it, paste the code you copied from HorizonAI, compile it, deal with common errors, and add the result to a chart.
1) Open the NinjaScript Editor
From the Control Center, go to New → NinjaScript Editor (you can also reach it from Tools → NinjaScript Editor). The editor opens in its own window.
2) Create a new indicator or strategy
Your generated code already contains a full class. Create a matching file for it:
- In the NinjaScript Editor, click New and choose Indicator or Strategy — pick whichever matches your code. (HorizonAI-generated indicators derive from
Indicator; strategies derive fromStrategyand useEnterLong()/EnterShort()calls.) - The NinjaScript Wizard asks for a name. Name it to match the class name in your generated code — e.g. if the code says
public class EmaCross : Strategy, name itEmaCross. - Finish the wizard. NinjaTrader creates a template file with some starter code.
3) Paste your HorizonAI code
Select all of the template code the wizard generated (Ctrl+A) and replace it by pasting your copied HorizonAI code (Ctrl+V). You want the pasted code to be the entire contents of the file — including its using statements and namespace — not appended to the template.
4) Compile
Compile the code in any of these ways:
- Press F5, or
- Click the Compile button on the editor toolbar, or
- Right-click in the editor and choose Compile.
On success, NinjaTrader converts your code into a native C# assembly and your script is ready to use. If anything is wrong, compile errors appear at the bottom of the editor with the file and line number.
Where your compiled script lands
NinjaTrader files your script by its base class automatically:
- Indicators (deriving from
Indicator, namespaceNinjaTrader.NinjaScript.Indicators) appear in the chart's Indicators list. - Strategies (deriving from
Strategy, namespaceNinjaTrader.NinjaScript.Strategies) appear in the chart's Strategies list and in the Strategy Analyzer.
Add an indicator to a chart
- Open the chart you want to use.
- Right-click the chart and choose Indicators (or press Ctrl+I).
- Find your indicator by name in the Available list, select it, and click Add.
- Adjust any inputs on the right, then click OK. It plots on the chart in real time.
Apply a strategy
To run a strategy live-in-simulation, right-click a chart and choose Strategies, add yours, set its account to your simulation account, and enable it. To test it on historical data instead, use the Strategy Analyzer — see Backtesting in NinjaTrader.
Fixing common compile errors
If the compile fails, read the message at the bottom of the editor — it names the line. A few things that trip up pasted code:
- File name ≠ class name. The
.csfile must be named exactly like thepublic classin the code. - Duplicate name. If a script with that name already exists, rename your new one (and its class) to something unique.
- Missing
usingor namespace. Make sure you pasted the whole script, including theusingblock andnamespaceat the top — don't paste just the class body over the template. - Indicator vs. strategy mismatch. Trading calls like
EnterLong()only exist on aStrategy. If you created an Indicator file but the code is a strategy, recreate it as a Strategy (or ask HorizonAI to regenerate it as the type you want).
Next steps
- Backtesting in NinjaTrader — Test your strategy in the Strategy Analyzer
- Running NinjaScript on NinjaTrader 8 — The full HorizonAI → NinjaTrader overview
Related Guides
- Setting up NinjaTrader 8 — Install the platform first
- Getting Started with HorizonAI — Generate NinjaScript with AI
- How to Prompt — Get cleaner, compile-ready code