add_ruleSave a typed condition and attach it as an entry, exit or gate rule in one call.
Area
Strategy Builder
Group
Authoring
Access
Write
Risk
May change server state
Details
Full description
Details
Save a condition and attach it as a rule in one call.
Does what builder_add_condition followed by builder_attach_rule does, and checks everything both would check before saving anything: a refused call leaves no definition and no rule behind. Use builder_add_condition, builder_compose and builder_attach_rule instead to reuse one saved definition in several rules or to combine saved definitions.
Roles: entry (requires direction 'long' or 'short'), exit (optional direction and size_frac), gate (blocks entries while false). A stop, target or trailing stop belongs in an exit rule, not an entry or gate.
Entry rules on the SAME side are ANDed on the same bar. Express alternatives inside one any_of condition. Long/short groups are alternatives; simultaneous signals place no entry. Position policy controls repeated entries and reversal while invested.
Start with builder_discover(action='quickstart') for a complete example. overview lists the complete grammar and units; get supplies exact primitive detail. Inline sequence/Boolean children need no separate save/compose calls. The complete machine-readable schema is action='specification'.
Returns definition_id, rule_id, name, source, source_version and description. Use rule_id for builder_detach_rule.
Capabilities
Bounded options and operating modes surfaced above the full JSON schema.
Role options
role
entryexitgateRequired Inputs
conditionobjectTyped condition source with a "kind" discriminator. Read builder_discover(action='overview') once for the complete language; use action='get' for exact detail. Combinators may hold inline conditions or condition_ref children.roleenum: entry, exit, gateRule role: entry, exit, or gate (block entries)strategy_idstringStrategy IDOptional Inputs
directionanyOf (2 variants)Entry role: required ('long' or 'short'). Exit role: optionally scope the exit to that position direction; None means BOTH long and short. Not used for gates.nameanyOf (2 variants)Optional strategy-scoped definition name (snake_case, at most 48 chars, leading letter, unique within the strategy). Auto-generated if omitted.remainder_unprotectedanyOf (2 variants)Exit role: explicit consent to leave a partial stop's remainder unprotected. Otherwise another exit must cover the remainder.scan_run_idanyOf (2 variants)Optional ID of the signal scan run that validated this condition.size_fracanyOf (2 variants)Exit role: fraction to close, greater than 0 through 1. None = full close.