Appearance

Personalize your experience

Mode
Accent Color
Direction
Strategy DSL — Execution Model

Strategy DSL — Execution Model

Reference

What the engine does on every bar: protective exits, exit signals, entries, layers and re-entries, sizing and costs, and where every statistic in the result comes from. Backtests and live strategies run this same code.

One bar at a time

Before the first bar the engine computes every series the references over the whole history (each distinct indicator once). Then each bar is processed in four steps. Signals are evaluated on the bar's close and fill at that close; stops and targets are checked against the bar's high and low.

  1. 1
    Protective exits on the bar’s range
    For each position opened on an earlier bar: the stop first (a gap through it at the open), then take-profit targets in order (a gap fills at the open); then the per-entry time exit and max loss, then the intraday square-off. A trailing stop moves for the next bar after these checks.
  2. 2
    Exit signals
    Any that acts closes every open position at the close.
  3. 3
    Entries
    An instant entry on the first bar, then at most one main entry per bar from the entry signals, then at most one entry per layered entry set. Entries open at the close.
  4. 4
    Equity
    Equity is marked to market at the close; the daily loss limit is checked.
ℹ
Note:A position opened on a bar is not checked against that same bar's range — its stop and targets apply from the next bar. A can exit and re-enter on one bar: exits run before entries.

Warm-up has no value

An indicator has no until it has enough bars ((200) needs 200). Until then every comparison involving it is false, so a signal cannot fire during warm-up and a needs one valid bar before it. The result warns when an indicator never produced a value on the — usually a test shorter than its .

When a signal fires and acts

  1. The signal's conditions are evaluated on the bar (in its interval and candle type).
  2. Repetition. A repetitive signal fires on every true bar; a non-repetitive one only on the first bar of each run of true bars. This count is fired in the signal .
  3. Cooldown. If the signal acted within the last cooldownBars bars it does nothing.
  4. . With flow blocks, the first matching if / elif (or the else, or the switch case) decides the action; the signal acts only if that action is its role (entry or exit).
  5. Position rules. An entry also needs room under maxPositions, the open for entries, the daily loss limit not hit, and — when already holding — the re-entry rules. When it opens a position, acted is counted and the cooldown starts.
★
Pro tip:A gap between fired and acted in the signal means the conditions are fine but something after them — cooldown, position limit, , — is blocking the .

Adding to positions

FieldTypeDescription
reEntryobjectRestricts when the main entry signals may add while a main position is open (without it, any acting adds until maxPositions). cooldown | grid | dca (only at a worse price) | pyramid (only at a better price); maxReEntries; cooldownBars since the last main entry; distance + distanceType ( | | ) from the last entry; and spacing.
entries[]entry setLayered entry sets with their own signals. Layer k opens only while layer k−1 is open (not opened on this bar), and only once the gap is reached.
layering"adverse" | "favorable" | "any"Direction of the gap: adverse = price moved against the previous layer (DCA), favorable = in its favour (pyramid), any = either way.
gap{ type, value } of, or distance from, the previous layer’s .
exitOverrideobjectPer entry set (or for the main entry): its own / takeProfit replacing the global ones, a timeExit in minutes and a maxLoss percent. Exit signals still close every position.

Sizing and costs

ModeQuantity
fixedquantity units
percentOfCapitalquantity % of current cash ÷ fill price
riskBasedquantity % of cash ÷ (needs a stop; without one it falls back to and warns)
capitalPerPositioncapital × leverage ÷ fill price

Percent and risk sizes are capped at cash × leverage ÷ price. Every fill moves against you by slippagePercent; each fill pays commissionPercent of plus commissionPerOrder, and a partial close carries its share of the entry fee.

Stops and targets

FieldTypeDescription
stopLoss.type"percentage" | "fixed" | "atr"Distance from the entry fill: percent of price, price units, or × (atrPeriod) at entry.
stopLoss.trailingEnabled / trailingValueboolean / numberTrails the reached by trailingValue (same unit as the stop; trails a percent of the best price). Only ever moves in your favour. Exits as trailing-stop once it is at or past the entry.
takeProfit.type + valuepercentage | fixed | riskRewardOne target that closes the whole position. riskReward is a multiple of the and is skipped (with a ) when there is no stop.
takeProfit.targets[]{ type, value, exitPercent }Several targets, each closing exitPercent of the original size, nearest first (target-1, target-2, …). The rest rides to the stop or an .
maxDailyLossPercentnumberWhen the day’s equity reaches it, no new entries until the next day. Open positions are not closed.
symbol.sessionMode intradaysessionPositions are squared off on the last bar that ends at or after sessionEnd; entries only between sessionStart and the square-off.
Exit reasonFill
stop-loss / trailing-stopthe stop level, or the open on a gap through it
take-profit / target-Nthe target level, or the open on a gap through it
time-exit / max-loss / session-endthe
signal: <name>the
end-of-datathe last close (backtests only; a keeps the position)

Where the numbers come from

Result fieldHow it is computed
trades[]One per fill that closes: entry / exit time and price, side, quantity, pnl (net of fees), pnlPercent, fees, barsHeld, MFE / MAE %, exitReason, signalId, entryLabel
totalPnl, winRate, profitFactorFrom ; profitFactor is gross profit ÷ |gross loss| (infinite with no losses)
maxDrawdown(Percent)Largest peak-to-trough fall of the -to-market
sharpeRatioMean ÷ of daily equity returns × √252 (days in the )
exposurePercentShare of bars with at least one open position
signalStats[]Per signal: fired (conditions met, after the repetition rule) and acted (opened or closed positions)
warnings[]Signals that never fired, indicators that never produced a , and target fallbacks, parser warnings
!
Caution: at the and at stop / target levels assume liquidity. On thin instruments, sizes or fast markets, fills will be worse — set realistic slippage and commission before trusting a result.

See also

Related articles

  • Grid Range

    Charts / Drawing Tools / Measurement

    Design a grid trading ladder directly on the chart. Drag out the price range the grid should trade and the tool derives every rung price, order size,…

  • Step 6 — Exit & Risk

    Automation / Strategy Builder / Wizard Steps

    Exit conditions, stop loss, take profit, staged partial exits and portfolio-level limits. The step that decides whether a losing trade costs you a percent…

  • Strategy DSL — Conditions That Can Never Be True

    Coding / Strategy DSL

    Which conditions the engine and the editors reject because no bar could ever satisfy them, how the check works, what it deliberately does not reject, and…

  • Strategy DSL — Language Reference

    Coding / Strategy DSL

    The strategy JSON the C++ engine executes: every top-level block, signals and flow, operands and the 94-indicator catalog, the eleven operators, and the…

  • Strategy DSL — The Engine

    Coding / Strategy DSL

    The native C++ engine (dslx) that parses, validates, backtests and runs strategy DSL: its modules, the catalog the editors are generated from, indicator…

  • Strategy DSL — The Live Engine

    Coding / Strategy DSL

    How deployed DSL strategies run: one engine process, one connection per client, shared bar feeds and indicators per symbol and timeframe, the request…

  • Writing DSL by Hand

    Coding / Strategy DSL

    Authoring strategy JSON directly: the minimum document, small constructors that keep it readable, validating before anything runs, generating variants, and…

  • Writing Strategies in the IDE

    Coding / IDE / Strategies

    Paste the code below into a new Strategy file. Click Run ▶ to backtest, then Apply to see trade markers on the chart.

  • Stop Loss

    Automation / Predefined Strategies / Risk & Capital

    A grid has no natural exit in a sustained adverse trend. The stop loss is the deliberate escape hatch — off by default, because arming it changes the…

Browse all knowledge base articles →