Overview
The signal-based strategy module provides components for trading based on prediction signals from machine learning models or other signal generators. It includes:- Signal types with direction, strength, and confidence
- Configurable confidence thresholds
- Position sizing based on signal strength
- Risk management with position limits
Signal
Represents a trading signal with direction, strength, and confidence.Signal Fields
direction
The trading direction suggested by the signal:+1: Buy signal (expect price to increase)-1: Sell signal (expect price to decrease)0: Neutral signal (no clear direction)
strength
Magnitude of the signal, ranging from 0.0 to 1.0. Higher values indicate stronger signals. Usage:- Can be used for position sizing
- Filters out weak signals
- Typically derived from model prediction magnitude
confidence
Model confidence in the prediction, ranging from 0.0 to 1.0. Higher values indicate more reliable signals. Usage:- Primary filter for signal quality
- Compared against
min_confidencethreshold - Can represent model uncertainty or ensemble agreement
timestamp
When the signal was generated, used for tracking signal freshness.Signal Constructors
buy
sell
neutral
Signal Methods
is_buy
true if the signal direction is positive (buy).
is_sell
true if the signal direction is negative (sell).
is_neutral
true if the signal direction is zero (neutral).
side
Some(Side::Buy)for buy signalsSome(Side::Sell)for sell signalsNonefor neutral signals
SignalConfig
Configuration for signal-based trading strategies.Configuration Parameters
min_confidence
Minimum confidence threshold for acting on signals. Signals below this threshold are ignored. Default:0.55 (55%)
Example:
min_magnitude
Minimum prediction magnitude required. Can filter out weak predictions. Default:0.001
Note: Currently not actively used in the base implementation but available for custom strategies.
confidence_scaling
Whether to scale position size based on signal strength. Default:true
Behavior:
true: Order size =base_size * signal.strengthfalse: Order size =base_size(constant)
max_position_size
Maximum position size as a fraction. Currently defined but not actively enforced in base implementation. Default:1.0
target_ticks
Target profit level in ticks for take-profit orders. Default:10
Note: Available for use in custom strategies or profit-taking logic.
stop_ticks
Stop loss level in ticks for risk management. Default:5
Note: Available for use in custom strategies or stop-loss logic.
Default Configuration
SignalStrategy
A strategy that trades based on external signals.Constructor
new
name: Strategy identifierinstrument_id: ID of the instrument to tradesignal_config: Signal configurationorder_size: Base order size in contractsmax_position: Maximum absolute position allowedtick_value: Value of one tick for P&L calculation
Core Methods
process_signal
- Skip if pending order exists
- Check signal confidence against threshold
- Determine order side from signal direction
- Calculate order size (respecting position limits)
- Generate IOC (Immediate-Or-Cancel) order
- Record as pending order
calculate_order_size
- Apply confidence scaling if enabled:
- Calculate remaining capacity:
- For buy:
max_position - current_position - For sell:
max_position + current_position
- For buy:
- Return minimum of calculated size and remaining capacity
last_signal
Strategy Implementation
TheSignalStrategy implements the Strategy trait:
on_market_data
file:///home/daytona/workspace/source/crates/nano-strategy/src/signals.rs:248-251 Updates base strategy but doesn’t generate orders. Signals must be provided externally viaprocess_signal().
on_fill
file:///home/daytona/workspace/source/crates/nano-strategy/src/signals.rs:253-259 Handles fill events:- Updates position and P&L via base strategy
- Clears pending order if the fill matches
on_order_reject / on_order_cancel
file:///home/daytona/workspace/source/crates/nano-strategy/src/signals.rs:263-273 Clears pending order tracking when orders are rejected or cancelled.Usage Patterns
Integration with ML Models
Multiple Signal Sources
Risk Management
Signal Interpretation
Confidence vs Strength
Confidence:- How certain is the model about its prediction?
- Used as a gate: signals below
min_confidenceare rejected - Represents model reliability or uncertainty
- How strong is the predicted move?
- Used for position sizing when
confidence_scaling = true - Represents magnitude of expected price movement
Direction Values
| Direction | Meaning | Use Case |
|---|---|---|
| +1 | Buy | Expect price increase |
| 0 | Neutral | Uncertain or no clear signal |
| -1 | Sell | Expect price decrease |
Complete Example
See Also
- BaseStrategy - Base strategy implementation
- MarketMakerStrategy - Market-making strategy
- Strategy Trait - Core strategy interface