Skip to main content
Skip to main content
Version: Next 🚧

Entry Conditions Schema

This document provides the complete schema reference for the entryConditions configuration object. Entry conditions define when the algorithm should open new trading positions.

Overview

Entry conditions are Step 3 of algorithm configuration. They control:

  • Position type (long, short, or both)
  • Logical combination of conditions (AND/OR)
  • Individual condition rules
  • Confirmation requirements
  • Time filters
  • Re-entry settings

Schema Structure

interface EntryConditions {
positionType: 'long' | 'short' | 'both'
logicalOperator: 'AND' | 'OR'
confirmationCandles: number
conditions: Condition[]
candlestickPatterns?: CandlestickPattern[]
timeFilters?: TimeFilters
reEntry?: ReEntrySettings
multiTimeframe?: MultiTimeframeConfig
}

Core Fields

positionType

  • Type: enum
  • Required: Yes
  • Values:
    • long - Only open long (buy) positions
    • short - Only open short (sell) positions
    • both - Open both long and short positions
  • Example: "both"

Use Cases:

  • long - Bullish strategies, trending up markets
  • short - Bearish strategies, trending down markets
  • both - Neutral strategies, range-bound markets

logicalOperator

  • Type: enum
  • Required: Yes
  • Values:
    • AND - All conditions must be true
    • OR - At least one condition must be true
  • Example: "AND"

Truth Tables:

AND Logic:

Condition 1Condition 2Result
TrueTrue✅ Enter
TrueFalse❌ No Entry
FalseTrue❌ No Entry
FalseFalse❌ No Entry

OR Logic:

Condition 1Condition 2Result
TrueTrue✅ Enter
TrueFalse✅ Enter
FalseTrue✅ Enter
FalseFalse❌ No Entry

confirmationCandles

  • Type: number
  • Required: Yes
  • Range: 0 to 10
  • Description: Number of candles condition must remain true before entry
  • Default: 0 (immediate entry)
  • Example: 1

Purpose: Reduces false signals by requiring conditions to persist.

Trade-off:

  • Higher value = Fewer false signals, but delayed entries
  • Lower value = Faster entries, but more false signals

Example:

{
"confirmationCandles": 2
}

Condition must be true for 2 consecutive candles before entering.

conditions

  • Type: Condition[]
  • Required: Yes
  • Minimum: 1 condition
  • Description: Array of condition rules that generate entry signals
  • See: Condition Types

Condition Types

There are three types of conditions:

1. Indicator vs Value

Compare an indicator to a fixed value.

interface IndicatorValueCondition {
type: 'indicator_value'
indicator: Indicator
operator: ComparisonOperator
value: number
}

Example:

{
"type": "indicator_value",
"indicator": {
"type": "RSI",
"period": 14
},
"operator": "above",
"value": 50
}

Enters when RSI(14) is above 50.

2. Indicator vs Indicator

Compare two indicators.

interface IndicatorIndicatorCondition {
type: 'indicator_indicator'
indicator1: Indicator
operator: ComparisonOperator
indicator2: Indicator
}

Example:

{
"type": "indicator_indicator",
"indicator1": {
"type": "EMA",
"period": 9
},
"operator": "crosses_above",
"indicator2": {
"type": "EMA",
"period": 21
}
}

Enters when EMA(9) crosses above EMA(21).

3. Price vs Indicator

Compare price to an indicator.

interface PriceIndicatorCondition {
type: 'price_indicator'
priceType: 'open' | 'high' | 'low' | 'close'
operator: ComparisonOperator
indicator: Indicator
}

Example:

{
"type": "price_indicator",
"priceType": "close",
"operator": "above",
"indicator": {
"type": "SMA",
"period": 200
}
}

Enters when close price is above SMA(200).

Indicator Structure

interface Indicator {
type: IndicatorType
period?: number
// Indicator-specific parameters
fastPeriod?: number // MACD
slowPeriod?: number // MACD
signalPeriod?: number // MACD
stdDev?: number // Bollinger Bands
kPeriod?: number // Stochastic
dPeriod?: number // Stochastic
}

Supported Indicators

Moving Averages

  • SMA - Simple Moving Average
    • Parameters: period (5-200)
  • EMA - Exponential Moving Average
    • Parameters: period (5-200)
  • WMA - Weighted Moving Average
    • Parameters: period (5-200)

Momentum Indicators

  • RSI - Relative Strength Index
    • Parameters: period (5-50, default 14)
  • Stochastic - Stochastic Oscillator
    • Parameters: kPeriod (5-50, default 14), dPeriod (3-10, default 3)
  • CCI - Commodity Channel Index
    • Parameters: period (5-50, default 20)

Trend Indicators

  • MACD - Moving Average Convergence Divergence
    • Parameters: fastPeriod (5-50, default 12), slowPeriod (10-100, default 26), signalPeriod (5-20, default 9)
  • ADX - Average Directional Index
    • Parameters: period (5-50, default 14)
  • ParabolicSAR - Parabolic Stop and Reverse
    • Parameters: acceleration (0.01-0.1, default 0.02), maximum (0.1-0.5, default 0.2)

Volatility Indicators

  • BollingerBands - Bollinger Bands
    • Parameters: period (10-50, default 20), stdDev (1-3, default 2)
  • ATR - Average True Range
    • Parameters: period (5-50, default 14)
  • KeltnerChannels - Keltner Channels
    • Parameters: period (10-50, default 20), atrPeriod (5-50, default 10)

Volume Indicators

  • Volume - Trading Volume
    • No parameters
  • OBV - On-Balance Volume
    • No parameters
  • VWAP - Volume Weighted Average Price
    • No parameters

Comparison Operators

operator

  • Type: enum
  • Required: Yes
  • Values:
    • above - Greater than
    • below - Less than
    • equals - Equal to (with tolerance)
    • crosses_above - Crosses from below to above
    • crosses_below - Crosses from above to below
    • greater_than_equal - Greater than or equal
    • less_than_equal - Less than or equal

Cross Detection

Crossover operators require previous candle data:

crosses_above:

Previous: value1 <= value2
Current: value1 > value2

crosses_below:

Previous: value1 >= value2
Current: value1 < value2

Candlestick Patterns

Optional array of candlestick patterns to detect.

interface CandlestickPattern {
pattern: PatternType
direction?: 'bullish' | 'bearish' | 'any'
}

Supported Patterns

Single-Candle Patterns

  • hammer - Bullish reversal (long lower wick)
  • shooting_star - Bearish reversal (long upper wick)
  • doji - Indecision (very small body)
  • marubozu - Strong trend (no wicks)
  • spinning_top - Indecision (small body, wicks both sides)

Two-Candle Patterns

  • bullish_engulfing - Bullish reversal
  • bearish_engulfing - Bearish reversal

Three-Candle Patterns

  • morning_star - Bullish reversal
  • evening_star - Bearish reversal

Example:

{
"candlestickPatterns": [
{
"pattern": "hammer",
"direction": "bullish"
},
{
"pattern": "bullish_engulfing"
}
]
}

Time Filters

Optional time-based filtering for entries.

interface TimeFilters {
tradingHours?: {
start: string // HH:MM format
end: string // HH:MM format
}
tradingDays?: string[] // ['monday', 'tuesday', ...]
timezone?: string // IANA timezone
}

tradingHours

  • Type: object
  • Required: No
  • Description: Restrict trading to specific hours
  • Format: 24-hour time (HH:MM)

Example:

{
"tradingHours": {
"start": "09:30",
"end": "15:00"
}
}

Only enter trades between 9:30 AM and 3:00 PM.

tradingDays

  • Type: string[]
  • Required: No
  • Values: monday, tuesday, wednesday, thursday, friday, saturday, sunday
  • Description: Days of week to allow trading

Example:

{
"tradingDays": ["monday", "tuesday", "wednesday", "thursday", "friday"]
}

Only trade on weekdays.

timezone

  • Type: string
  • Required: No
  • Default: "Asia/Kolkata"
  • Description: IANA timezone for time filters
  • Example: "Asia/Kolkata"

Re-Entry Settings

Optional settings to control re-entering after exits.

interface ReEntrySettings {
cooldownMinutes: number // 0 to 1440
maxReEntries: number // 0 to 10
}

cooldownMinutes

  • Type: number
  • Required: Yes (if reEntry is defined)
  • Range: 0 to 1440 (24 hours)
  • Description: Minutes to wait after exit before re-entering
  • Example: 30

maxReEntries

  • Type: number
  • Required: Yes (if reEntry is defined)
  • Range: 0 to 10
  • Description: Maximum number of re-entries for same symbol in same day
  • Example: 3

Example:

{
"reEntry": {
"cooldownMinutes": 30,
"maxReEntries": 3
}
}

Wait 30 minutes after exit, maximum 3 re-entries per day.

Multi-Timeframe Configuration

Optional higher timeframe confirmation.

interface MultiTimeframeConfig {
enabled: boolean
higherTimeframe: Timeframe
conditions: Condition[]
confirmationRequired: boolean
onMisalignment: 'skip_entry' | 'alert_only' | 'enter_anyway'
}

enabled

  • Type: boolean
  • Required: Yes
  • Description: Whether multi-timeframe analysis is enabled
  • Example: true

higherTimeframe

  • Type: enum
  • Required: Yes (if enabled is true)
  • Values: 5m, 15m, 30m, 1h, 2h, 4h, 1d, 1w
  • Description: Higher timeframe for confirmation
  • Example: "1h"

conditions

  • Type: Condition[]
  • Required: Yes (if enabled is true)
  • Description: Conditions to check on higher timeframe
  • See: Condition Types

confirmationRequired

  • Type: boolean
  • Required: Yes (if enabled is true)
  • Description: Whether higher timeframe must confirm
  • Example: true

onMisalignment

  • Type: enum
  • Required: Yes (if enabled is true)
  • Values:
    • skip_entry - Don't enter if timeframes disagree
    • alert_only - Enter but send alert
    • enter_anyway - Enter regardless
  • Example: "skip_entry"

Example:

{
"multiTimeframe": {
"enabled": true,
"higherTimeframe": "1h",
"conditions": [
{
"type": "indicator_value",
"indicator": {
"type": "EMA",
"period": 50
},
"operator": "above",
"value": 0
}
],
"confirmationRequired": true,
"onMisalignment": "skip_entry"
}
}

Complete Examples

Simple RSI Strategy

{
"positionType": "long",
"logicalOperator": "AND",
"confirmationCandles": 0,
"conditions": [
{
"type": "indicator_value",
"indicator": {
"type": "RSI",
"period": 14
},
"operator": "below",
"value": 30
}
]
}

EMA Crossover with Volume

{
"positionType": "both",
"logicalOperator": "AND",
"confirmationCandles": 1,
"conditions": [
{
"type": "indicator_indicator",
"indicator1": {
"type": "EMA",
"period": 9
},
"operator": "crosses_above",
"indicator2": {
"type": "EMA",
"period": 21
}
},
{
"type": "indicator_indicator",
"indicator1": {
"type": "Volume"
},
"operator": "above",
"indicator2": {
"type": "SMA",
"period": 20
}
}
]
}

Multi-Condition with Time Filter

{
"positionType": "long",
"logicalOperator": "AND",
"confirmationCandles": 2,
"conditions": [
{
"type": "price_indicator",
"priceType": "close",
"operator": "above",
"indicator": {
"type": "SMA",
"period": 200
}
},
{
"type": "indicator_value",
"indicator": {
"type": "RSI",
"period": 14
},
"operator": "above",
"value": 50
},
{
"type": "indicator_value",
"indicator": {
"type": "MACD",
"fastPeriod": 12,
"slowPeriod": 26,
"signalPeriod": 9
},
"operator": "above",
"value": 0
}
],
"timeFilters": {
"tradingHours": {
"start": "09:30",
"end": "15:00"
},
"tradingDays": ["monday", "tuesday", "wednesday", "thursday", "friday"]
}
}

Multi-Timeframe Strategy

{
"positionType": "both",
"logicalOperator": "AND",
"confirmationCandles": 1,
"conditions": [
{
"type": "indicator_indicator",
"indicator1": {
"type": "EMA",
"period": 9
},
"operator": "crosses_above",
"indicator2": {
"type": "EMA",
"period": 21
}
}
],
"multiTimeframe": {
"enabled": true,
"higherTimeframe": "1h",
"conditions": [
{
"type": "indicator_value",
"indicator": {
"type": "ADX",
"period": 14
},
"operator": "above",
"value": 25
}
],
"confirmationRequired": true,
"onMisalignment": "skip_entry"
}
}

Validation Rules

General Rules

  • At least one condition is required
  • All indicator parameters must be within valid ranges
  • Confirmation candles must be between 0 and 10
  • If multiTimeframe is enabled, all multiTimeframe fields are required

Condition Validation

  • Each condition must have all required fields for its type
  • Indicator types must be supported
  • Operators must be valid for the condition type
  • Cross operators require two values to compare

Time Filter Validation

  • Trading hours must be in HH:MM format
  • Start time must be before end time
  • Trading days must be valid day names
  • Timezone must be valid IANA timezone