Strategy semantics: what a strategy can express, and exactly how each piece behaves

Exactly how each building block behaves: values and indicators, conditions and timing, actions, hard limits and complexity, revisions and the text form.

This page states what a strategy can express and exactly how each building block behaves. It has five parts:

  1. Values: everything a strategy can read, and the exact rule behind each number.
  2. Conditions, events and timing: how rules are evaluated.
  3. Actions: what each action acts on.
  4. Limits, checks, history and versions: what is refused, what a revision is.
  5. Backtest versus live.

When each event fires, and the order of operations inside a step, are on the execution model; how orders fill is on Orders and fills.


Values: what a strategy can read

Video tutorial · B1 · on YouTubeStrategy, settings and values

The catalog

  • A strategy is made of values, conditions and actions. There is no scripting and no custom indicator code: every value is one of a fixed catalog of 62 types, and anything else is composed from them with Expressions, status holders and record sets.
  • The 62 types:
    • Constants (5): Number, Bool, DateTime, Symbol, Timeframe.
    • Indicators (38): the built-in technical indicators, by group on Indicators. Only these count towards the limit of 30 indicators.
    • Market reads (4): Candle Data, Market Price, Price Range, Session Range.
    • Clock (1): Current Time.
    • Trades and account (8): Trade Value, Market Exposure, Account Value, Trade Volume (position sizing), Consecutive Losses, Time Since Last Trade, Session P&L, Trade Count.
    • State (5): Bool / Number / DateTime status holder, Record Set, Record Set Reader.
    • Calculation (1): Expression.
  • Every value is a Number except the Bool constant and Bool holder (true/false) and the DateTime constant and DateTime holder (a date and time). Symbol and Timeframe constants exist to be referenced by an instrument or timeframe field (see Shared parameters).
  • Every value that reads bars names its own instrument and its own timeframe (M1 … MN1). There is no "chart timeframe" a strategy inherits; candle-close events are chosen separately per action.

Prices, bars and the two sides of the quote

  • Bars are bid bars. Open, high, low and close are built from the bid, in every timeframe (bars). Every Candle Data field and every indicator is therefore computed on bid prices.
  • Market Price is the only value that can read the ask. Modes: Bid, Ask, Spread (= ask − bid, in price units, not points). There is no mid. It is the same quote a market order fills at. It takes no timeframe and no shift (a non-zero shift is refused).
  • In a bar-by-bar backtest there is no quote inside a bar: Market Price's bid is the processed M1 bar's close (its open while a next-bar-open fill is being priced) and the ask is that price plus the minute's average spread (or your spread override). Tick mode and live read the last real tick, so Market Price can differ between bar mode and the other two.
  • Before a symbol's first price — its first bar or tick in a backtest, the deployment's first live price of it after each start — Market Price reads not a number, so a condition on it is not met (a symbol with no price yet). A symbol read only through Market Price is loaded and subscribed at 1 minute, as a traded one is.
  • Closing side: a long is valued and closed at the bid, a short at the ask — for stop-loss/take-profit checks, floating P&L and closes.

Candle Data

  • Fields: Open, High, Low, Close, Median = (H+L)/2, Typical = (H+L+C)/3, Weighted = (H+L+2C)/4, Volume, and OpenTime = the bar's open time in Unix seconds (a Number, so bars can be ordered and subtracted). OpenTime is refused as an indicator input.
  • Volume is the bar's tick count, the number of ticks inside it. It depends on the price feed: the same bar reads one number in a backtest and another at each broker, so a volume threshold tuned in a backtest does not carry over to live. In an On Tick rule the bar in progress reads its volume so far (volume).
  • A bar's spread cannot be read; Market Price → Spread reads the current spread.

Read positions: shift and buffer

  • A reference reads a value at a shift (bars back) and, on an indicator with several lines, a buffer: the line, by name or by number (Bollinger Bands 0 = upper, 1 = middle, 2 = lower; each indicator's lines are on its entry, reading a line).
  • Every indicator accepts a shift, and so do Candle Data, Price Range and an Expression whose bar-based inputs all sit on one instrument and one timeframe. On every other type a non-zero shift or buffer is refused when you save and again when a run starts — never silently ignored.
  • What shift 0 means depends on when the read happens:
    • in a candle-close evaluation, shift 0 is the bar that just closed and shift k the k-th bar before it — a candle-close rule never sees a bar in progress;
    • in an On Tick / On Timer evaluation (and in status holders and record sets that update on ticks or the timer), shift 0 is the bar in progress, built from the ticks seen so far (MT5's [0]), and shift 1 is the last closed bar. An indicator read at shift 0 then returns a provisional value computed with the bar in progress as its latest input.
    • The rule is the same in tick-by-tick backtests, bar-by-bar backtests and live.
  • If the instrument has not ticked yet in the current period there is no bar in progress, and shift 0 reads the last closed bar.
  • A series on another timeframe than the candle-close event is read at its last completed bar too, cut on the strategy's time zone. A coarser one moves only when its own bar closes: a rule on the daily close reading a monthly candle at shift 0 reads June's close on 1 July, never the month in progress. A finer one reads its last bar closed by the event: a rule on the monthly close reading a daily value reads the month's last day.
  • A shift is a whole number written in the strategy: a shared parameter cannot stand in it. For a look-back you want to optimize, use a Moving Average of period 1 whose Shift is the parameter: MA(1, lookback, sma, close) returns the close lookback bars back (the Shift field).
  • Shifts count bars that exist, not clock periods: a period without prices has no bar, so shift 1 on D1 is the previous daily bar that exists and a 20-bar average can span a data gap (bars).
  • A negative shift (a look into the future) is refused when you save and when a run starts. The largest shift is 1,000. A read deeper than the available history is not evaluable (see below).
  • A line drawn back (Ichimoku's Chikou span, Fractals) has a smallest readable position: a read nearer can never hold a value and is refused when you save and when a run starts, naming that position (lines drawn forward or back).

"Not evaluable" (NaN)

  • A value that cannot be computed — an indicator still warming up, a read deeper than the history, nothing selected in a record set, a division by zero — is not evaluable (NaN). How conditions treat it is under not-evaluable operands; an open whose stop loss, take profit, volume or distance reads not evaluable is refused rather than opened unprotected (stop loss and take profit).

Indicators

  • 38 built-in technical indicators: the catalog, in four groups, is on Indicators, and each indicator's formula, lines, parameters, reading and porting on its group's page (Trend, Oscillators, Volumes, Bill Williams). At most 30 per strategy; periods 1 to 2,500.
  • An indicator's first value lands on the bar its entry gives; before it the indicator is not evaluable (the first value).
  • The "Shift" field (Moving Average, Bollinger Bands, Envelopes, Standard Deviation, DEMA, TEMA, Adaptive Moving Average, Fractal Adaptive Moving Average, Variable Index Dynamic Average; the Alligator has one per line) moves the line that many bars to the right, as MetaTrader 5's ma_shift and bands_shift do: a read at shift s returns the value computed s + Shift bars back. It is a whole number of bars from 0 to 1,000. With a Shift above 0, shift 0 is a closed bar's value, never the developing bar's, and the warm-up loads Shift more bars. It applies in backtests and live alike.

Warm-up and recursive indicators: read this if you compare with MetaTrader

  • Before a run starts, the engine loads enough bars before the start date that the first decision has a value; how many, value by value, is on the execution model → warm-up.
  • SMA, LWMA, Bollinger Bands, ATR (Sma), Price Range, Session Range and the indicators built only on windows (Ichimoku, Fractals, the Stochastic's main line, Williams' Percent Range, CCI, Momentum, DeMarker, RVI, Standard Deviation and Envelopes on a simple or linear-weighted average) use a finite window: once warmed they do not depend on where the run started.
  • Every exponential or smoothed average is recursive, and so is every indicator built on one: EMA, SMMA, RSI, ATR (Wilder), ADX, MACD, OsMA, TRIX, DEMA, TEMA, Bears and Bulls Power, the adaptive averages (AMA, FrAMA, VIDyA), and the exponential or smoothed method of the Stochastic's signal, the Force Index, the Chaikin Oscillator, Envelopes, Standard Deviation, the Alligator and the Gator. Their value depends on where the calculation started. In a backtest they start from their seed only that warm-up before the start date — not from years of history as on an MT5 chart. Their first values in a backtest therefore depend on the start date (and on how much history the strategy's other values need), and converge as the run proceeds: the starting error shrinks by (1 − 2/(N+1)) per bar for an EMA(N) and an Exponential ADX, and by (1 − 1/N) per bar for SMMA, RSI, Wilder ATR and Wilder ADX — below 0.1 % after about 3.5 × (N+1) bars for the first two, about 7 × N bars for the others (ADX chains two such smoothings, so give it about twice as long). MetaTrader 5 starts its ADX smoothings from 0 rather than from an average; that difference fades at the same rates. The adaptive averages forget at a rate that follows the market, given on each one's entry. Start a backtest at least that many bars before the period you want to judge.
  • The Accumulation/Distribution line and On Balance Volume are running totals: their level depends on the first bar the run loaded, for good, and only their changes agree between runs that start on different bars (the first value).
  • Parabolic SAR's warm-up is already sized so the starting bias is below one millionth ((1 − Step)^n ≤ 1e-6, at least 64 bars).
  • Live, every indicator carries its state the way a backtest does: it starts from the first bar of the deployment's warm-up and each closed candle adds one value to what it carried. On every closed candle a deployment therefore reads the value a backtest started at the deployment's start reads on that candle, over the same bars — whatever the period and the timeframe, and however long the deployment runs. A recursive indicator converges from that starting point at the rates above, exactly as in the backtest. A restart, or a full re-warm after a long disconnection, starts the indicators again from the new warm-up, as a new deployment would. A bar corrected after the fact (the broker's own bar for the minute a deployment started in, a gap filled from the broker's history) is recomputed from the state carried up to it. The deployment keeps a limited number of bars per series — the largest warm-up any value on that instrument and timeframe needs, plus 64 bars, growing by as many again (at most 256 bars) before the oldest are dropped (M1 series always keep at least 2,944 bars) — which bounds how far back a value can read (a read past the kept bars is not evaluable); it no longer moves where an indicator started.
  • How the values are verified. Every indicator's values are verified value by value against an independent reference; the record is on Why you can trust the engine → indicators.

Price Range

  • Highest high, lowest low, or percentage height (highest − lowest) / lowest × 100 over barsCount bars (1 to 2,500) of one instrument and timeframe. There is no absolute high − low mode: write it as an Expression of the two.
  • The window is numbered from the bar in progress, as MT5's iHighest/iLowest(…, count, shift): shift 0 includes the bar in progress (its running extremes, so the value can change during the bar); shift k ≥ 1 starts k bars before the bar in progress and spans barsCount closed bars. If fewer closed bars exist than the window needs, the value is not evaluable.
  • Trap in candle-close evaluations. There, Candle Data and indicators number from the bar that just closed (shift 0), but Price Range shift 1 also starts at the bar that just closed. A breakout written as close (shift 0) > highest high (N bars, shift 1) compares the bar with a window that contains it and can never be true; use shift 2 to compare with the N bars before it. On M1 in a candle-close evaluation, shift 0 and shift 1 give the same window. In On Tick / On Timer evaluations both providers agree: shift 1 is the last closed bar.

Session Range

  • High, Low or Range (= high − low) of a time-of-day window, start–end (hours and minutes) read on the strategy's time zone, on the current local day. Overnight windows (end before start) are refused. It takes no shift.
  • A bar counts when its open time lies in [start, end], both ends included — the bar opening exactly at the end time is included. For an 08:30–08:45 range on M3 set the end to 08:42; 08:45 would also include the 08:45–08:48 bar.
  • Before the first bar of the window it is not evaluable; during the window it includes the bar in progress (On Tick reads); after the end it stays fixed for the rest of the local day and starts again the next day.

Current Time

  • One component per value, as a Number: Year, Month, Day (of month), DayOfWeek (Sunday = 0 … Saturday = 6), DayOfYear, Hour, Minute, Second — of the engine's clock in the strategy's time zone. "Minute of day" is Hour × 60 + Minute as an Expression.
  • Clock: in tick mode and live, the tick's time. In a bar-by-bar backtest, the decision instant, which is the close of the M1 bar being decided — the decision taken at the close of the 09:59 bar reads Hour 10, Minute 0, as the tick that closes that minute does in tick mode.
  • So a candle-close rule reads the close of its candle, not its open: at the daily close of Thursday 30 November, Month already reads 12. A rule keyed on a change of month fires at the close of the month's last trading day.

Trades and the account

Trade Value — one field of one of your trades.

  • You choose a kind (any trade, long position, short position, buy limit, sell limit, buy stop, sell stop), optionally the opener action whose trades count, and an index: 0 = the first by placement, 1 the next… A pending order keeps its place when it fills, and the numbering shifts as trades close. For "any trade", open positions are numbered first, then pending orders.
  • Fields: Price, StopLoss, TakeProfit, Volume (remaining lots), Profit, Day (of month) / Hour / Minute / Second of the open time in the strategy's time zone, AgeMinutes.
  • Price: a pending order's order price; a position's fill price — a position that came from a pending order included, in a backtest and live alike, so any gap or slippage at the fill shows in it.
  • Profit: the position's floating P&L in account currency at the closing side (long → bid, short → ask), before commission and swap; 0 for a pending order.
  • AgeMinutes: fractional minutes since the position opened (since placement for a pending order), measured in UTC so daylight-saving changes do not affect it. Use it for time-based exits.
  • No matching trade → every field reads 0, which cannot be told apart from a real 0; gate such reads on a Market Exposure count.

Market Exposure — nine counts: open positions (all / long / short), pending orders (all / buy limit / sell limit / buy stop / sell stop), and positions + pending orders together — across every instrument the strategy trades, optionally only those one opener produced. On a netting account each instrument's net position counts as one.

Account Value — Balance, Equity or Free Margin.

  • Backtest: balance = deposit + realized P&L (commission and swap included); equity = balance + floating P&L; free margin = equity − used margin (the simulated account). Balance includes every close at once. Equity and Free margin are as of the last recomputation: in tick mode the previous tick, or the latest fill in the same tick; in bar mode normally the previous bar's close, or this bar's open after a market fill. Used margin, margin level and deposit load cannot be read.
  • Live: the whole broker account, not the strategy. Balance = the account's balance as last synchronised with the broker plus the P&L realized by ATH deployments since; equity = that balance plus the floating P&L of every open position on the account — those of ATH deployments priced on every price, the others (manual trades, positions a stop kept) at your broker's figure from the last read; free margin = equity − the used margin your broker states for the account (Live execution). Every deployment on the same account reads the same figures.

Consecutive Losses, Time Since Last Trade, Session P&L, Trade Count — read your closed trades (optionally one opener's).

  • A closed trade is every close, including each partial close, with its profit net of commission and swap.
  • Consecutive Losses = the run of closed trades with profit < 0 counting back from the latest; a break-even (0) trade ends the run.
  • Time Since Last Trade = time since the latest close, in seconds, minutes, hours or days; with no closed trade it reads ≈ 1.8 × 10^308 (the largest number), so "more than X since the last trade" is true before the first trade.
  • Session P&L = the sum of the profit of trades closed since the period started (open positions and swap booked to the balance are not in it); Trade Count = how many closed since then. Periods: Hourly, FourHourly, Daily, Weekly, Monthly — on the same grid as the bars: FourHourly is a local 4-hour block like an H4 bar, Weekly starts on local Monday 00:00 like a W1 bar; the full table is on your strategy's clock.

Position sizing: Trade Volume

  • Six modes. "Balance" is the Account Value balance above (live: the whole broker account's).
    • FixedLotSize — the parameter in lots, passed through unchanged. An off-step or out-of-range lot is refused at order time, not rounded.
    • OneLotEvery — balance ÷ parameter.
    • FixedMoneyAmount — lots = risk ÷ (|entry − stop| × contract size × quote→account rate), risk = the parameter in account currency; entry and stop are two Number values you name (each with its own shift); the rate converts the loss at the stop price.
    • BalancePercentage — the same with risk = balance × parameter / 100.
    • FixedDollarExposure — parameter ÷ (current ask × contract size × quote→account rate): the lots whose notional, in the account currency, is the parameter. On EURUSD at 1.10 (100,000 per lot) on a USD account a parameter of 10,000 is 0.09 lots; on JP225 at 48,000 (one unit per lot, quoted in yen) with USDJPY at 150, one lot is $320, so 10,000 is 31 lots. BalancePercentageExposure — the same with a notional of balance × parameter / 100. The rate converts at the ask, so on the conversion pair itself (USDJPY on a USD account) the lots are the notional ÷ the contract size; other pairs use the current rate.
  • Risk-based sizing reads the balance, not equity, and leaves out spread, commission and slippage; its conversion at the stop price is exact only when the conversion pair is the traded pair itself (USDJPY on a USD account), other pairs use the current rate.
  • Every mode except FixedLotSize is then floored to the volume step and clamped into [minimum, maximum] volume — with no upper clamp where no maximum is stated, as on the catalog's instruments (volume). A result ≤ 0, an unset entry or stop, a zero distance or a missing FX rate gives 0 lots, and an entry or stop that is not evaluable gives a not-evaluable volume; either way the order is refused — no trade, never a minimum-lot trade. Parameter must be > 0.

Expressions

  • Binary: Add, Subtract, Multiply, Divide, Modulo, Power, Min, Max. Unary: Negate, Abs, Sqrt, Log (natural). Leaves: numbers and references to Number values (each with its own shift/buffer). No comparisons inside an expression — those are conditions.
  • Divide or Modulo by exactly 0, Sqrt of a negative, Log of ≤ 0 → not evaluable; Power follows standard floating-point rules (a negative base with a fractional exponent is not evaluable); Modulo keeps the sign of the dividend; any not-evaluable input makes the result not evaluable. Nesting depth ≤ 32.
  • A shift written on a reference inside the expression reads that input at that offset. A shift on the reference to the expression (expr[1]) returns the value the whole expression had that many bars ago; it is allowed only when every bar-based input sits on one instrument and timeframe and each of them accepts a shift (an expression over a Session Range does not), and is refused otherwise. Bars before the run started (or before a live restart) read not evaluable.

Constants and shared parameters

Video tutorial · B6 · on YouTubeShared parameters and expressions
  • Number: a double, no rounding. Bool: true/false. DateTime: a fixed date and time in UTC — it is not converted to the strategy's time zone.
  • DateTime values exist only as DateTime constants and DateTime holders fed by them; there is no "now" as a DateTime. Time-of-day logic uses Current Time; durations use Trade Value AgeMinutes or Time Since Last Trade.
  • Shared parameters: any numeric setting (a period, a bar count, a capacity, a session hour…) can reference a Number constant of the same strategy, and an instrument or timeframe field can reference a Symbol or Timeframe constant. The constant's value is substituted before the run, so optimizing the constant moves every place that uses it. Only constants can be referenced; a missing or wrong-type target, or a resolved value out of range, is refused when you save. A Timeframe constant cannot be "current".

Status holders

Video tutorial · B7 · on YouTubeStatus holders and record sets

Status holders (Bool, Number, DateTime) hold one value until a rule replaces it.

  • The holder starts at its initial value. On every event of its own event type (tick, timer or a candle close, independent of the actions'), its rules are tried in order and the first rule whose conditions are true writes its source value; the rest are skipped for that pass. Reads are never gated: anything reads the current value at any time.
  • All holders and record sets update before any action is evaluated on the same event, in ascending order of creation (their id). One that reads an earlier-created unit sees its value from this pass; one that reads a later-created unit sees its value from the previous pass. A shift on a holder read is refused, so "the value one pass ago" is a second holder, created earlier, whose rule copies the first.
  • The initial value and every source must have the holder's type; a holder cannot be its own initial value; each rule needs at least one condition; crossovers are not allowed in holder rules.
  • A holder that reads itself (a counter, a running peak, a sum) must start with a reset rule whose condition reads Current Time (directly or through an Expression); its other rules stay inactive until that reset has fired once in this run, so a backtest starting mid-session and a live restart both hold the initial value instead of a partial sum.

Record sets

Record sets keep an ordered book of records, each of 1 to 8 numeric fields.

  • On every event of its own type the set runs, in order: anchor (a required rule; when true the book is cleared and appending is enabled) → select (walk the records oldest first, keep those passing the filter, reduce the survivors to one record, below; recomputed every pass, never held over) → retire (any record matching a retire rule is dropped) → append (the first append rule that is true adds one record, one source per field). A record is never selected or retired in the pass that appended it; a record selected and then retired still drives that pass's actions. Nothing is appended until the anchor has fired once in this run (with a lookback, in the replay before it).

  • The pick. Its filter is required: a pick over every record names a condition every record meets, such as a field at or above 0. The survivors are then reduced by one of:

    • First or Last, in append order;
    • Max or Min of a field;
    • Largest k or Smallest k of a field: the k-th record from the large or the small end, k from 1 to the capacity, so Largest 1 is Max and Smallest 1 is Min;
    • Quantile p of a field: the records ordered from the smallest, and the one at the nearest rank, p % of their count rounded up and never below 1, p from 1 to 100. Of 60 records, Quantile 95 is the 57th smallest, the 4th largest.

    Equal values keep append order, the earliest-appended record first, from whichever end the pick counts; Max and Min therefore keep the earliest of equal records. A rank past the number of survivors selects nothing, and a not-evaluable field never wins and takes no rank.

  • Capacity 1 to 64; when full: DropOldest (default), DropNewest, or Refuse (the new record is dropped, as DropNewest). At most 8 record sets per strategy.

  • A Record Set Reader returns the selected record's field (not evaluable when nothing is selected), the selected count (1 or 0) or the number of records in the book. Reading the set itself returns the selected count. With nothing selected every comparison on a field is false, != and NOT included (not-evaluable operands); gating on selected count == 1 says so plainly.

Lookback: the book before the start

A record set that runs on a candle close can declare a lookback of 1 to 1,000 closed bars of its event.

  • Before the run's first decision, the set, with every status holder and record set it reads (and what those read), is replayed over those bars before the start: each at its own candle closes, with the clock and the candles as they stood at each close, no action evaluated and no order placed. The run starts with the book a run started that many bars earlier would hold, record for record. A live deployment rebuilds it the same way from your broker's history, at every start and restart.
  • The anchor fires in the replay as it would have, so with a lookback the run's first pass is the replay's first.
  • With DropOldest and a lookback at least as long as the capacity, the book is full and the same whatever the start. DropNewest and Refuse keep the oldest records, so where the replay starts decides what the book holds.
  • Only what bar history can rebuild is replayed. A lookback is refused when you save if the set runs on ticks or the timer, or if it, or something it reads, reads a 1-minute series, a Price Range or Session Range (built from 1-minute bars), the market price, a trade, position or account value, or a holder or record set on ticks or the timer. The message names the read.
  • The replay is capped at 100,000 closes of the finest timeframe the set and its reads use. A weekly lookback of 60 that reads an hourly holder is about 10,000.
  • When the history before the start is shorter than the lookback, a backtest rebuilds the book from what there is and names the set on its result. A deployment refuses to start, naming the set, the closes your broker's history holds and the lookback asked; so does a deployment whose lookback reaches back more than 2 years.
  • A lookback can't be swept in an optimization.
  • A set that could declare a lookback and does not is flagged by a warning in the Source view, and to a connected AI app: its book starts empty at every start and restart.

Worked example: the top 5 % of weekend gaps

A book of the last 60 weekly opening gaps on EURUSD, whose 95th percentile is the threshold for an unusual gap:

param one = 1
let wopen = candle(open) on EURUSD W1
let wclose = candle(close) on EURUSD W1
let gap = abs(wopen - wclose[1])

records gaps on close(W1) {
  fields size
  capacity 60
  lookback 60
  reset when gaps.count == 0
  add when one == one -> size = gap
  pick quantile(size, 95) where self.size >= 0
}

let bigGap = gaps.size
  • Each weekly close appends the week's opening gap: its open against the previous week's close.
  • The anchor holds only while the book is empty, so it fires on the set's first pass and the book then rolls: 60 records, the oldest dropped at each new one.
  • With lookback 60, that first pass is 60 weeks before the start, so the run's first decision already reads 60 gaps. Without it, bigGap would rest on a handful of gaps for the first weeks, and on none after a live restart.
  • The filter keeps every record (a gap is never negative), and Quantile 95 of 60 picks the 57th smallest gap, the 4th largest. An entry can then compare the current gap with bigGap.

Not yet documented (values)

  • Whether RSI on a completely flat window matches MT5 (we return 100).

Conditions, events and timing

Video tutorial · B2 · on YouTubeYour first rule: an entry

Comparisons

  • Operators: ==, !=, >, >=, <, <=, crosses above, crosses below. Both sides must be the same type (refused at save otherwise; if a mismatch ever reaches a run, the comparison is false). Numbers and DateTimes accept every operator; Bools accept only == and !=. Crossovers work on Numbers and DateTimes, in actions only (not in holder or record-set rules).

Groups: AND, OR, NOT

  • A group is AND or OR over its conditions and child groups, and can be negated as a whole. At most 16 levels deep and 150 nodes per tree.
  • Evaluation follows the stored order — the group's own conditions first, then its child groups — and stops early: an AND at the first false, an OR at the first true. A comparison that reads a not-evaluable value stops neither (not-evaluable operands). Negation applies to the group's result.
  • An action whose condition group is empty fires on every evaluation of its event (an empty AND is true). Holder and record-set rules must contain at least one condition.

Not-evaluable operands

  • A value is not evaluable when it cannot be computed: an indicator still warming up, a division by zero, a record-set field with nothing selected. A comparison that reads one is undefined, and a condition that reads an undefined value is false — != and NOT included: RSI != 50 and NOT (RSI > 70) do not fire while the RSI warms up. A crossover never fires on a not-evaluable operand.
  • The tree combines an undefined comparison the three-valued way: an AND is false if any part is false, true only if every part is true, and otherwise undefined; an OR is true if any part is true, false only if every part is false, and otherwise undefined; NOT leaves undefined undefined. An undefined tree does not fire. So a group whose answer does not depend on the missing value still decides: NOT (RSI > 70 AND hour == 3) is true at 10:00 even while the RSI warms up, because hour == 3 is false.
  • Holder and record-set rules follow the same rule. In a live deployment's trace and in a replay, a comparison that read a not-evaluable value shows as false, and the groups above it as not evaluated.

Crossovers

  • A crosses above B is true at an evaluation where A > B now and A ≤ B held at the previous evaluation of that action (mirrored for below). The previous evaluation is the action's own: the previous tick for On Tick, the previous bar close for a candle-close action. Every crossover of the action is recorded before its group is evaluated, so an early stop in the group cannot make it miss one.
  • The memory starts empty when a run starts (and when a live deployment restarts): the first evaluation never crosses. During a paused drawdown window it is frozen: the first evaluation after the pause compares with the last one before it. The same holds for an open's crossover while you pause a live deployment, since its opens are not evaluated then.

When an action is evaluated

  • Each action has an event: On Tick, On Candle Close · {timeframe} for any of the 21 timeframes, or On Timer (kept by strategies that already use it; new strategies cannot pick it). The strategy has a default event and an action may override it, and the event's timeframe does not have to match any value's timeframe. Status holders and record sets have their own event, independent of the actions'.
  • When each event fires in tick mode, bar mode and live, the order of operations inside one tick or bar, and the order of actions within one evaluation are on the execution model → when rules run and order of operations.
  • In a bar-by-bar backtest every evaluation is a decision at the close of a 1-minute bar (an On Candle Close · H1 action on the 10:59 bar, at 11:00), the instant tick mode decides it, and what it decides executes at the next bar's open. A run's first decision is therefore at its start + 1 minute: a candle close falling exactly on the start is not decided.
  • Action order: the order the Actions list shows — the top-level actions by their number, each followed by its children by theirs (A, B, B's first child, B's second child…). Within one evaluation the actions that fire are then applied under the same-evaluation rules: closes, deletes and modifies first, decided together on the state the evaluation started from, then the opens one at a time, each seeing what came before it. So a strategy that closes and re-opens on one signal works whichever action is listed first.

Multi-instrument strategies

  • Each open names its instrument (directly or through a Symbol constant); each bar-reading value names its own. The traded instruments are the ones named by trade-levels blocks; the first one in the Actions list's order is the primary symbol, which alone drives candle-close events. An instrument you only read never becomes primary; currency-conversion instruments are loaded automatically and never trade. Every open fills on its own instrument's quote; closes and cancels are not limited to one instrument (scope).
  • A second instrument's M1 bars are read one bar late at a candle close (read conventions).

Time zone and higher-timeframe bars

Video tutorial · B4 · on YouTubeTrading hours and session ranges
  • Each strategy has a time zone (an IANA id, e.g. Europe/Athens, or New York close, the clock MT5 brokers keep), shown in the app as its Reference timezone. Only zones whose base offset is a whole number of hours are accepted (Asia/Kolkata is refused); daylight saving is followed. New strategies created in the app start on Europe/Bucharest; a strategy created without a zone uses UTC (your strategy's clock). The zone is on the strategy's header line, and the Setup row of every backtest and optimization report names the zone of the revision it ran.

  • It decides: Current Time, candle-close boundaries, how higher-timeframe bars are cut, Session Range windows, the Daily/Weekly/Monthly periods of Session P&L and Trade Count, and Trade Value's Day/Hour/Minute/Second. Trade timestamps stay in UTC and durations (AgeMinutes, Time Since Last Trade) are unaffected. Where each period starts, what daylight saving does, and the short Sunday bar a UTC strategy sees are on your strategy's clock. Backtest and live cut bars the same way.

Trading hours

  • There is no trading-hours setting. Trading hours are conditions on Current Time (e.g. Hour >= 8 AND Hour < 17, or a minute-of-day Expression), and "close at session end" is a close action gated the same way.

Not yet documented (conditions and timing)

  • Whether live reads a second instrument's M1 bars one bar late at a candle close, as the backtest does.

Actions

Video tutorial · B3 · on YouTubeExits and trade management

The actions

  • The catalog has 20 actions. Opens: buy / sell × market / limit / stop (6). Closes: close buy, close sell, partial close buy, partial close sell (4). Cancels: delete buy limit, buy stop, sell limit, sell stop orders (4). Modifies: modify buy position, modify sell position, modify buy limit / buy stop / sell limit / sell stop order (6).

Opening at market

Stop loss and take profit

  • Absolute prices, each read from a Number value when the order executes (so ask − 2 × ATR works), rounded to the instrument's digits (an exact half rounds away from zero, as in MetaTrader 5). 0 or empty = no stop / no target.
  • A stop loss, take profit, trailing or break-even distance that is not evaluable, infinite or negative refuses the whole order, in backtest and live alike — the position is never opened without the protection you configured.
  • A market open whose stop or target is already on the wrong side of the price it would close at is refused, in backtest and live alike, as a broker refuses it (wrong-side stops).

Volume

Pending orders

Video tutorial · B5 · on YouTubePending orders
  • The order price is a Number value, rounded to the digits, and must be positive. Which side of the market it must be on, and when and at what price the order fills, are on Orders and fills → pending orders.
  • Expiration is an optional DateTime value, read when the order is placed; the order expires on the first tick at or after it. Since DateTime values are fixed UTC dates (constants), "expire N minutes after placement" cannot be written; instead gate a delete action on the order's Trade Value AgeMinutes.
  • There is no time-in-force setting: without an expiration, an order stays until it fills or is cancelled.

Closing, partial closing and cancelling: what they act on

  • Close buy closes every open long of the strategy on every instrument; close sell every short. With a parent opener it closes only that opener's positions; with a position index (hedged accounts) exactly the Nth matching position by placement. The instrument on a close's own block does not limit what it closes — it only decides whose ticks evaluate it. Partial close applies its close volume to each matching position with the same scope rules. Delete cancels every resting order of its kind on every instrument, or only its parent opener's.

  • The prices, the partial-close volume rounding (which differs live) and the netting rules are on Orders and fills → closing positions and Live execution → closing.

Modifying positions and orders

  • Position modify (buy / sell) sets stop loss, take profit, trailing activation, trailing step and/or break-even activation on every open position of that side on its instrument (or its parent opener's). Order modify reprices resting orders of one kind: price, expiration and the five levels. A modify must set at least one level; on a netting account a position modify cannot have a parent. What is refused, and when a modify takes effect in each mode, is on Orders and fills → changing open positions and cancelling and modifying.

Parent and child actions

  • Only an open can be a parent. A market open's children: the same-side close, partial close and position modify. A pending open's children: those, plus its matching delete and order modify. A child acts only on the trades its parent produced (the link survives a pending fill); a parentless close, delete or modify acts on every matching trade. Values that filter by opener (Trade Value, Market Exposure, Trade Count, Session P&L, Consecutive Losses, Time Since Last Trade) use the same link.

Trailing stop and break-even

Re-entry and caps

  • There is no one-trade-per-bar or re-entry rule: an open action sends a new order every time it is evaluated with its conditions true, unless you gate it (for example long positions == 0, a Trade Count, a holder or a crossover) (a rule that stays true). A backtest that holds too many open positions or completes too many trades fails (limits).

Hedged and netting accounts

  • The strategy declares its account type. On a netting strategy, the Nth-position selector and a parented position modify are refused when you save, and deploying it on an account of the other type is refused (deploying to netting accounts is turned off for now: netting accounts). How each account model handles fills is on Orders and fills → hedged and netting accounts.

Strategy drawdown limits

  • A strategy can carry drawdown limits: Overall and Static overall, which halt the run or deployment, and timed ones, which close every position and pause the actions until their window passes (D1, W1 and MN1 on the strategy's calendar, the shorter ones rolling). How they are measured, in backtests and live, is on Drawdown limits → strategy limits.

Settings that have no effect today

  • "Consume all calculated lots" — retired: the setup no longer shows the switch, and a value stored on an older strategy is kept as it is and ignored. No engine splits an oversized volume into several orders; a volume above the maximum is clamped (computed sizing modes) or refused (fixed lots).

Limits, checks, history and versions

Hard limits per strategy

  • 200 values, of which at most 30 indicators; 50 actions; condition trees at most 16 levels deep and 150 nodes (actions, holder rules and record-set rules alike); expression depth 32; indicator period and Price Range bars at most 2,500; shift at most 1,000; at most 8 record sets, capacity 64, 8 fields, a lookback of 1,000 closed bars and a replay before the start of 100,000 closes; across all record sets, capacity × (select-filter nodes + retire-rule nodes) at most 7,500; name 200 characters, strategy note 500, notes on parts 1,000.
  • A write over any limit is refused whole, naming the count. A basket of many instruments (a momentum or trend book over dozens of markets) does not fit in one strategy: build one strategy per asset class and combine them in a portfolio.

The complexity limit

  • A strategy may evaluate at most 500 units per tick. One unit is one condition evaluated on every tick: conditions of On Tick / On Timer actions, holders and record sets count fully; candle-close ones count 1/60; a record set counts its anchor and append conditions once and its retire and select-filter conditions × capacity, and a pick by rank one more unit × capacity; a lookback's replay runs once before the start and does not count; a Price Range or Session Range weighs one unit per 100 bars of its window, never less than 5.
  • Over the limit the strategy still saves (the builder flags it), but starting a backtest, creating an optimization, deploying and restarting are refused with a message naming the three heaviest parts. To get under it: move rules to candle close, shorten long ranges, lower record-set capacities, or split the strategy.

What is checked when

  • Save: structural errors — unknown types, missing instrument or timeframe, bad parameters, type mismatches, illegal shifts or buffers, illegal parent links, two drawdown limits on one period, circular references, the hard limits, a partial close without a close volume, a modify without a level. A half-finished open (no volume yet) and a strategy over the complexity limit still save.
  • Validate (the validate check, and a connected AI app's check): also at least one action and at least one open.
  • Backtest start, optimization create, deploy: every open has an instrument and a volume, every pending open a price, every partial close a close volume, every modify a level; the complexity limit; and the structural checks again.

History before the start

  • See warm-up and recursive indicators: enough bars are loaded before the start that the first decision has values; recursive indicators start from a seed over that history only.
  • Holders, record sets and shifted Expression reads are not replayed over that history: they start at the run's start (holders at their initial value, record sets empty, anchored rules inactive until the anchor fires).
  • The exception is a record set with a lookback. It is replayed over the closed bars it declares before the start, with the holders and record sets it reads, so the run starts with the book a run started that much earlier would hold. Its candles and indicators are loaded from the replay's start, with their own warm-up before it.

What a live restart resets

  • When a deployment restarts, its strategy starts fresh: crossovers need one evaluation before they can fire; holders return to their initial value and self-referencing ones wait for their reset rule; record sets are empty until their anchor fires, except that one with a lookback is rebuilt from your broker's history before the restart, with the holders and record sets it reads; shifted Expression reads are not evaluable for bars before the restart; recursive indicators are re-seeded from the history fetched at restart; the On Timer schedule restarts from the restart moment.

Revisions

Video tutorial · B8 · on YouTubeRevisions and the Source view
  • Every backtest, optimization and deployment runs on a frozen revision of the strategy; later edits never affect it. Identical logic is the same revision; a change only to the name, description, notes, log level or value names creates none. Revisions can be labelled, listed with a summary of changes, compared, and restored (the state before the restore is kept as a revision first).

Templates

  • 19 templates are copied into every account; the Templates page lists them. A copy is an ordinary, editable strategy but cannot be deleted from the app.

The text form

  • Every strategy has a text form, regenerated from the strategy each time you open it, and a strategy can be written or edited as text. Shifts and buffers ride the reference (atr[1], bands.lower[2]); # lines are notes. A text that would not turn back into exactly the same strategy is refused and nothing is saved.
  • Once a text is applied, the Source view lists its warnings under it: what the strategy will do that you may not mean. Today there are two: a close without a parent action in a strategy that opens the same side on two or more symbols, since such a close acts on every one of them (close scope); and a record set that could declare a lookback and does not, since its book starts empty at every start and restart. A warning never stops the save or the run. The AI assistant and a connected AI app get the same warnings when they write or check a strategy.

Backtest versus live: where the same strategy can behave differently

The engine code is shared, so shift rules, the update order of holders and record sets, crossovers, rounding of prices and the order checks are the same in both. Every place where the same revision can still behave differently — volume, Market Price in bar mode, recursive indicators, Account Value and balance-based sizing, partial-close volume, several actions in one evaluation, trailing stops and the broker's minimum distance, stops and targets at the broker, candle closes in multi-instrument strategies, On Timer, heavy load, restarts and the first evaluations after a start — is in the table on Live execution → live versus a backtest; the bar-mode differences are on the execution model.

Not yet documented (backtest versus live)

  • The live counterpart of the one-bar-late read of a second instrument's M1 bars (read conventions).

Questions?support@algotradinghub.io

Last updated Nov 21, 2026© 2026 AlgoTradingHub