Automated Trading Strategies Suite
Assembly:
TraderJan.Strategies.dll
Source Files:TJ Alpha Strategy.cs,Options Strategy.cs
Framework: ATAS Native C# Strategy Engine (ATAS.Indicators.Technical.Strategy)
🟢 Part 1: Layman & Trader Guide
1. What are Trader-Jan Strategies?
Trader-Jan Strategies are fully automated execution robots that run directly inside the ATAS platform. While indicators only draw lines, arrows, and statistics on the chart, strategies have the authority to: * Submit live market, limit, and stop orders to your broker or prop firm account (Apex, Topstep, Tradovate, Rithmic, Interactive Brokers). * Manage open trades with sub-millisecond precision. * Automatically close positions when daily loss limits or time rules are reached.
2. Supported Strategy Types
- TJ Alpha Strategy (Engine A):
- Trades automated price-action reversals and breakouts derived from order flow delta and wick rejections.
- Options Strategy (Engine B):
- Trades automated gamma wall sweeps and magnet drift setups derived from institutional options flow.
3. How Order Execution Works (ATM Brackets)
When a valid signal triggers on the chart, the strategy manages the trade following strict rules: * Immediate Entry: Submits an order at the market or limit price. * Automatic OCO Bracket: The exact moment your entry fills, the strategy immediately submits two linked orders: * A Take Profit (TP) limit order at your target price. * A Stop Loss (SL) stop order to protect against adverse moves. * One-Cancels-Other (OCO): If your profit target is reached, the stop loss is automatically cancelled (and vice-versa). * Two-Stage Breakeven: Once the trade reaches your first profit milestone (e.g., +15 ticks), the stop loss order is automatically moved up to your entry price + 1 tick to guarantee a risk-free trade. * Trailing Stop: If configured, the stop ratchets tighter behind price as the trade moves further into profit.
4. Prop Firm Safety & Account Protection
Designed specifically for prop trading evaluations and live funded accounts, the strategies feature hard protective gates: * Daily Loss Limit Circuit Breaker: If your cumulative losses on the day reach your threshold (e.g. -$450), the strategy flattens any open position and refuses to enter any new trades until 17:00 CT. * Session Close Auto-Flatten: Never hold contracts into the CME electronic session break or weekend. The strategy automatically exits positions before the 16:00 / 17:00 CT boundary. * Pre-Trade Risk Clamp: If a setup requires a stop loss wider than your maximum allowed loss per trade, the order is blocked before submission.
💻 Part 2: Expert & Developer Specification
1. State Machine Architecture & Order Lifecycle
The strategy execution engine operates as a deterministic, asynchronous finite state machine (FSM):
stateDiagram-v2
[*] --> Idle
Idle --> PendingEntry: Signal Received & Risk Gates Pass
PendingEntry --> Filled: OnOrderChanged (Filled)
PendingEntry --> Idle: Order Canceled / Timed Out
Filled --> ManagingBrackets: OCO Bracket Submitted
ManagingBrackets --> BreakevenRatcheted: Profit >= BreakevenTrigger
BreakevenRatcheted --> TrailingRatcheted: Price advances by TrailingStep
ManagingBrackets --> Closed: TP Hit or SL Hit
BreakevenRatcheted --> Closed: Exit Order Filled
TrailingRatcheted --> Closed: Exit Order Filled
ManagingBrackets --> Flattened: Daily Circuit Breaker / Session End
Closed --> Idle: Clean State & Reset
Flattened --> Halted: Locked Until 17:00 CT
2. Dual Operation Modes: Bus Listener vs Internal Calculation
Trader-Jan strategies support two architectural operational modes:
1. Indicator Bus Listener Mode (UseIndicatorBus = true):
* Strategy scans the host chart for an active instance of Alpha Signal or Options Signal.
* Directly subscribes to the 9-series DataSeries unmanaged bus.
* Zero redundant calculations: chart visualizer computes mathematics, strategy focuses exclusively on low-latency order execution.
2. Autonomous Headless Mode (UseIndicatorBus = false):
* Strategy instantiates internal signal calculation engines (PnLSimulator, GexEngine).
* Operates completely independently of chart rendering for headless backtesting or background execution.
3. ATAS Event Handlers & Concurrency Contracts
Strategies inherit from ATAS Strategy base class and bind to native lifecycle hooks:
* OnCalculate(int bar, decimal value): Evaluates signal bar completions, checks clock time constraints against CME 17:00 CT rollover, and updates intra-bar trailing stops.
* OnOrderChanged(Order order): Tracks order state transitions (Pending, Filled, Cancelled). Employs lock-guarded ID mappings to match broker IDs against internal trade structures.
* OnTradeChanged(MyTrade trade): Ingests fill price, executed volume, and broker commission. Computes realized mark-to-market PnL and updates daily circuit breakers.
4. Race Condition & Slippage Mitigation
To ensure bit-perfect synchronization with the Python backtester under live market conditions: * Adverse Fill Model: Strategies account for tick-level slippage when evaluating bracket distances. * Stop-Loss Execution Priority: In high-volatility bars where both TP and SL price thresholds are breached simultaneously, the execution harness always yields priority to the protective stop order.