Comparison Operators Reference
Overview
Comparison operators are used in entry conditions to define relationships between indicators, prices, and values. x3Algo supports 5 primary comparison operators that enable sophisticated signal generation logic.
Operator Types
Static Comparison Operators
above- Greater thanbelow- Less thanequals- Equal togreater_than_equal- Greater than or equal toless_than_equal- Less than or equal to
Dynamic Comparison Operators
crosses_above- Crosses from below to abovecrosses_below- Crosses from above to below
Static Comparison Operators
Above
Description: Checks if the left value is greater than the right value.
Syntax:
{
"operator": "above",
"value": 50
}
Visual Example:
Value
│
80│ ● Current value (above 50)
│
60│
│
50│ ───────── Threshold
│
40│
│
20│
└─────────────────────> Time
Use Cases:
1. Indicator Above Value:
{
"type": "indicator_value",
"indicator": "RSI",
"period": 14,
"operator": "above",
"value": 70
}
Triggers when RSI is above 70 (overbought)
2. Price Above Indicator:
{
"type": "price_indicator",
"priceType": "close",
"indicator": "SMA",
"period": 200,
"operator": "above"
}
Triggers when price is above 200 SMA (bullish trend)
3. Indicator Above Indicator:
{
"type": "indicator_indicator",
"indicator1": "EMA",
"period1": 9,
"indicator2": "EMA",
"period2": 21,
"operator": "above"
}
Triggers when 9 EMA is above 21 EMA (bullish alignment)
Below
Description: Checks if the left value is less than the right value.
Syntax:
{
"operator": "below",
"value": 30
}
Visual Example:
Value
│
50│
│
40│
│
30│ ───────── Threshold
│
20│ ● Current value (below 30)
│
10│
└─────────────────────> Time
Use Cases:
1. Indicator Below Value:
{
"type": "indicator_value",
"indicator": "RSI",
"period": 14,
"operator": "below",
"value": 30
}
Triggers when RSI is below 30 (oversold)
2. Price Below Indicator:
{
"type": "price_indicator",
"priceType": "close",
"indicator": "SMA",
"period": 50,
"operator": "below"
}
Triggers when price is below 50 SMA (bearish trend)
3. Indicator Below Indicator:
{
"type": "indicator_indicator",
"indicator1": "MACD",
"indicator2": "MACD_Signal",
"operator": "below"
}
Triggers when MACD is below signal line (bearish)
Equals
Description: Checks if the left value equals the right value (with small tolerance for floating-point comparison).
Syntax:
{
"operator": "equals",
"value": 0
}
Visual Example:
Value
│
2│
│
1│
│
0│ ─────●─── Current value equals threshold
│
-1│
│
-2│
└─────────────────────> Time
Use Cases:
1. Indicator Equals Value:
{
"type": "indicator_value",
"indicator": "MACD",
"operator": "equals",
"value": 0
}
Triggers when MACD equals zero line
2. Stochastic Crossover at Level:
{
"type": "indicator_value",
"indicator": "Stochastic_K",
"period": 14,
"operator": "equals",
"value": 50
}
Triggers when Stochastic K equals 50
Note: Due to floating-point precision, "equals" uses a small tolerance (±0.0001). For exact matches, consider using greater_than_equal and less_than_equal together.
Greater Than Equal
Description: Checks if the left value is greater than or equal to the right value.
Syntax:
{
"operator": "greater_than_equal",
"value": 50
}
Visual Example:
Value
│
80│ ● Current value (≥ 50)
│
60│
│
50│ ─────●─── Threshold (inclusive)
│
40│
│
20│
└─────────────────────> Time
Use Cases:
1. Minimum Volume Requirement:
{
"type": "indicator_value",
"indicator": "Volume",
"operator": "greater_than_equal",
"value": 1000000
}
Triggers when volume is at least 1 million
2. ADX Trend Strength:
{
"type": "indicator_value",
"indicator": "ADX",
"period": 14,
"operator": "greater_than_equal",
"value": 25
}
Triggers when ADX is 25 or higher (strong trend)
Less Than Equal
Description: Checks if the left value is less than or equal to the right value.
Syntax:
{
"operator": "less_than_equal",
"value": 30
}
Visual Example:
Value
│
50│
│
40│
│
30│ ─────●─── Threshold (inclusive)
│
20│ ● Current value (≤ 30)
│
10│
└─────────────────────> Time
Use Cases:
1. Maximum ATR Volatility:
{
"type": "indicator_value",
"indicator": "ATR",
"period": 14,
"operator": "less_than_equal",
"value": 2.0
}
Triggers when ATR is 2.0 or lower (low volatility)
2. RSI Not Overbought:
{
"type": "indicator_value",
"indicator": "RSI",
"period": 14,
"operator": "less_than_equal",
"value": 70
}
Triggers when RSI is 70 or lower
Dynamic Comparison Operators
Crosses Above
Description: Detects when a value crosses from below to above another value. Requires previous candle data for comparison.
Detection Algorithm:
Previous Candle: value1 <= value2
Current Candle: value1 > value2
Result: CROSS ABOVE detected
Syntax:
{
"operator": "crosses_above"
}
Visual Example:
Value
│
80│ ● Current (crossed above)
│ /
60│ /
│ /
50│ ──────●──── Threshold
│ /
40│ ● Previous (was below)
│
20│
└─────────────────────> Time
Prev Current
Use Cases:
1. Moving Average Crossover (Golden Cross):
{
"type": "indicator_indicator",
"indicator1": "SMA",
"period1": 50,
"indicator2": "SMA",
"period2": 200,
"operator": "crosses_above"
}
Triggers when 50 SMA crosses above 200 SMA
2. MACD Signal Crossover:
{
"type": "indicator_indicator",
"indicator1": "MACD",
"indicator2": "MACD_Signal",
"operator": "crosses_above"
}
Triggers when MACD crosses above signal line
3. Price Crosses Above Moving Average:
{
"type": "price_indicator",
"priceType": "close",
"indicator": "EMA",
"period": 20,
"operator": "crosses_above"
}
Triggers when price crosses above 20 EMA
4. RSI Crosses Above Oversold:
{
"type": "indicator_value",
"indicator": "RSI",
"period": 14,
"operator": "crosses_above",
"value": 30
}
Triggers when RSI crosses above 30 (exiting oversold)
Important Notes:
- Requires at least 2 candles of data (previous + current)
- Only triggers on the exact candle where the cross occurs
- Does not trigger if value was already above on previous candle
Crosses Below
Description: Detects when a value crosses from above to below another value. Requires previous candle data for comparison.
Detection Algorithm:
Previous Candle: value1 >= value2
Current Candle: value1 < value2
Result: CROSS BELOW detected
Syntax:
{
"operator": "crosses_below"
}
Visual Example:
Value
│
80│ ● Previous (was above)
│ \
60│ \
│ \
50│ ────────●── Threshold
│ \
40│ ● Current (crossed below)
│
20│
└─────────────────────> Time
Prev Current
Use Cases:
1. Moving Average Crossover (Death Cross):
{
"type": "indicator_indicator",
"indicator1": "SMA",
"period1": 50,
"indicator2": "SMA",
"period2": 200,
"operator": "crosses_below"
}
Triggers when 50 SMA crosses below 200 SMA
2. MACD Signal Crossover:
{
"type": "indicator_indicator",
"indicator1": "MACD",
"indicator2": "MACD_Signal",
"operator": "crosses_below"
}
Triggers when MACD crosses below signal line
3. Price Crosses Below Moving Average:
{
"type": "price_indicator",
"priceType": "close",
"indicator": "EMA",
"period": 20,
"operator": "crosses_below"
}
Triggers when price crosses below 20 EMA
4. RSI Crosses Below Overbought:
{
"type": "indicator_value",
"indicator": "RSI",
"period": 14,
"operator": "crosses_below",
"value": 70
}
Triggers when RSI crosses below 70 (exiting overbought)
Important Notes:
- Requires at least 2 candles of data (previous + current)
- Only triggers on the exact candle where the cross occurs
- Does not trigger if value was already below on previous candle
Cross Detection Deep Dive
How Crosses Are Detected
The cross detection algorithm compares the relationship between two values across consecutive candles:
Crosses Above:
// Pseudocode
if (previousCandle.value1 <= previousCandle.value2 &&
currentCandle.value1 > currentCandle.value2) {
return true; // Cross above detected
}
Crosses Below:
// Pseudocode
if (previousCandle.value1 >= previousCandle.value2 &&
currentCandle.value1 < currentCandle.value2) {
return true; // Cross below detected
}
Why Previous Candle Data Matters
Cross detection requires knowing the previous relationship to determine if a cross occurred:
Scenario 1: Valid Cross Above
Prev: value1 = 45, value2 = 50 (45 < 50) ✓ Was below
Curr: value1 = 55, value2 = 50 (55 > 50) ✓ Now above
Result: CROSS ABOVE ✓
Scenario 2: Already Above (No Cross)
Prev: value1 = 55, value2 = 50 (55 > 50) ✗ Already above
Curr: value1 = 60, value2 = 50 (60 > 50) ✓ Still above
Result: NO CROSS ✗
Scenario 3: Equal on Previous (Counts as Cross)
Prev: value1 = 50, value2 = 50 (50 = 50) ✓ Equal counts as "not above"
Curr: value1 = 55, value2 = 50 (55 > 50) ✓ Now above
Result: CROSS ABOVE ✓
Visual Cross Detection Examples
Example 1: EMA Crossover
EMA 9 vs EMA 21
Value
│
110│ ● EMA 9 (current)
│ /│
105│ / │ ← CROSS ABOVE detected here
│ / │
100│ ─────────●──●─ EMA 21
│ /
95│ ● EMA 9 (previous)
│
└─────────────────────> Time
Prev Current
Example 2: Price Crossing Moving Average
Price vs SMA 50
Value
│
155│ ● Price (previous)
│ \
150│ ──────●────●─ SMA 50
│ \ │
145│ \ │ ← CROSS BELOW detected here
│ \ │
140│ ● Price (current)
│
└─────────────────────> Time
Prev Current
Operator Combinations
Multiple Conditions with AND Logic
{
"entryConditions": {
"conditions": [
{
"type": "indicator_indicator",
"indicator1": "EMA",
"period1": 9,
"indicator2": "EMA",
"period2": 21,
"operator": "crosses_above"
},
{
"type": "indicator_value",
"indicator": "RSI",
"period": 14,
"operator": "above",
"value": 50
},
{
"type": "indicator_value",
"indicator": "Volume",
"operator": "greater_than_equal",
"value": 1000000
}
],
"logicalOperator": "AND"
}
}
All three conditions must be true
Multiple Conditions with OR Logic
{
"entryConditions": {
"conditions": [
{
"type": "indicator_value",
"indicator": "RSI",
"period": 14,
"operator": "below",
"value": 30
},
{
"type": "indicator_indicator",
"indicator1": "MACD",
"indicator2": "MACD_Signal",
"operator": "crosses_above"
}
],
"logicalOperator": "OR"
}
}
Either condition can trigger entry
Common Patterns
Trend Following with Crossover
{
"entryConditions": {
"positionType": "long",
"conditions": [
{
"type": "indicator_indicator",
"indicator1": "EMA",
"period1": 12,
"indicator2": "EMA",
"period2": 26,
"operator": "crosses_above"
},
{
"type": "price_indicator",
"priceType": "close",
"indicator": "SMA",
"period": 200,
"operator": "above"
}
],
"logicalOperator": "AND"
}
}
Mean Reversion with Oversold
{
"entryConditions": {
"positionType": "long",
"conditions": [
{
"type": "indicator_value",
"indicator": "RSI",
"period": 14,
"operator": "crosses_above",
"value": 30
},
{
"type": "price_indicator",
"priceType": "close",
"indicator": "Bollinger_Lower",
"period": 20,
"operator": "below"
}
],
"logicalOperator": "AND"
}
}
Breakout with Volume
{
"entryConditions": {
"positionType": "long",
"conditions": [
{
"type": "price_indicator",
"priceType": "close",
"indicator": "SMA",
"period": 20,
"operator": "crosses_above"
},
{
"type": "indicator_value",
"indicator": "Volume",
"operator": "greater_than_equal",
"value": 1500000
}
],
"logicalOperator": "AND"
}
}
Best Practices
1. Use Appropriate Operators for Context
- Trend identification: Use
above/belowfor sustained conditions - Entry signals: Use
crosses_above/crosses_belowfor precise timing - Filters: Use
greater_than_equal/less_than_equalfor thresholds
2. Combine Static and Dynamic Operators
{
"conditions": [
{
"operator": "crosses_above" // Dynamic: precise entry
},
{
"operator": "above" // Static: trend filter
}
]
}
3. Add Confirmation with Multiple Operators
Don't rely on a single cross - add filters:
{
"conditions": [
{
"type": "indicator_indicator",
"indicator1": "MACD",
"indicator2": "MACD_Signal",
"operator": "crosses_above"
},
{
"type": "indicator_value",
"indicator": "MACD",
"operator": "above",
"value": 0
}
],
"logicalOperator": "AND"
}
4. Use Confirmation Candles with Crosses
{
"entryConditions": {
"conditions": [...],
"confirmationCandles": 1
}
}
5. Consider Timeframe
- Lower timeframes (1m-5m): More crosses, more noise
- Higher timeframes (1h-1d): Fewer crosses, more reliable
Common Mistakes to Avoid
- Using crosses without filters - Always add trend or momentum filters
- Confusing
abovewithcrosses_above-aboveis continuous,crosses_aboveis momentary - No confirmation - Use confirmation candles to reduce false signals
- Ignoring previous candle requirement - Crosses need historical data
- Too many cross conditions - Multiple crosses rarely align, use static operators for filters
Operator Quick Reference
| Operator | Symbol | Use Case | Example |
|---|---|---|---|
| above | > | Sustained condition | RSI > 70 |
| below | < | Sustained condition | RSI < 30 |
| equals | = | Exact match | MACD = 0 |
| greater_than_equal | ≥ | Minimum threshold | Volume ≥ 1M |
| less_than_equal | ≤ | Maximum threshold | ATR ≤ 2.0 |
| crosses_above | ↗ | Bullish crossover | EMA 9 crosses above EMA 21 |
| crosses_below | ↘ | Bearish crossover | MACD crosses below signal |