Skip to main content

Strategy Framework

The MZpack strategy framework organizes trading logic into a structured pipeline: patterns define trading conditions through decision trees of signals and filters, which trigger entries with protective orders, managed by position management and risk management rules. This page covers each component in detail.

Patterns

A pattern is a set of conditions that, when satisfied, produce a determined trading direction (Long or Short). Patterns are the central organizing unit of any MZpack strategy.

Pattern Types

TypePurpose
EntryOpens a new position when validated
ExitCloses an existing position when validated (optional)
ReversalCloses the current position and opens one in the opposite direction
ScaleInAdds to an existing position
ScaleOutReduces an existing position

How a Pattern Works

When a pattern is evaluated, three steps occur in sequence:

  1. Signals tree — the signals decision tree is evaluated. If a determined direction (Long or Short) results, proceed to step 2. Otherwise the pattern is not validated.
  2. Filters tree — the filters decision tree is evaluated starting from the bar at which signals validated. If the direction is confirmed, proceed to step 3.
  3. Entry — a position is opened according to the entry configuration and the determined direction.

The signals tree must contain at least one signal. The filters tree is optional — if no filters are present, the pattern proceeds directly from signals to entry.

Pattern Localization

A pattern can be localized to constrain where its signals and filters must occur:

  • Price range — signals/filters must occur within a specified number of ticks
  • Bar range — signals/filters must occur within a specified number of bars
  • Session — signals/filters must occur within the current trading session

Price and bar ranges can be set independently for the signals tree and the filters tree.

Allowed Direction

Each pattern has an AllowedDirection property that restricts which directions the pattern can validate: Long, Short, or Any (both). The resulting direction from the decision trees must be consistent with the allowed direction.

Decision Trees

Signals and filters are organized into logical decision trees. Each tree has a root logical node, and supports three types of nodes:

  • Logical node — performs AND, OR, or CONJUNCTION operations on its child nodes
  • Signal/Filter node — a terminal node that evaluates market data and returns a direction (Long, Short, Any, or None)
  • Action node — performs auxiliary calculations without affecting the resulting direction, but can return None to terminate tree evaluation

Logic Operations

Each logical node combines the directions of its children using one of three operations:

OperationInputResult
ANDNone, NoneNone
ANDLong, NoneNone
ANDLong, ShortNone
ANDLong, LongLong
ANDLong, AnyLong
ORNone, NoneNone
ORLong, NoneLong
ORLong, ShortNone
ORLong, AnyLong
CONJUNCTIONNone, NoneNone
CONJUNCTIONLong, NoneLong
CONJUNCTIONShort, LongAny
CONJUNCTIONLong, AnyAny

AND requires all children to agree on direction. OR accepts any single valid direction. CONJUNCTION combines differing directions into Any — useful when you want coherent signals in a range without requiring a specific order.

Short-Circuit Evaluation

By default, AND nodes use short-circuit evaluation: if the first child returns None, the remaining children are skipped. This improves performance but makes the result dependent on the order of signals in the tree. For ranged patterns where signal order matters, consider using a CONJUNCTION root node with separate Long and Short branches.

Tree Structure Rules

  • The root node is always a logical node
  • Logical nodes cannot be terminal (leaf) nodes — they must have children
  • Signal/filter nodes must be terminal nodes
  • The signals tree must have at least one signal node
  • The filters tree root can be terminal (empty), meaning no filters are used

Invalid tree structures raise an error on strategy initialization.

Signals

A signal processes incoming market data and determines a trading direction based on indicator values. Each signal has:

  • Direction — the current output: Long, Short, Any, or None
  • Entry price — an optional price for opening the position
  • Chart range — the bar/price range where the signal was validated (for pattern localization)

Calculation Modes

ModeDescription
OnEachTickSignal is recalculated on every incoming tick
OnBarCloseSignal is recalculated only when a bar closes
NotApplicableUsed for Level 2 (DOM) signals that process market depth events independently

Market Data Sources

SourceDescription
Level1Order flow data (tick data) — used by most signals
Level2Market depth / DOM data — used by DOM-based signals
CustomCustom event source

Built-in Signals

The framework includes these ready-to-use signals:

SignalIndicatorDescription
TradesClusterSignalmzBigTradeDetects a cluster of trades at a given side within a bar/price range
BigTradeSignalmzBigTradeLONG for sell trades, SHORT for buy trades
FootprintImbalanceSignalmzFootprintLONG for buy imbalances, SHORT for sell imbalances
FootprintAbsorptionSignalmzFootprintLONG for sell absorptions, SHORT for buy absorptions
FootprintSRZonesSignalmzFootprintSearches for S/R zones (imbalance or absorption type)
ClusterZonesSignalmzFootprintSearches for consecutive cluster zones in the current bar
BarJoinedPOCsSignalmzFootprintValidates if the bar has a given number of joined POCs
BarDeltaSignalmzFootprintLONG for positive delta, SHORT for negative delta
CumulativeDeltaSignalmzFootprintLONG for positive session cumulative delta, SHORT for negative
DeltaRateSignalmzFootprintLONG for positive delta rate, SHORT for negative delta rate
OrderflowBarMetricsSignalmzFootprintSignal based on orderflow metrics of the bar
DeltaDivergenceSignalmzDeltaDivergenceDetects delta-price divergence patterns
RelativeToProfileSignalmzVolumeProfileSHORT if price above VWAP/VAH, LONG if below VWAP/VAL
VolumeProfileDeltaSignalmzVolumeProfileLONG for negative profile delta, SHORT for positive
DOMImbalanceSignalmzMarketDepthDetects DOM imbalance; entry at best bid (LONG) or best offer (SHORT)
DOMBlockSignalmzMarketDepthDetects large limit orders in the DOM
BarIcebergsSignalmzVolumeDeltaLONG for icebergs on bid side, SHORT for icebergs on ask side
BarVolumeSignalVolumeValidates if bar volume meets a minimum threshold
BarMetricsSignalPrice ActionSignal based on price action patterns inside the bar
BarWickSignalOHLCLONG for bars with low wick only, SHORT for bars with high wick only
UpDownBarSignalOHLCLONG for bullish bars, SHORT for bearish bars

Custom signals can be created by extending the Signal base class.

Filters

Filters are structurally identical to signals — they process market data and return a direction. The distinction is organizational: filters are placed in the filters tree, which is evaluated after the signals tree validates. This separation lets you define primary trading conditions as signals and confirmations as filters.

For example, a strategy might use big-trade clusters and absorption zones as signals, and DOM imbalance as a filter to confirm the entry direction before opening a position.

Entry Configuration

When a pattern validates, a position is opened according to the entry configuration.

Order Methods

MethodDescription
MarketSubmits a market order for immediate execution
LimitSubmits a limit order at the price generated by the pattern, with optional shift in ticks
StopLimitSubmits a stop-limit order

For limit orders, additional options include:

  • Limit entry shift — offset in ticks added to the pattern-generated price
  • Limit entry price chase — moves the pending limit order tick-by-tick as price moves away
  • Cancel limit order — cancels unfilled limit orders after a specified number of ticks, bars, or milliseconds

Protective Orders

Order TypeDescription
Stop LossCloses the position at a specified number of ticks or a fixed price from entry
Profit TargetTakes profit at a specified number of ticks or a fixed price from entry
Break-evenMoves the stop loss to the entry price (plus an optional shift) after price moves a specified number of ticks in your favor
TrailA trailing stop that activates after a specified profit threshold, then follows price at a defined distance and step size

Each entry also specifies a Quantity (number of contracts) and a Signal name for order identification.

Position Management

ATM Modes

MZpack strategies support two ATM (Advanced Trade Management) approaches:

ModeDescription
MZpack ATMUses MZpack's built-in order management with Entry, Trail, and Break-even classes
NinjaTrader ATMDelegates order management to a NinjaTrader ATM strategy template

The ATM mode is configured via the strategy's PositionManagement property.

Opposite Pattern Action

When a position is open and the pattern validates in the opposite direction, the strategy's behavior is controlled by the OppositePatternAction setting:

ActionDescription
NoneKeep the current position, ignore the opposite signal
CloseClose the current position
ReverseClose the current position and open a new one in the opposite direction
UnmanagedSignals continue to be calculated after entering a position — can be used for scaling in

Position Lifecycle

The position progresses through these states:

StateDescription
FlatNo position open
EntrySubmittingEntry order has been submitted
LongLimitPending / ShortLimitPendingLimit order is pending, not yet filled
LongMarketPending / ShortMarketPendingMarket order is pending
Long / ShortPosition is filled

Trading Times

The strategy can be restricted to specific trading hours using the Trading Times setting:

  • In Auto mode, no entries are made outside trading times. Open positions are closed and pending orders are cancelled when trading times end.
  • In Manual mode, trading times do not affect the strategy — signals continue to display regardless of the time.

Risk Management

Risk management enforces daily limits that apply at the account level (not per instrument). All limits reset overnight if the strategy is not in a position.

LimitDescription
DailyLossLimitMaximum loss allowed in a single day. The strategy stops trading when realized + unrealized PnL reaches this negative threshold.
DailyMaxDrawdownA trailing daily loss limit. Tracks the peak account value for the day and stops trading if the account drops by this amount from the peak.
DailyProfitLimitMaximum profit target for the day. The strategy stops trading when realized + unrealized PnL reaches this positive threshold.
DailyTradesLimitMaximum number of trades (filled entries) allowed per day.

When a risk limit is reached, the current position is closed automatically and no further entries are made for the rest of the day.

note

Risk management tracks both realized and unrealized PnL. An open position's floating profit or loss counts toward daily limits.

Backtesting

MZpack strategies can be backtested in the NinjaTrader Strategy Analyzer:

  1. Enable the MZpack: backtesting option in the strategy settings
  2. Open NinjaTrader Strategy Analyzer
  3. Select your strategy and configure the backtest parameters
  4. Run the backtest
note

Enabling backtesting increases historical data loading time for mzFootprint and mzVolumeProfile indicators, as load-time optimizations must be disabled to calculate all values on historical bars.

Visualization

The strategy framework provides several visualization options, configured in the Visual category of the strategy properties.

Pattern Background

Enable Pattern: background to display a colored vertical area on the chart when an Entry pattern validates. Separate colors can be assigned for Long and Short directions, and for the signals and filters portions of the pattern.

Entry/Exit Markup

In Manual operating mode, enable Entry/Exit: markup to display entry and exit markers on the chart. Options include Marker only, or Marker and Text.

Pattern Dashboard

Enable Pattern dashboard: show to display a real-time view of the decision tree on the chart, showing the current state (direction) of each signal and filter on every bar. This is particularly useful in Manual mode for discretionary trading.

Partially Visible Mode

When a strategy uses multiple indicators, the chart can become cluttered. Partially Visible mode shows only the indicator plots that are relevant to validated signals. Three strategy indicator classes support this mode:

Strategy IndicatorPartially Visible Property
StrategyBigTradeIndicatorITrade.View.PartiallyVisible
StrategyFootprintIndicatorIFootprintBar.PartiallyVisible
StrategyMarketDepthIndicatorIMarketDepthBlock.PartiallyVisible

Toggle Partially Visible mode by clicking the "eye" button next to the indicator name in the chart. See Algo Strategy — Partially Visible for a full code sample.

Logging

MZpack strategies include a built-in logging system for debugging and monitoring.

Log Levels

Log level is a bitmask — multiple levels can be combined:

LevelDescription
NONENo logging
NV_PATTERN_OBCLog not-validated pattern state on each bar close (for debugging)
V_PATTERNLog pattern when validated
ORDERLog order events: submitted, working, filled, partially filled, cancelled, rejected
ENTRYLog entry details
POSITIONLog position state changes
PROPERTIESLog strategy properties on initialization
ALLAll of the above

Log Targets

TargetDescription
NinjaScriptOutputNinjaTrader Output window
FileText file in Documents\NinjaTrader 8\mzpacklog\
AllBoth Output window and file

Control Panel

The optional Control Panel is a panel on the right side of the chart that provides runtime controls for the strategy. It can display operating mode switches, direction selectors, and other configurable properties. Enable it with the ControlPanelShow option. The panel is disabled while historical data is loading.

Multi-Data Series

Strategies can use multiple timeframes or instruments by adding additional data series. Each MZpack indicator and signal can be attached to a specific data series by index, enabling multi-timeframe analysis within a single strategy.