models
Trading Logic
Building Your Trading Algorithm
The first step in creating a trading algorithm is defining its logic – the rules that determine when to enter and exit trades. Spectral Alpha's Model Builder simplifies this process by dividing the logic into distinct sections, aligning with development best practices.
Step-by-Step Approach:
We recommend building your algorithms incrementally, validating each step as you go. This allows you to systematically refine your logic and avoid unnecessary complexity.
Logic Sections:
- Signal: Generates trading signals based on market conditions and indicator values.
- Filter: Defines conditions under which trading should be avoided to prevent losses during unfavorable market periods.
- Stops: Adds fixed stop-loss orders to protect your capital.
- Trailing Stops: Implements dynamic stop-loss orders that trail the price action.
- Risk: Manages the risk of open trades with features like breakeven stops and profit locking.
- Phantom: (Coming soon) Controls how the algorithm manages drawdowns internally.
Signal
The Signal section defines the logic for generating trading signals. You can use multiple signals for a single trading action, combining them with AND/OR logic.
Trading Actions
Each action has a Long/Short/Both setting for precise control:
- Long/Short: Enter a long or short position, closing any opposing positions.
- Exit: Exit all trades, or specifically long or short trades.
- Reverse: Flip an existing long/short position.
- Stay: Maintain the current position (useful for training continuous signal logic).
- Scale In/Out: Partially enter or exit positions.
Trigger Logic
Add multiple rules to an action using AND/OR logic. This allows you to create complex conditions for generating signals.
Source
Select the data series to analyze for trading logic:
- Indicator Series: Use indicator values or levels (e.g., crossovers).
- Market Series: Use market data like Open, High, Low, Close.
- Trade Series: Analyze trade-specific data like lifetime, risk/reward (requires Stops).
Conditions
Choose from a variety of conditions to define your trading logic, such as:
- Crossover: One series crosses above/below another.
- Above/Below: A series is above/below a specific value or another series.
- Equals/Not Equals: A series equals/does not equal a specific value.
Filter
Similar to the Signal section, but with actions designed for continuous conditions (e.g., price above the 200-day SMA).
Filter Actions
- Open All New (Long/Short): Allow new trades when the logic is true.
- Skip All New (Long/Short): Prevent new trades when the logic is true.
Stops
This section defines how the volatility-based stop-loss is calculated (e.g., using the Average True Range).
- Multiple: Controls the factor applied to the indicator value (e.g., a multiple of 2 would set the stop-loss at 2 times the ATR).
Trailing Stops
Trailing stops dynamically adjust the stop-loss level to trail the price action, potentially locking in profits and reducing losses.
Simple
- Slope: Adjusts how much the stop-loss moves with each new high/low (a value less than 1 results in a slower trailing stop).
- Step: Trails the stop-loss by a fixed fraction of the distance between the current stop level and the price at every bar.
Advanced
- Offset: Requires the price to move a certain distance into profit before activating the trailing stop.
- Speed: Increases the trailing speed before the breakeven level is reached.
- Lock: Locks in a percentage of open profit or raises the stop-loss to breakeven once the offset is reached.
Risk
Dynamically adjust the behavior of open trade stops based on algorithm events.
Trigger Logic
Trigger events based on:
- Indicator crossovers
- Market data reaching certain levels
- Trade-specific events (duration, risk/reward)
Stop Config
Override the default stop configurations when the logic is triggered.
Example Use Cases
- Cycles: Set the stop-loss to breakeven when a cycle indicator crosses its midpoint.
- Trend Following: Use a wide stop initially, then trail aggressively before breakeven and more conservatively afterward.
Phantom Trading
(Coming Soon) Implement advanced drawdown management techniques like equity curve trading.