Project Setup
This page covers two workflows: using the NinjaTrader built-in editor (quickest) and setting up a Visual Studio 2022 project (recommended for multi-file projects).
Option 1: NinjaTrader Built-in Editor
The fastest way to start:
- In NinjaTrader, go to New → NinjaScript Editor
- Right-click in the editor and select New → Strategy
- Enter a name (e.g.,
MyMZpackStrategy) and click Generate - Replace the generated base class with
MZpackStrategyBase:
using MZpack;
using MZpack.NT8;
using MZpack.NT8.Algo;
using MZpack.NT8.Algo.Indicators;
namespace NinjaTrader.NinjaScript.Strategies
{
public class MyMZpackStrategy : MZpackStrategyBase
{
// ...
}
}
- Add a reference to
MZpack.NT8.Pro.dll: right-click in the editor, choose References..., click Add, selectMZpack.NT8.Pro.dll, then click Open. Click OK to close the References window. - Press F5 to compile
Option 2: Visual Studio 2022
Create the Project
- Open Visual Studio 2022
- File → New → Project → select Class Library (.NET Framework)
- Set framework to .NET Framework 4.8
- Set platform to x64
- Name the project (e.g.,
MyMZpackStrategies)
Add Assembly References
Right-click References → Add Reference → Browse and add the following DLLs:
From Documents\NinjaTrader 8\bin\Custom\:
| Assembly | Provides |
|---|---|
MZpack.NT8.Pro.dll | MZpack API — all MZpack.* namespaces |
From NinjaTrader installation directory (typically C:\Program Files\NinjaTrader 8\bin\):
| Assembly | Provides |
|---|---|
NinjaTrader.Core.dll | Core NinjaTrader types |
NinjaTrader.Gui.dll | UI types (Stroke, Brushes) |
NinjaTrader.Vendor.dll | Vendor integration |
From NinjaTrader installation directory (for Direct2D rendering in custom indicators):
| Assembly | Provides |
|---|---|
SharpDX.dll | SharpDX core |
SharpDX.Direct2D1.dll | Direct2D rendering |
SharpDX.DXGI.dll | DXGI types |
Framework assemblies (Add Reference → Assemblies):
WindowsBasePresentationCorePresentationFrameworkSystem.Xml.Serialization
Set Build Output
Set the build output path to the NinjaTrader custom folder so your compiled DLL loads automatically:
- Right-click the project → Properties → Build
- Set Output path to:
Documents\NinjaTrader 8\bin\Custom\ - Set Platform target to x64
Namespace Convention
NinjaTrader requires strategies to live under the NinjaTrader.NinjaScript.Strategies namespace:
namespace NinjaTrader.NinjaScript.Strategies.MyProject
{
public class MyStrategy : MZpackStrategyBase
{
// ...
}
}
Minimal Strategy Template
A minimal MZpack strategy with one indicator:
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using MZpack;
using MZpack.NT8;
using MZpack.NT8.Algo;
using MZpack.NT8.Algo.Indicators;
using NinjaTrader.Data;
namespace NinjaTrader.NinjaScript.Strategies.MyProject
{
public class MyFirstStrategy : MZpackStrategyBase
{
StrategyBigTradeIndicator bigTradeIndicator;
public MyFirstStrategy() : base()
{
OnCreateIndicators = new OnCreateIndicatorsDelegate(CreateIndicators);
OnBarCloseHandler = new OnTickDelegate(OnBarClose);
}
protected List<TickIndicator> CreateIndicators()
{
List<TickIndicator> indicators = new List<TickIndicator>();
bigTradeIndicator = new StrategyBigTradeIndicator(this, "BigTrade")
{
TradeFilterEnable = true,
TradeFilterMin = TradeMin
};
indicators.Add(bigTradeIndicator);
return indicators;
}
protected override void OnStateChange()
{
base.OnStateChange();
lock (Sync)
{
if (State == State.SetDefaults)
{
BarsRequiredToTrade = 1;
EntriesPerDirection = 1;
TradeMin = 50;
}
else if (State == State.Configure)
{
bigTradeIndicator.TradeFilterMin = TradeMin;
}
}
}
protected void OnBarClose(MarketDataEventArgs e, int currentBarIdx)
{
// Your trading logic here
}
[Display(Name = "Min trade volume", GroupName = "Strategy", Order = 0)]
[Range(1, int.MaxValue)]
[NinjaScriptProperty]
public long TradeMin { get; set; }
}
}
Key Points
| Concept | Detail |
|---|---|
| Base class | Inherit from MZpackStrategyBase, not NinjaTrader's Strategy |
| Constructor | Set OnCreateIndicators and optionally OnBarCloseHandler / OnEachTickHandler delegates |
OnStateChange | Always call base.OnStateChange() first and wrap in lock (Sync) |
State.SetDefaults | Set default property values |
State.Configure | Apply UI property values to indicators, create entries and patterns |
| Indicator creation | Return a List<TickIndicator> from your CreateIndicators method |
| Properties | Use [Display] and [NinjaScriptProperty] attributes for NinjaTrader UI |
Working with Samples
All MZpack API samples are included in the source code within #if APISAMPLE blocks. To compile a sample in NinjaTrader:
- Copy the sample
.csfile toDocuments\NinjaTrader 8\bin\Custom\Strategies\ - Remove the
#if APISAMPLEdirective at the top and the#endifat the bottom - Compile in NinjaTrader (press F5 in the NinjaScript Editor)
Next Steps
- API Overview — architecture and available interfaces
- Advanced Template — full-featured strategy template with dual entries, control panel, and XML persistence
- Custom Strategy — VWAP/POC — simple backtesting strategy using volume profile