NinjaTrader

Running NinjaScript on NinjaTrader 8

From HorizonAI to a compiled indicator or strategy

HorizonAI writes and converts NinjaScript — the C#-based language that powers NinjaTrader 8. This page explains what NinjaScript is, what HorizonAI does for you inside the app, and the short loop you follow to get your code running on your own charts in NinjaTrader.

What is NinjaScript?

NinjaScript is the programming language of NinjaTrader 8, a popular desktop platform for futures and forex traders. It's built on C#, and it comes in two flavours:

  • Indicators — draw studies on your chart (moving averages, RSI, custom signals).
  • Strategies — place and manage trades automatically, and can be backtested.

You write NinjaScript in the NinjaScript Editor inside NinjaTrader, compile it, and it runs natively on the platform.

What HorizonAI does with NinjaScript

You can both generate NinjaScript from scratch and convert existing code into it:

  • Create: on the New Script page, set the language toggle to NinjaScript, describe your idea, and the AI writes it.
  • Convert: on the Converter, NinjaScript (labelled NinjaTrader 8) is part of the full any-to-any matrix — turn Pine Script or MQL5 into NinjaScript, or go the other way. Uploads accept .cs files.
  • Get your code out: click Copy Code in the chat header to copy the whole script to your clipboard.

NinjaScript is copy-to-clipboard only — there's no download button for it (that's MQL5-specific, for the .mq5 file). You'll paste the copied code straight into the NinjaScript Editor, so a download isn't needed.

What happens in the app vs. in NinjaTrader

For NinjaScript, HorizonAI is where you write, refine, and convert the code. Everything after that — compiling, adding it to a chart, and backtesting — happens inside NinjaTrader 8, which is free to install.

The in-app Visual Flow, live Chart preview, and Backtest tab are currently available for Pine Script and MQL5 only — not NinjaScript. For a NinjaScript thread, those tabs show greyed out. To visualize or backtest a NinjaScript strategy, take it into NinjaTrader (see Backtesting in NinjaTrader below).

So the NinjaScript loop is short:

  1. Generate or convert your script in HorizonAI.
  2. Click Copy Code.
  3. Paste it into the NinjaScript Editor in NinjaTrader 8 and compile.
  4. Add the indicator to a chart, or run the strategy in the Strategy Analyzer.

Indicator or strategy?

The AI produces whichever you ask for. If you describe a study that draws on the chart, you'll get an indicator (a class deriving from Indicator). If you describe something that enters and exits trades, you'll get a strategy (a class deriving from Strategy). NinjaTrader reads that base class when you compile and files the result in the right place automatically — you don't have to tell it which is which.

Not sure which you want? Just say so in the prompt — e.g. "make this a strategy that actually places trades" vs. "make this an indicator that only plots signals." See How to Talk to Horizon AI for more.

Next steps

Follow these three guides in order to go from copied code to a running script:

Related Guides