Skip to main content

Strategies Overview

The MZpack strategy framework sits on top of NinjaTrader 8's strategy API and provides order flow-aware trading automation. Every MZpack strategy inherits from MZpackStrategyBase, which handles indicator lifecycle, market data routing, and chart rendering.

Two Approaches

ApproachClassWhen to Choose
Custom StrategyMZpackStrategyBaseFull C# control, simple rules, backtesting-only scenarios
Algo.StrategyAlgo.Strategy + PatternDeclarative signal combination, real-time trading, ATM integration

Most production strategies use Algo.Strategy because it handles signal evaluation, position management, and chart rendering automatically. Use MZpackStrategyBase directly when you need backtesting with simple rules or full manual control.

Component Architecture

MZpackStrategyBase
└── Algo.Strategy
├── Entry Pattern
│ ├── Signals (Decision Tree)
│ │ ├── Actions — side effects (e.g. rolling profile)
│ │ ├── Filters — confirm or reject signals
│ │ └── LogicalNode — AND / OR / CONJUNCTION
│ └── Entry — order submission (Market, Limit, StopLimit)
│ └── Exit / Trail — stop loss, profit target, trailing stop
├── Reversal Pattern
├── ScaleIn Pattern
├── ScaleOut Pattern
└── Risk Management — daily limits

Strategy Lifecycle

OnStateChange(SetDefaults)     → Set default property values
OnStateChange(Configure) → OnCreateIndicators(), OnCreateAlgoStrategy()
OnStateChange(DataLoaded) → Indicators initialized, data series ready
OnStateChange(Historical) → Backtesting begins
OnStateChange(Transition) → Historical → Realtime switch
OnStateChange(Realtime) → Live trading
OnStateChange(Terminated) → Cleanup

During execution, market data flows through:

OnBarUpdate()                  → Bar close events (all data series)
OnMarketData(e) → Level 1 tick events
OnMarketDepth(e) → Level 2 DOM events
OnOrderUpdate(...) → Order state changes
OnExecutionUpdate(...) → Fill events

Reading Order

  1. MZpackStrategyBase — base class and lifecycle
  2. Algo.Strategy — pattern-oriented framework
  3. Pattern — pattern types and evaluation
  4. Position — position management
  5. Signals Overview — signal system and all built-in signals
  6. Pipeline — Action, Filter, Decision Tree components
  7. Entry / Exit / Trail — order management
  8. Risk Management — daily limits and caps