Code migration guide

cTrader to NinjaTrader converter

Both platforms use C#, but a cTrader cBot is not a NinjaScript Strategy: namespaces, base classes, lifecycle states, series containers, volume conventions, and order management all need platform-native rewrites.

Generate a NinjaScript draft, then compile it in NinjaScript Editor and test it in NinjaTrader 8.

Conversion map

What changes between cTrader and NinjaTrader 8

The migration is a model translation. Use this map to decide where the source behavior belongs before writing target syntax.

Source and target platform conversion map
ConcernSource modelTarget modelMigration decision
LifecycleRobots use lifecycle methods including OnStart, OnTick, OnBar, OnStop, and OnException; indicators calculate by index.OnStateChange configures lifecycle states and OnBarUpdate handles bar-driven calculations at the selected Calculate frequency.Choose when each cTrader calculation should run in NinjaTrader 8; matching syntax alone does not preserve timing.
Market data and historyBars and DataSeries expose typed C# collections, while multi-timeframe data is requested explicitly.Series use bars-ago indexing such as Close[0]; multi-series scripts must route work with BarsInProgress.Recheck bar indexing, warm-up requirements, timeframe requests, and behavior on an unfinished bar.
Indicators and chart outputIndicator classes expose output series and use the cTrader Algo indicators API.Indicator classes configure plots and update their Series values inside the NinjaScript lifecycle.Map calculations before recreating plots, labels, colors, and platform-specific drawing objects.
Orders and positionsRobot methods submit and manage trades through Symbol, Positions, PendingOrders, and volume measured in units.Strategies can use managed methods such as EnterLong and ExitLong or opt into lower-level unmanaged handling.Define fill timing, sizing, pyramiding or hedging, stops, and position ownership for the target platform.
Native validationBuild the C# project in cTrader Algo, resolve build output, attach it to the intended symbol, and run a cTrader backtest.Compile in NinjaScript Editor, load the Indicator or Strategy, and test strategies with Strategy Analyzer before runtime use.Treat generated NinjaScript as a draft until it passes the target editor, chart, and backtest workflow.

Code example

Moving-average cross: cTrader C# to NinjaScript

These fragments show where the same signal starts in each API. They are not complete standalone programs; lifecycle setup, inputs, plots, and order handling still depend on the selected artifact.

cTrader C# source fragment
var fast = Indicators.SimpleMovingAverage(Bars.ClosePrices, 10);
var slow = Indicators.SimpleMovingAverage(Bars.ClosePrices, 20);
bool longSignal = fast.Result.Last(2) <= slow.Result.Last(2)
    && fast.Result.Last(1) > slow.Result.Last(1);
NinjaScript target fragment
protected override void OnBarUpdate()
{
    if (CurrentBar < 20) return;
    bool longSignal = CrossAbove(SMA(10), SMA(20), 1);
}

Workflow

A four-step migration path

Keep generation, target-platform validation, and behavior comparison as separate stages.

  1. 1

    Inventory the source behavior

    Separate calculations, plots, alerts, orders, external dependencies, and assumptions in a C# cBot or custom indicator project.

  2. 2

    Choose the target artifact

    Decide whether the result is a C# NinjaScript Indicator or Strategy class. This choice controls lifecycle methods and available APIs.

  3. 3

    Rewrite through target APIs

    Translate state, series, indicators, drawings, and orders into NinjaTrader 8 concepts instead of replacing function names.

  4. 4

    Validate behavior natively

    Compile in NinjaScript Editor, load the Indicator or Strategy, and test strategies with Strategy Analyzer before runtime use.

Manual decisions

Decisions code replacement cannot make

  • Choose the NinjaScript base class and move cBot initialization into appropriate OnStateChange states.
  • Replace Bars and DataSeries access with NinjaScript Series and BarsInProgress routing.
  • Convert cTrader units, labels, and position events into NinjaTrader quantities, signals, and execution callbacks.

Limitations

What the draft cannot prove

  • cTrader and NinjaTrader 8 do not share one execution, data, or order model, so behavior can change even when both versions compile.
  • Broker, symbol, session, timezone, history, and fill settings can change signals and backtest results on NinjaTrader 8.
  • Pineify can generate and revise a NinjaScript draft, but the target platform remains the authority for compilation, loading, backtesting, and runtime behavior.

Use cases

When this conversion is useful

  • Port a cTrader cBot to a NinjaTrader Strategy.
  • Rebuild a cTrader C# indicator as a NinjaScript Indicator.
  • Reuse platform-neutral C# calculations while replacing all trading APIs.

FAQ

cTrader C# to NinjaScript questions

Build the NinjaScript draft with its native model in view

Bring the complete source and your artifact, timing, data, and order requirements. Validate the result in NinjaTrader 8.