Condition

[[condition]] is a conditional block that evaluates the condition expression each time the strategy reaches it.

The expression is interpreted as a boolean: 0.0 and NaN are false, and any other non-zero value is true.

When the expression is true, execution jumps to the block referenced by next_block_id. When the expression is false, the block is not validated on that candle. The strategy stays on the same [[condition]] block and evaluates it again on the next candle.

[[condition]] is the generic conditional block. Blocks such as [[trend]], [[threshold]], and [[position]] can often be rewritten with a [[condition]] block that states the intended comparison explicitly.

Block declaration

A strategy can contain multiple [[condition]] blocks.

Examples

Minimal standalone condition

This example shows the smallest valid standalone [[condition]] block. The strategy moves to open_long only when close > ema_200 evaluates to true.

[[condition]]
id            = "entry_filter"
condition     = "close > ema_200"
next_block_id = "open_long"

Manual crossover with history indexing

This example reproduces a bullish crossover pattern manually by comparing the current bar and the previous bar with [1].

[[condition]]
id            = "golden_cross"
condition     = "fast > slow and fast[1] <= slow[1]"
next_block_id = "buy"

Condition on position state

This example checks a runtime position variable. The block validates only when no open trade remains (opentrades == 0).

[[condition]]
id            = "exit_filled"
condition     = "opentrades == 0"
next_block_id = "golden_cross"

Child condition inside [[and]]

This example shows two child [[condition]] blocks evaluated by a parent [[and]] block. Child conditions do not define next_block_id; flow is controlled by the parent [[and]].

[[and]]
id            = "entry_filters"
conditions    = ["trend_ok", "volatility_ok"]
next_block_id = "open_long"

[[condition]]
id        = "trend_ok"
condition = "close > ema_200"

[[condition]]
id        = "volatility_ok"
condition = "atr_14 > atr_min"

Block parameters

ParameterDescription
id
 Text
 Required
Unique identifier of the block.
condition
 Expression
 Required
Condition expression evaluated on every candle. A value equal to 0.0 or NaN is false, any other non-zero value is true.
next_block_id
 Text
 Conditional
Required when the [[condition]] block is used on its own. Must be omitted when it is used as a child of an [[and]] or [[or]] block.

This block does not produce any output variable; it only controls the execution flow.