Skip to main content

Decision Tree

The decision tree evaluates signals, filters, and actions to determine a trade direction. A Pattern holds two trees — SignalsTree for signal evaluation and FiltersTree for post-validation gating.

Namespace: MZpack.NT8.Algo

Evaluation Flow

Pattern.Evaluate()
├── SignalsTree
│ └── Root (LogicalNode: AND/OR)
│ ├── Signal A → Long
│ ├── LogicalNode (OR)
│ │ ├── Signal B → Short
│ │ └── Signal C → None (not triggered)
│ ├── Action → side effect
│ └── RangeNode → max 5 bars, 20 ticks

└── FiltersTree (evaluated only if SignalsTree validates)
└── Root (LogicalNode: AND)
└── ValueInRangeFilter → Any (pass) or None (block)

Pattern

Top-level container that holds both trees and drives evaluation.

Inheritance: Pattern : StrategyItem Source: [INSTALL PATH]/API/Pattern.cs

Properties

PropertyTypeDefaultDescription
TypePatternTypeEntryPattern type
AllowedDirectionSignalDirectionAnyConstrain pattern to Long, Short, or Any
IsShortCircuitANDEvaluationboolIf true, AND signals are validated in sequence
SignalsSignalsTreeSignals decision tree
FiltersFiltersTreeFilters decision tree

Read-Only State

PropertyTypeDescription
DirectionSignalDirectionResulting direction after evaluation (None, Long, Short)
StrategyStrategyParent Algo.Strategy

Constructor

public Pattern(Strategy strategy, Logic rootLogic, Range signalsRange,
Logic filtersLogic, Range filtersRange, bool isShortCircuitANDEvaluation)

Creates both SignalsTree and FiltersTree with the specified root logic and range constraints.


SignalsTree

Wraps a root LogicalNode and evaluates all signals on each market event.

Inheritance: SignalsTree : ViewModelBase Source: [INSTALL PATH]/API/SignalsTree.cs

Properties

PropertyTypeDescription
RootLogicalNodeRoot node of the tree
RangeRangeBar/tick range constraint for signal proximity
ChartRangeChartRangeCombined bar/price range of validated signals
ValidatedCountintNumber of validated signals
HeightintTree depth

Constructor

public SignalsTree(Pattern pattern, Logic rootLogic, Range range)

Key Methods

MethodDescription
OnMarketEvent(object e, MarketDataSource source, bool isFirstTickOfBar, SignalDirection allowed)Propagate market event through the tree
Initialize(Pattern pattern, bool isInConstructor)Bind to pattern
UpdateChartRange()Recalculate combined chart range from all signals
HasSignal(MarketDataSource source)Check if the tree contains signals for a data source

FiltersTree

Evaluated only after SignalsTree validates. If the filter expires (out of range), the entire pattern resets.

Inheritance: FiltersTree : SignalsTree Source: [INSTALL PATH]/API/FiltersTree.cs

Behavior

  • UpdateChartRange sets MinBarIdx to Pattern.Signals.ChartRange.MaxBarIdx — filters are anchored to the signal validation point
  • OnMarketEvent checks the bar range; if signals are out of Range.Bars, the pattern resets
  • Filters use SignalDirection.Any to pass and SignalDirection.None to block

LogicalNode

AND/OR combiner node in the decision tree.

Inheritance: LogicalNode : Node Source: [INSTALL PATH]/API/Signals/LogicalNode.cs

Properties

PropertyTypeDescription
LogicLogicCombination logic

Logic Behavior

LogicBehavior
AndAll children must resolve to a determined direction
OrFirst child with a determined direction wins
ConjunctionUpgrades directions: Long + Short = Any

Constructor

public LogicalNode(Logic logic)

Allowed child types: LogicalNode, Signal, RangeNode.

Key Methods

MethodDescription
CheckSyntax()Validates that the node has at least one child
GetSignals(MarketDataSource source)Recursively collects all signals for the given data source
OnPatternValidated()Propagates validation event to all children

RangeNode

Constrains how far apart signals can validate (in bars and ticks) and still count as one pattern.

Inheritance: RangeNode : Node, IRange Source: [INSTALL PATH]/API/Signals/RangeNode.cs

Properties

PropertyTypeDefaultDescription
Barsint0Max bar distance (0 = no limit)
Ticksint0Max tick distance (0 = no limit)
LogicLogicAndHow Bars and Ticks combine
IsInSessionboolfalseRestrict to current session

Key Methods

MethodDescription
IsInRange(int bars, int ticks)Returns true if within constraints (AND: both must pass; OR: either passes)
CheckSyntax()Validates that range nodes have no children

Enums

PatternType

ValueDescription
EntryStandard entry pattern
ExitExit pattern
ReversalReverse position
ScaleInAdd to position
ScaleOutReduce position

Logic

ValueDescription
AndAll conditions must be true
OrAny condition is sufficient
ConjunctionDirection upgrade (Long + Short = Any)

See Also