Logic Block — “Decide When Conditions Are Met”
The Logic Block is the brain of a trading algorithm. It evaluates indicator outputs and predefined rules to decide whether to generate a signal.
Core Purpose
- Evaluate Rules: Applies IF/THEN logic to indicator data (e.g., IF Indicator X > Threshold).
- Combine Conditions: Uses Boolean logic (AND / OR) to filter out noise.
- Signal Production: Outputs definitive actions: Buy, Sell, or Hold.
- Safety: Ensures actions occur only within strictly defined market environments.
Design Principle: Keep decision logic separate from execution. This ensures strategies remain transparent, testable, and safe from “blind execution.”
1. Logical & Comparison Actions
1.1 Crossover Logic (State Change Events)
Crossovers are used to detect transitions. They trigger at the exact moment a relationship between two values changes.
- Crosses Above: Triggers when a value moves from below to above another value.
- Example: RSI crosses above 50.
- Crosses Below: Triggers when a value moves from above to below another value.
- Example: EMA(9) crosses below EMA(21).
[Image of a Golden Cross and Death Cross showing moving average crossovers]
1.2 Relative Position Logic (Current State)
Unlike crossovers, these evaluate the current environment rather than the transition.
| Logic Type | Condition | Example Case |
|---|---|---|
| Above | Value > Reference | Price is currently above the VWAP. |
| Below | Value < Reference | Price is currently below the SMA(200). |
| Equal To | Value == Reference | Indicator value equals exactly zero. |
1.3 Threshold Comparison Logic (Boundaries)
Used to define overbought/oversold regions or volume spikes.
- Higher Than: True when a value exceeds a defined threshold (e.g., RSI > 70).
- Higher Than Equal To: Includes the threshold value (e.g., Volume ≥ Average Volume).
- Lower Than: True when a value is below a threshold (e.g., ATR < 1.5).
- Lower Than Equal To: True when a value is at or below a boundary (e.g., Stochastic ≤ 20).
1.4 Change-Magnitude Logic
This measures the amount of movement rather than just the direction.
- Up By: True when a value has moved upward by a specific unit or percentage.
- Example: Price is up by 2%.
- Down By: True when a value has moved downward by a specific unit or percentage.
- Example: Stock is down by $10.
1.5 Delta / Rate-of-Change Logic
Used to detect incremental changes between consecutive periods (Candle A vs. Candle B).
- Increases By: True when a value grows by a defined delta over the prior value.
- Example: Volume increases by 30% from the previous candle.
- Decreases By: True when a value drops by a defined delta over the prior value.
- Example: RSI decreases by 5 points.
2. Combining Logic (Boolean Operators)
To build a robust strategy, individual logic blocks are typically chained together:
- AND (All must be true):
(RSI < 30) AND (Price Crosses Above SMA20). - OR (Any can be true):
(Price Down By 5%) OR (Stop Loss Triggered). - NOT (Inversion):
NOT (Market is Choppy).