Decoded Intelligence Signal

Signal Logic

advanced
strategy
4 min read
410 words

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

Signal logic is the code layer where a trading strategy's decision rules are expressed as Python conditional statements. It is the direct algorithmic translation of a strategy's TSA Components 3 (Entry Trigger) and 6 (Exit Rules) into executable code — taking indicator values and price data from the DataFrame and determining whether trade entry or exit conditions are currently satisfied. In J21's RSI Signal Bot, signal logic lives in `signal_logic.py` and consists of three primary functions. The `market_condition_met(row)` function checks TSA Component 2 — whether the broader market condition filter is satisfied. The `entry_signal(df, i)` function checks whether entry conditions are met at candle i: market condition satisfied, a breakout above the prior candle's high, and RSI below the overbought threshold. The `exit_signal(row, entry_price, stop_price)` function checks whether exit conditions are met: target reached, SuperTrend flip, or stop-loss triggered. The critical characteristic of well-written signal logic is its stateless nature. Signal logic functions receive the current row's data as input and return a boolean — true or false. They hold no memory between calls, modify no external state, and produce the same output for the same inputs every time. This stateless design makes signal logic independently testable: every function can be verified with isolated tests before the full bot runs. Position state management — tracking whether the bot is in a position and at what entry price — is handled separately by the position state dictionary in the main loop, not within the signal logic functions. This separation is architectural: signal logic answers 'should a trade action happen now?', position management answers 'what are the financial parameters of that action?'

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

Common Misconception

Signal logic only handles entry signals — exit logic is managed by the position manager module.

Technical Reality

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.

Common Misconception

More complex signal logic with many conditions always produces more reliable trading signals.

Technical Reality

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.

Common Misconception

Signal logic bugs are always obvious — they produce clearly wrong trades immediately identifiable in backtesting.

Technical Reality

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.

Related Terms

Compare Adjacent Terms

Access Pro Research Infrastructure

Deciphering Signal Logic is just the first step. Apply for the Q3 2026 Beta to gain direct access to our 8-agent intelligence pipeline.