# Coming from NinjaScript

> A real import, the ideas side by side, and the names that translate.

Source: https://algobarsx.com/docs/from-ninjascript/

This is a real run of the importer on a small NinjaScript script. The result compiles. 26 lines were read: 5 carried over exactly, 1 were adapted and 4 came back as decisions for you.

```algobarsx
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();
            }
        }
    }
}
```

```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
```

## Line by line

| Status | Your line | What happened |
| --- | --- | --- |
| 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 |

> **Tip.** 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.

## Names the importer translates for you

| Their name | AlgoBarsX |
| --- | --- |
| `currentbar` | [`bar.index`](https://algobarsx.com/docs/ref-var-bars/#ref-bar-index) |
| `instrument` | [`market.symbol`](https://algobarsx.com/docs/ref-var-market/#ref-market-symbol) |
| `ticksize` | [`market.point_size`](https://algobarsx.com/docs/ref-var-market/#ref-market-point-size) |
| `null` | `na` |

> **Read every import before you run it.** Compare the plain-English description with what your original did, settle each decision, and backtest before you deploy.
