Skip to main content

MZpackStrategyBase

MZpackStrategyBase is the abstract base class for all MZpack strategies. It extends NinjaTrader's strategy infrastructure with MZpack indicator management, market data routing, and SharpDX chart rendering.

Namespace: MZpack.NT8.Algo Inheritance: MZpackStrategyBase : StrategyRenderBase : NinjaTrader.NinjaScript.Strategies.Strategy Source: [INSTALL PATH]/API/MZpackStrategyBase.cs

Delegates​

Set these in your strategy constructor or OnStateChange(SetDefaults) to define the strategy and its indicators:

DelegateSignaturePurpose
OnCreateAlgoStrategyStrategy OnCreateAlgoStrategyDelegate()Create and return the Algo.Strategy instance
OnCreateIndicatorsList<TickIndicator> OnCreateIndicatorsDelegate()Create and return the list of strategy indicators
OnEachTickHandlervoid OnTickDelegate(MarketDataEventArgs e, int currentBarIdx)Custom tick processing
OnBarCloseHandlervoid OnTickDelegate(MarketDataEventArgs e, int currentBarIdx)Custom bar close processing
OnMarketDepthHandlervoid OnMarketDepthDelegate(MarketDepthEventArgs e, int currentBarIdx)Custom Level 2 processing

Core Properties​

Strategy and Indicators​

PropertyTypeDescription
StrategyStrategyThe Algo.Strategy instance (set via OnCreateAlgoStrategy)
IndicatorsObservableCollection<TickIndicator>All strategy indicators
ExportsExportsData export handler
DashboardCollapsedNodesstringSerialized pattern-dashboard legend state. It is maintained by the dashboard and normally should not be set directly

Data Series Configuration​

PropertyTypeDefaultDescription
WorkingDataSeriesIdxint-1Which data series drives pattern logic (-1 = all)
TradingDataSeriesIdxint0Where orders are submitted
PatternValidatingDataSeriesIdxint0Data series for dashboard display

Operating Mode​

PropertyTypeDefaultDescription
OperatingStrategyOperatingAutoAuto = automated entries, Manual = chart trader entries
PositionManagementPositionManagementMZpackMZpack = MZpack manages position, NinjaTraderATM = use ATM template
WorkingStateRealtimebooltrueProcess data in real-time
WorkingStateHistoricalboolfalseProcess data on historical bars
EnableBacktestingboolfalseEnable backtesting mode

Logging​

PropertyTypeDefaultDescription
LogLevelLogLevelNONELog verbosity flags
LogTargetLogTargetNinjaScriptOutputOutput destination (File, NinjaScriptOutput, or All)

Key Methods​

Indicator Management​

MethodReturn TypeDescription
GetIndicator<T>(string name)TickIndicatorGet indicator by type and name
GetIndicator(string name)TickIndicatorGet indicator by name
RemoveIndicator(TickIndicator indicator)voidRemove an indicator
ApplyRequiredCapabilities()voidCollect requirements declared by tree and probe signals, then enable the required indicator calculations. It is called by Algo.Strategy.Initialize(); call it again after changing the signal set

Data Series​

MethodReturn TypeDescription
AddTickDataSeries()voidAdd 1-tick data series (auto-called if tick replay is off)
AddCustomDataSeries(BarsPeriodType, int)intAdd custom period data series, returns index

Price Helpers​

MethodReturn TypeDescription
RoundToTickSize(double price)doubleRound to valid tick size
PriceDiffTicks(double high, double low)intTick distance between prices
PriceAddTicks(double price, int ticks)doubleAdd ticks to price
PriceSubtractTick(double price)doubleSubtract one tick
Compare(double price1, double price2)intTick-aware price comparison
IsPriceApproaching(double price, double level, int ticks)boolCheck if price is within N ticks of level

Candle Access​

MethodReturn TypeDescription
GetCandle(int ago)ICandleGet candle from primary data series
GetCandle(int ago, int dataseries)ICandleGet candle from specific data series

Control Panel​

MethodReturn TypeDescription
CreateControlPanelElements()UIElement[]Override to create custom UI controls
ControlPanel_AttachEventHandlers()voidOverride to attach control event handlers
ControlPanel_DetachEventHandlers()voidOverride to detach control event handlers
OnConfigureSignalProbe(SignalProbe)voidOverride to configure a newly created probe, for example its horizon and outcome ladder
OnBeforeSignalProbePass(SignalProbe)voidOverride to refresh host-owned state before each probe pass

Enums​

StrategyOperating​

ValueDescription
AutoEntries made automatically when patterns validate
ManualEntries made manually from chart trader

PositionManagement​

ValueDescription
MZpackPosition managed by MZpack API (Entry/Exit/Trail)
NinjaTraderATMPosition managed by NinjaTrader ATM template

Example: Minimal Custom Strategy​

public class MyCustomStrategy : MZpackStrategyBase
{
StrategyFootprintIndicator footprint;
StrategyVolumeProfileIndicator vpIndicator;

public MyCustomStrategy()
{
// Create indicators
OnCreateIndicators = () =>
{
footprint = new StrategyFootprintIndicator(this, "FP");
footprint.TicksPerLevel = 1;

vpIndicator = new StrategyVolumeProfileIndicator(this, "VP");
vpIndicator.ProfileCreation = ProfileCreation.Session;
vpIndicator.ProfileAccuracy = ProfileAccuracy.Minute;

return new List<TickIndicator> { footprint, vpIndicator };
};

EnableBacktesting = true;
WorkingStateHistorical = true;
}

protected override void OnBarUpdate()
{
if (BarsInProgress != TradingDataSeriesIdx) return;
if (CurrentBar < 10) return;

IFootprintBar bar = footprint.FootprintBars[CurrentBar];
IVolumeProfile profile = vpIndicator.GetProfile(0);
if (profile == null) return;

// Buy when delta is positive and price is below VWAP
if (bar.Delta > 0 && Close[0] < profile.VWAP)
{
EnterLong();
}
}
}

See Also​