# Bring your NinjaScript scripts. Keep your work.

> You have spent years on your NinjaScript scripts. You should not have to start again. Paste one in, and AlgoBarsX rewrites it and tells you what it did to every line.

Source: https://algobarsx.com/convert/ninjascript/

## A real example.

A real run of the importer (26 lines: 5 exact, 1 adapted, 4 your call).

```
namespace NinjaTrader.NinjaScript.Strategies
{
    public class MacdMomentum : Strategy
    {
        protected override void OnStateChange()
        {
            if (State == State.SetDefaults)
            {
                Name = "MACD Momentum";
            }
        }
        protected override void OnBarUpdate()
        {
            if (CrossAbove(EMA(Close, 12), EMA(Close, 26), 1))
            {
                SetStopLoss(CalculationMode.Ticks, 40);
                SetProfitTarget(CalculationMode.Ticks, 80);
                EnterLong();
            }
            if (CrossBelow(EMA(Close, 12), EMA(Close, 26), 1))
            {
                ExitLong();
            }
        }
    }
}
```

becomes

```algobarsx
strategy "MACD Momentum"
    market: EURUSD
    bars: 1h

input risk = 1%

when crosses_above(ema(close, 12), ema(close, 26)):
    buy risk: risk, stop: 40 points, target: 80 points

when crosses_below(ema(close, 12), ema(close, 26)):
    close_all side: long
```

- Exact: `SetStopLoss ( CalculationMode.Ticks , 40 ) ;` — a stop in ticks became points
- Your call: `; 
 SetProfitTarget ( CalculationMode.Ticks , 80 )` — this line has no equivalent yet
- Exact: `SetProfitTarget ( CalculationMode.Ticks , 80 ) ;` — a stop in ticks became points
- Your call: `; 
 EnterLong ( ) ; 
 }` — this line has no equivalent yet
- Adapted: `EnterLong ( ) ; 
 } 
 if` — NinjaTrader sizes an order by the strategy settings, so this one risks a set share of the balance
- Your call: `; 
 } 
 if ( CrossBelow (` — this line has no equivalent yet
- Exact: `if ( CrossAbove ( EMA ( Close ,` — a condition became a rule
- Exact: `ExitLong ( ) ; 
 } 
 }` — an exit carried over
- Your call: `; 
 } 
 } 
 }` — this line has no equivalent yet
- Exact: `if ( CrossBelow ( EMA ( Close ,` — a condition became a rule

## How the ideas translate.

| In NinjaScript | In AlgoBarsX |
| --- | --- |
| `OnBarUpdate()` | the body of the script |
| `EMA(Close, 12)` | ema(close, 12) |
| `CrossAbove(a, b, 1)` | crosses_above(a, b) |
| `SetStopLoss(CalculationMode.Ticks, 40)` | stop: 40 points, on the order itself |
| `SetProfitTarget(CalculationMode.Ticks, 80)` | target: 80 points |
| `EnterLong()` | buy |
| `ExitLong()` | close_all side: long |
| `Instrument, TickSize` | market.symbol, market.point_size |

Set a stop with `SetStopLoss` before the entry. The import sizes the trade by risk, and a risk-based order needs a stop to measure from. The C# around the strategy (namespaces, State handling) comes back as notes, not code.

## How to move a script.

1. **Paste or upload** Open the Terminal, choose Import, and paste your code or pick the file.
2. **Read every note** Each line is marked exact, adapted, or your call. Settle every “your call” before you go on.
3. **Read it back, then test** Check the plain-English description against what your old script did. Then run a test.

## What you gain.

- **It reads itself back** The compiler writes out what the script does in plain English.
- **Units are real** Percent, pips, R and money are types. Mix-ups are caught before anything runs.
- **One script everywhere** The same file draws, tests, alerts and trades.

> **Always read an import before you run it.** No converter is perfect, and some shapes of code import better than others. Other platforms leave things unsaid that AlgoBarsX makes you state, such as the market, the bar size and the trade size. Compare the plain-English description with what your old script did, and test before you deploy.

## Good questions.

**Will every script convert cleanly?** No. Simple, common shapes convert best. An import that does not compile says so, and every changed line carries a note. Always read the result.

**Do I lose my original?** No. Your old script is untouched. Lines that needed a choice keep the original as a comment.

**Is it free?** AlgoBars is $0 a month with no card. Credits pay for AI, tests and auto trades.

## Important

Trading is risky and you can lose money. AlgoBars is software, not a broker or an adviser. Backtests are hypothetical and leave out spread, fees, swaps and slippage. AlgoBarsX is in beta.
