Skip to main content

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:

  1. In NinjaTrader, go to New → NinjaScript Editor
  2. Right-click in the editor and select New → Strategy
  3. Enter a name (e.g., MyMZpackStrategy) and click Generate
  4. 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
{
// ...
}
}
  1. Add a reference to MZpack.NT8.Pro.dll: right-click in the editor, choose References..., click Add, select MZpack.NT8.Pro.dll, then click Open. Click OK to close the References window.
  2. Press F5 to compile

Option 2: Visual Studio 2022

Create the Project

  1. Open Visual Studio 2022
  2. File → New → Project → select Class Library (.NET Framework)
  3. Set framework to .NET Framework 4.8
  4. Set platform to x64
  5. 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\:

AssemblyProvides
MZpack.NT8.Pro.dllMZpack API — all MZpack.* namespaces

From NinjaTrader installation directory (typically C:\Program Files\NinjaTrader 8\bin\):

AssemblyProvides
NinjaTrader.Core.dllCore NinjaTrader types
NinjaTrader.Gui.dllUI types (Stroke, Brushes)
NinjaTrader.Vendor.dllVendor integration

From NinjaTrader installation directory (for Direct2D rendering in custom indicators):

AssemblyProvides
SharpDX.dllSharpDX core
SharpDX.Direct2D1.dllDirect2D rendering
SharpDX.DXGI.dllDXGI types

Framework assemblies (Add Reference → Assemblies):

  • WindowsBase
  • PresentationCore
  • PresentationFramework
  • System.Xml.Serialization

Set Build Output

Set the build output path to the NinjaTrader custom folder so your compiled DLL loads automatically:

  1. Right-click the project → Properties → Build
  2. Set Output path to: Documents\NinjaTrader 8\bin\Custom\
  3. 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

ConceptDetail
Base classInherit from MZpackStrategyBase, not NinjaTrader's Strategy
ConstructorSet OnCreateIndicators and optionally OnBarCloseHandler / OnEachTickHandler delegates
OnStateChangeAlways call base.OnStateChange() first and wrap in lock (Sync)
State.SetDefaultsSet default property values
State.ConfigureApply UI property values to indicators, create entries and patterns
Indicator creationReturn a List<TickIndicator> from your CreateIndicators method
PropertiesUse [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:

  1. Copy the sample .cs file to Documents\NinjaTrader 8\bin\Custom\Strategies\
  2. Remove the #if APISAMPLE directive at the top and the #endif at the bottom
  3. Compile in NinjaTrader (press F5 in the NinjaScript Editor)

Next Steps