Signal Logic
Published Last updated
Key Takeaway
Signal logic is the conditional code in a trading bot that evaluates indicator values and price conditions to determine when entry and exit signals are generated during each execution cycle.
Learn These First
What Is Signal Logic?
Signal logic is the conditional code in a trading bot that evaluates indicator values and price conditions to determine when entry and exit signals are generated during each execution cycle.
How Signal Logic Works
Frequently Asked Questions
What is signal logic in a trading bot and how does it work?
Signal logic is the conditional code that decides when the bot should enter or exit a trade. On each execution cycle, the bot passes the current candle's data — including all computed indicator values — to the signal logic functions. These functions evaluate whether the conditions in the strategy's entry and exit rules are all simultaneously satisfied. If the entry function returns true and the bot is not in a position, a trade entry is recorded or executed. If the exit function returns true while the bot holds a position, the trade is closed. Signal logic is the strategy's decision rules translated into executable code.
How does signal logic translate a TSA strategy specification into Python code?
TSA Component 3 (Entry Trigger) and Component 6 (Exit Rules) map directly to signal logic functions. Each condition in the TSA is expressed as a Python comparison on a DataFrame row value: 'SuperTrend is bullish' becomes `row['supertrend_direction'] == 1`. 'RSI below overbought' becomes `row['RSI_14'] < 70`. Multiple conditions are combined using Python's `and` operator. The entry signal function returns `True` only when every condition is simultaneously met. This translation is the core ADL Phase 1 task — converting qualitative strategy language into unambiguous, computable boolean expressions Python can evaluate precisely.
Why is signal logic kept separate from position state management in J21's bot architecture?
Signal logic and position state management are separated because they have fundamentally different responsibilities. Signal logic is stateless — it evaluates conditions on a single row and returns true or false with no memory of previous calls. Position state management is stateful — it tracks whether the bot holds a position, at what entry price, and with what stop loss, persisting across multiple candle evaluations. Mixing these in one module creates functions with hidden dependencies that are harder to test and debug independently. Separation ensures each module can be verified and updated in isolation without introducing unexpected side effects.
Common Misconceptions About Signal Logic
Signal logic only handles entry signals — exit logic is managed by the position manager module.
Both entry and exit signals are part of signal logic, not the position manager. Signal logic determines when conditions are met for entering and exiting trades based on indicator values and price levels. The position manager handles the financial consequences of those signals — calculating position size, recording entry and exit prices, tracking P&L, and enforcing the daily loss limit. Signal logic answers 'should a trade action happen now?', while position management answers 'what are the financial parameters of that action?' Both are required; neither replaces the other in J21's bot architecture.
More complex signal logic with many conditions always produces more reliable trading signals.
Additional conditions reduce signal frequency but do not inherently improve signal quality. Each condition added requires the market to satisfy one more simultaneous requirement — and some conditions may be correlated, providing redundant rather than independent confirmation. Overly complex signal logic also reduces qualifying trades in backtesting, reducing statistical significance and making it difficult to determine whether the strategy's edge is real. Professional algorithmic traders prefer simple, robust signal logic with two to four clear conditions over multi-condition logic that barely fires in backtesting and performs unpredictably in live market conditions.
Signal logic bugs are always obvious — they produce clearly wrong trades immediately identifiable in backtesting.
Signal logic bugs are frequently subtle and detectable only through systematic log review. A common off-by-one error — using `df.iloc[i]` instead of `df.iloc[i-1]` for the previous candle comparison — fires entries one candle too late, producing different fill prices but still generating plausible-looking trades. A condition using `>=` where the specification requires `>` admits one additional trade category that appears normal in most cases. These bugs produce small but systematic performance differences from the intended strategy — detectable through indicator value verification against platform charts and paper trading log analysis.