Portfolio configuration
The Portfolio Builder (Backtest › the bottom panel) builds a book of strategies and judges each by what it adds to the book: strategy slots, ranking, position rules, a risk budget and portfolio-level risk configuration, saved as a portfolio template (the book) to reuse the same authored snapshot. It has six tabs, each with its sections on the left:
| Tab | Sections |
|---|---|
| Components | Slots (each slot as the open test ran it, with its version, label and weight, and the groups and slots being built) · What each adds · Candidates |
| Correlation | Matrix (Daily returns · Drawdown overlap · Clusters) · Pairs |
| Weights | Method · What each carried |
| Simulation | Run · Runs · Results · Trades · Signal priority |
| Robustness | Luck · Uncertainty · Drawdown risk |
| Risk policy | Rules · Pause and reduce · What it did |
The header names the book and the open test every number is of (what it is evidence
for, its version and run, the attempts on its ledger and its details). Open a test from
Simulation › Runs; where you are lives in the page's address (?pb=…&pb_run=…), so a
reload or a shared link lands on the same view of the same test.
Each slot names its strategy with the same searchable picker as the Symbol Tester: your
strategies with their versions and labels, then the templates in no strategy. Type to
filter by name, or by a timeframe written exactly (1M is a month, 1m a minute). A
version fills a slot through the template that holds it; a version no template holds is
listed but cannot be chosen (open it in the Symbol Tester and save it as a template
first). Until a test of the book is open, Components › Slots says what comes next: add a
strategy to a group, then run a test in Simulation › Run. Simulation › Runs lists each
test's book (Unsaved book for one never saved), the strategies its slots ran, and its
window of data.
A book is saved by its name: Save writes a named book in place, and asks a book
you never saved for its name first. A name another saved book already has is never
written over silently: renaming to it is refused, a book a live portfolio runs cannot be
replaced, and any other is replaced only by the dialog's own Replace “…” button. The
server holds the same rule: a book saved under that name from another tab since the list
was read turns the dialog into the same question. (An agent saving with save_portfolio
gets 409 PORTFOLIO_NAME_TAKEN and says replace: true to write over that book.)
Simulation › Trades prints the test's trade R ledger as the server computes it (the
same object get_portfolio_run carries): closed trades only, with the average R per trade,
the win rate, the profit factor in R, the total R and the $ P&L, for the whole book and by
group → slot, symbol and side → grade. A position still open when the data ends is
marked, not closed: it is counted as open and enters no R statistic. This ledger is
the test's only set of trade statistics: Simulation › Runs lists each test's account
numbers (return, max drawdown, Sharpe), and a finished test is never deleted (its result is
the record of the book's attempt). Opening a test shows its trades,
100 to a page (sorting and the filters cover every trade), with Side and P&L $ kept in
view while the other columns scroll sideways; the magnifier on a row replays that slot
as the test ran it on the chart, which is not an attempt;
Results also says, once, the entry signals the engine set aside (a stop on the wrong
side of the entry, no usable stop, the account gone) and its warnings.
Every portfolio test says what it is evidence for before it runs: Running under one of your registered strategies, a hypothesis you register on the spot, or account exploration (counted for your account, never evidence for any strategy). The test is recorded with its configuration hash (each slot template counted by its own rules) and, once it runs, a digest of the price bars and the perpetual funding settlements it read; a test's details (Simulation › Runs, or the header's Test details) show them, including whether a slot template changed between the submit and the run.
One clock for every trade
A portfolio test acts on each signal at the moment its information exists: the close of the bar it was decided on (portfolio engine 9). A live portfolio takes the same decisions, bar by bar (see When a live portfolio decides). A ranking orders the signals of one timeframe and one market decided on one bar, which is what a live portfolio ranks together: in a group trading crypto and equity symbols, a crypto signal is ranked against the crypto signals of its bar and an equity signal against the equity ones, never against each other (a crypto day and an equity day of one date close at different moments). When both markets' bars close together, the crypto signals are decided first, as live decides them: an equity bar is final in the price store 31 minutes after its close. Live decides in the price store's runs at :01 and :31 past each hour, so in a book trading both markets intraday a crypto bar closing at :30 and an equity bar that closed at :00 are decided in the same :31 run (the crypto one first, the longer timeframe first when they differ), and a portfolio test decides them in that order too (portfolio engine 9). A ranking that could not be computed as configured (an indicator that failed or returned no series for a symbol) fails the test with its reason, rather than ranking on part of its scores; a live portfolio admits no entry that ranking orders on that bar (its exits run as usual) and says so on its card until the ranking computes again. A symbol listed too recently for the ranking indicator simply has no score yet. A pair ranking scores a scoring group only where it can be read: on a bar where its indicator has no value for a pair (still warming up, or a gap in the data), neither symbol of the pair gets its points. A pair ranking compares two symbols' prices, so a pair ranking on volume is refused when you save it: rank by volume with a metric ranking.
-
Ties are taken in a fixed random order, never by name. When more signals of one side of a group arrive on a bar than it has seats for, and nothing ranks them apart (no ranking on that side, or equal scores), the book takes them in an order drawn from each signal's group, symbol and bar. The same portfolio on the same data always takes the same ones, and its live book takes what its backtest took; no symbol is favoured because of where its ticker sorts. A result whose seats this order chose says on how many bars (
seat_order_bars, in its warnings): add a ranking to choose. The groups of a bar compete for the book's room in the order the portfolio lists them (portfolio engine 12). -
An entry is admitted at its decision. An entry that fills at the next open (the default) is admitted at the close of the bar that signalled it: that is when it takes a position slot and its share of the risk budget, sized from the equity the book has realized by then. Its profit or loss starts at its fill. A daily entry is decided at the daily close, a 4h entry at its 4h close: whichever was decided first is admitted first.
-
An entry the next open refuses still held its slot. When the next open is on the wrong side of the entry's stop (it gapped through it), the entry never fills. But the book could not know that at the close it was decided, so it held its slot and risk until that open's bar closed, and another signal of the same close may have been refused for room. The result counts these entries (
entries_not_filled) and says so in its warnings, apart from the skipped entries (skipped_wrong_side_stops,skipped_stop_unavailable), which are signals refused at their decision: the counts add up. -
An exit frees its slot when it is decided. A position leaves at the close of the bar that decided its exit (a stop or a trailing stop: the bar that touched it), and its profit or loss counts at its fill. A stop hit inside a bar frees nothing before that bar closes. A stop hit in the very bar an entry filled in closes the position in that bar, at about −1 R. An exit that fills at the next open frees its slot at the close that decided it (also when the open gaps through the stop and the stop takes the position there), and its profit or loss counts once that open has happened. An entry that fills at that same close can take the freed slot and risk at once, so until the next open the book can hold more positions and more open risk than its limits (the leaving positions are still open).
-
At one close, the longer timeframe goes first. When a daily bar and a 4h bar close together, the daily signals act first.
-
A daily anchor with 4h adds. An add decided before its anchor's decision finds no anchor open and is not taken; one decided at the same close as the anchor is.
-
Cooldown bars count the book's shortest timeframe. A 48-bar cooldown on a book of daily and 4h slots lasts 48 × 4 hours = 8 days, from the close that started it.
-
Every price is one the book had. The Risk Policy, a flatten and the end of the data mark each position at the last close of its own bars, never a bar that closes later. A flatten during a day closes a daily position at the previous day's close, and cancels an entry admitted but not filled yet.
-
A slot never reads a ratio to its own symbol. A strategy reading a ratio to one of the slot's symbols (BTC/BTC is 1.0 on every bar) skips that symbol, and the warnings say so. A strategy the engine refuses to read (an operand reading an output its indicator does not produce) fails the test with the reason, never a slot that quietly trades nothing.
A test run before portfolio engine 4 admitted each entry at its fill bar and could hold a position stopped out in its first bar until the end of the data; one run under engine 4 gave an entry the open refused no slot at all: run it again.
Risk Policy
Risk Policy is a list of independent triggers and configured responses. V1 uses
OR composition: each rung can trigger independently. Thresholds are percentages;
for example, -3.0 means negative three percent. These triggers do not state a
maximum possible loss or outcome.
Risk policy › Rules authors, validates, and saves Risk Policy (E-A).
Every portfolio backtest now applies an enabled policy during the simulation
and Risk policy › What it did reports it (E-B): rung firings marked on the equity
curve, a per-rung impact table, and a one-click no-policy counterfactual. The
cooldown and the risk reduction are set in Risk policy › Pause and reduce. This is a
backtest overlay only: it changes the simulated equity path, never live money.
E-C then enforces the same policy live, frozen at activation and immutable while
armed (no endpoint edits it in place). A park ends when you resume the portfolio with
a written reason, or re-arm it (see Live enforcement (E-C) below). A backtest with
risk_policy absent or enabled: false trades exactly like a pre-Risk-Policy run.
The saved/API field uses the exact snake_case key and shape:
{
"risk_policy": {
"enabled": true,
"composition": "OR",
"rungs": [
{
"id": "day-loss",
"window": "session",
"metric": "pnl_pct",
"operator": "<=",
"threshold": -3.0,
"action": {
"type": "pause_new_entries",
"duration": "until_next_session",
"semantics": "AUTO_RESUME"
}
}
]
}
}
Allowed values:
window:session,week,month,from_highmetric:pnl_pct,drawdown_pct,book_concurrent_risk_pctoperator:<=,>=action.type:pause_new_entries,halve_sizes,reject_new_entries,flatten_and_parkduration:null,until_next_session, or{ "sessions": <positive integer> }semantics:AUTO_RESUMEorPARK
flatten_and_park uses PARK with a null duration. PARK means: enforced live
(E-C) it flattens the whole book and keeps blocking entries until you resume the
portfolio with a written reason, or re-arm it. The other actions use AUTO_RESUME; pause and halve
responses use an auto-resume duration, while reject uses null for its immediate
response.
The parser rejects unknown keys, unsupported enum values, non-finite thresholds,
duplicate or empty rung IDs, mismatched action semantics/durations, and any
composition other than OR. Older templates without risk_policy remain valid
and load as disabled with no rungs.
How the policy is applied in simulation (E-B)
When a backtest runs with an enabled policy, the engine marks the book to market at the close of every represented bar, each position at the last close of its own bars, and evaluates the rungs against that snapshot:
- Metrics/windows:
pnl_pctis measured over a calendarsession(day),week, ormonth; each period's baseline is the previous period's close, so an overnight gap counts.drawdown_pct(from_high) is(peak − equity)/peakover the running marked-equity high.book_concurrent_risk_pctis the summed stop-distance risk of the open positions as a percent of equity. It is instantaneous and ignores the configured window (reported aseffective_window: "instantaneous"). - Actions:
pause_new_entriesandhalve_sizesare duration-gated: they act for theiruntil_next_session/{sessions: N}window then auto-resume (halve scales new position sizes by 0.5).reject_new_entriesis condition-gated: it blocks new entries while its condition holds and auto-resumes the instant it clears.flatten_and_parkcloses the whole book at that close (each position at its own last close; an entry not filled yet is cancelled) and opens nothing for the rest of the backtest (in a backtest there is no owner to resume it, so park = stop for the remainder; live, it stays parked until you resume or re-arm it, as described below).
Results reports three fields on the backtest result (all absent for a disabled
policy): risk_policy_events (each firing: rung, timestamp, observed value,
action, semantics), risk_policy_impact (per fired rung: times fired, max DD saved, and return foregone), and risk_policy_counterfactual (the cached
no-policy twin: the same book re-simulated with the policy off). The
saved/foregone deltas come from comparing the policy-on run against that twin;
each impact row disables only its own rung so a rung is credited its marginal
effect, not the whole policy's. The with-policy run stays the truth everywhere;
the twin exists only for those comparison columns.
Note on drawdown basis: inside the simulation an enabled policy marks the book on
every bar, so drawdown_pct rungs can react to an intraday dip. The equity curve and
Max drawdown of Simulation › Results are the daily marked book (see
Results metrics) for every run, with or without a policy, so a
policy run and a separate no-policy run are measured the same way, and the
Compare without policy counterfactual is too.
Results metrics
Simulation › Results shows the book's account: the equity curve is the portfolio's book marked to market at every daily close: closed positions at their exit, open positions at that day's close, one point per day, flat days included. Max Drawdown is the deepest fall of that curve from a peak, in % of equity, so it includes losses that open positions lived through and later recovered.
Sharpe, Sortino and Calmar are measured on the same daily returns:
- Sharpe: mean ÷ standard deviation of daily returns, annualized with 252 days for equities, 365 for crypto, and the calendar's own count for a mixed book.
- Sortino: the same, against downside deviation only.
- Calmar: compound annual growth ÷ max drawdown.
Sharpe and Sortino need at least 20 days of history; a shorter run reports them
as empty rather than as a number. Final equity is the starting equity plus every
position's net P&L. The result also carries account: the daily panel (CAGR and its
95 % interval, volatility, longest recovery, time in market, return vs an
equal-weight buy and hold of the traded symbols, a Sharpe confidence interval, the
drawdown simulation and a Newey–West t-statistic). The intervals and the simulation
resample whole days in blocks, so days that move together stay together. Results shows
each interval beside its number; Robustness holds the rest of the evidence: the luck
line every book tried on the ledger raises (Luck), the Newey–West t and how the
intervals are made (Uncertainty), and the drawdown simulation (Drawdown risk).
Every position's net P&L is after commission, slippage (inside the fill prices) and,
for crypto, perpetual funding: every crypto symbol is a Binance USD-M perpetual, so
a position pays or receives funding at each settlement it is held through (notional at
the settlement's mark × the rate; a long pays a positive rate, a short receives it).
Simulation › Trades shows each position's funding (−$0.63 paid, +$0.42 received, – for
an equity, which pays none) and the run's costs on one line: commission, slippage and
net funding with its settlement count (the result's costs block; each trade carries
funding (positive = paid) and funding_settlements). A test that would hold a
perpetual over settlements the funding history cannot price yet fails with the reason
rather than running as if funding were free; the history is fetched every hour.
Every position is sized from its stop. An entry signal whose stop has no value at the
signal bar (an indicator stop still warming up) is not a trade: the result counts it as
skipped_stop_unavailable, next to skipped_wrong_side_stops, with a line in
warnings; a test that took no trade because of them says so. Positions are sized from
the portfolio's own equity: once a loss beyond the account takes it to zero or below, no
later candidate can be sized, and the result counts each as skipped_account_ruined
(with its warnings line) on a test that reads ruined.
A portfolio test ends before your account's seal, like every research run (see
the account seal): a window that reaches
into the sealed months is cut at the last day before them, and the result says so
with an "Ends at seal" chip and its seal block. A test that ran before the seal
existed may include the sealed months: its numbers are hidden in Simulation › Runs and
its result is not served. Re-run it.
The agent reads a test the way the Builder shows it (get_portfolio_run: your tests, or
one test's account, attempts, costs, Risk Policy effect and the slots that ran, with its
daily equity and a page of its trades on request), as does the command line
(ss portfolio run [RUN_ID]).
Weights: how the book spreads its risk
Weights › Method decides how much risk each slot carries. A slot's weight is a multiple of its strategy's own risk per trade:
- Equal risk (the default): every slot gets the same volatility while it holds a position. A slot that trades a third of the time is not "safer" on its flat days, so it is not sized up for them.
- Equal risk contribution: every slot contributes the same share of the whole book's volatility, correlations included: two slots that move together share one slice. If that cannot be solved for a month (two slots that cancel each other out), the month falls back to equal risk and Weights › What each carried lists it.
- Manual: you set each slot's weight in Weights › Method (for example 1, 1 and 2).
The whole book is then scaled to the target volatility you choose (10 % a year by default) or, with "Scale to target" off, kept at the volatility the slots would have at their own risk. Manual with equal weights and "Scale to target" off runs every slot at exactly its own risk. The weights are saved with the template.
The weights never look ahead. On the first day of every month they are re-estimated from the slots' daily returns over the 365 days before that day, and they size only the trades decided from then on (a trade is sized when its signal bar closes); the first three months run every slot at its own risk, and so does a slot with fewer than 60 trading days in the market in that year. No slot ever takes more than four times its own risk, no trade is lifted above 5 % of the account, and your risk budget and position limits still apply. When they bind, the book ends below the target and Weights › What each carried says so. Every number in Results comes from simulating the whole weighted book on shared capital, never from adding the slots' curves together.
The live book applies the same weights: what you test is what trades. Once a month, on the month's first trading day, the research worker re-estimates each slot's multiplier for the live book by re-running your Portfolio Test of exactly this book (its start, its symbols and its chart timeframe) extended to that day, and takes the multiplier the test computes there (the test your incubation is compared with, else your newest test of the book). It records the estimate and what it ran on. A test that named no symbols ran every symbol active then; the re-run uses every symbol active now, so it matches the test only while that list is unchanged. Without such a test (or after re-running it failed three times in a month), it runs the book from about 15 months before that day on the live symbols, and the Live page says so: a book whose positions depend on their history (one position at a time, long holds) can then be weighted differently from what a test would show. Run a Portfolio Test of the book to fix that. Every live entry is sized at its strategy's risk × the multiplier in force for its decision, with the same 4× and 5 %-per-trade limits. Three guard rails:
- No valid estimate, no upsizing. Until the month's estimate is recorded (a new book, a late or failed estimate), no slot trades above its strategy's own risk: it takes the lower of 1× and its last multiplier. The Live page says so.
- Real orders never exceed what you consented to. The consent you confirm when you arm a book shows its weights and the most a re-estimate may raise a slot to (4× its strategy's risk, never past 5 % of the account per trade). A book armed before the live book applied weights trades no slot above its own risk until you arm it again (or save its live execution settings again through the consent). A signals-only book places no order and applies the full multiplier.
- Reduced sizing stays reduced. While a book's grade sizing is in its flat fallback (its grade order reversed two months running), no slot trades above its strategy's own risk, whatever the estimate; a multiplier below 1× still applies.
The Live page's Overview shows the Weights strip: the method and target, whether an estimate is in force, each slot's multiplier and risk per trade, what the estimate was calibrated on (your test, from its start, or a fresh window and why), and every estimate recorded. A re-weighted Portfolio Test counts as the template's risk simulation for an arm, and it is the test the incubation compares the book with.
Correlation: how the slots move together
The Correlation tab measures every slot on the book's daily account: its profit or loss each day, marked to market, as a share of the book's equity (a day without a position counts as 0).
- Daily returns: the correlation of each pair over the days both markets trade (a crypto slot's weekend rolls into Monday against an equity slot). Orange means they move together, blue that they offset each other; a dash means too few shared days to say. Selecting a cell shows the 90 % range and how many days it rests on (no range when the two slots were rarely in the market together).
- Drawdown overlap: how often both slots were in a real drawdown at the same time (deeper than their own normal month's swing), against what two unrelated slots with the same drawdown habits would show: the second slot's history is slid against the first's, and only an overlap outside that range is called lose together or lose apart. Inside it the cell stays neutral: it says nothing about the pair. Plus the deepest drawdown they went through together.
- Clusters: the matrix regrouped so similar slots sit together. A group whose average correlation is 0.6 or more is outlined: the same bet twice.
The three are one grid read three ways (Correlation › Matrix); a cell opens its pair. Correlation › Pairs lists every pair, strongest first, and details one: its 90 % range, how often both were in drawdown against unrelated slots, the deepest drawdown they shared and the chart of both.
Weights › What each carried lists each slot's trades, time in the market, volatility, current weight (and its range over the run), share of the book's risk and correlation with the rest of the book. Use as manual weights copies the current weights into Weights › Method.
What a strategy adds to the book
A strategy is judged by what it adds to the book you run, never by how good it looks alone. From a completed portfolio test of a book, ask either:
- What does each slot add? The book is tested again as it is, and once without each slot in turn.
- What would each candidate add? The book is tested again with each of up to ten candidate strategies added: a strategy template at its own risk on the symbols you name, in a group of its own unless you name one of the book's groups. The answer is a ranking.
Every book is a full portfolio test on shared capital (competing signals, cash, the book's weights re-estimated) on the same days, ending before your sealed months. The numbers are never the book's curve plus the candidate's: a strategy that crowds another out of its room shows it. For each candidate you get the book's daily Sharpe, deepest drawdown, longest recovery and yearly growth with and without it, its correlation with the rest of the book, whether it loses together with a slot, and one verdict:
| Verdict | When |
|---|---|
| One strategy twice | it moves with a slot already in the book (an average daily correlation of 0.6 or more), whatever the Sharpe does |
| Adds value | the book's Sharpe is higher with it, and the whole 90 % range of the difference is above zero |
| Adds risk, not return | the whole range is below zero: the book is worse with it |
| Overlaps slot | the difference could be zero, and it loses together with that slot or moves with it. Judged against every slot of the book at once, so a strategy unrelated to all of them reads this at most 5 % of the time |
| Not distinguishable | the difference could be zero, either way |
The range is honest about luck: the two books are resampled on the same days, and the more candidates you compare, the wider every range gets. It aims at 90 % for the whole comparison; measured on simulated candidates that add nothing, the best of five or of ten reads "adds value" about 5 to 7 % of the time, a little more than the 5 % intended. When a book's daily returns themselves carry momentum from one day to the next, the range covers the truth about 86 % of the time instead of 90 %. A ranking orders the candidates by what each adds at worst (the low end of its range). Nothing is decided while a book is still running, failed, or ran on other days or another engine version: re-run what failed and the answer appears. The book as it is uses its own earlier test when that test ran on exactly the same days; otherwise it is tested again with the others.
Choosing a book is a search too. Every book a comparison tests is an attempt on the book's own ledger (its portfolio card; under a strategy card, every book tested under that card, whatever name each was saved under; else its saved portfolio template), never on the strategies in it. The count is shown beside the answer, and the more books you try, the more a good-looking result can be luck. A book you test without a card or a saved template cannot be compared. A strategy is charged by a book only when one of its slots runs something the strategy never ran (attempts).
Question 9 of each strategy's scorecard ("Does it improve your portfolio?") reads the "what each slot adds" comparison of the newest test that holds that version of the strategy and has one: "Adds value" is a Yes; "One strategy twice", "Adds risk, not return" and "Overlaps" are a No; "Not distinguishable" is Inconclusive. A ranking of candidates never answers it, and it never changes a strategy's label (The scorecard).
In the Portfolio Builder: Components › What each adds and Components ›
Candidates, from the open test. A comparison is priced first (how many portfolio
tests it would run and what the book's ledger holds) and runs only when you start it;
the table then shows each slot or candidate with its correlation with the book, the
book's Sharpe and deepest drawdown without → with it, the difference with its range and
the verdict, the selected row's sentence below it and the attempt count beside the
ranking. Ask it from the agent ("what does each slot add to this book?",
book_value_added, rank_candidates), the ss command line (ss portfolio value-added, ss portfolio rank) or the API.
Ensemble the plateau
When a version's neighbor settings keep its edge (its robustness battery's nearby-settings test reads on a plateau), its exact setting does not matter, and betting everything on that one setting is parameter luck. An ensemble trades the version and its nearest neighbor settings that kept the edge as ONE component of the book:
- Its members are the version and up to four neighbors that kept at least half of its edge, nearest first (a 10 % step is nearer than a 20 % one; one setting moved is nearer than two), never the best-looking ones. Each shows the share of the version's edge it kept.
- The split: each member trades at 1/k of its own risk per trade, so the k members together risk what the version alone would. They open together on a symbol inside the component's risk, the symbol counts once against the book's position limits, and the book's weights treat the ensemble as one slot.
- It sits alone in its group, taking every signal its room and risk allow; it is never an anchor and never adds to winners: a member never passes the risk budget on another member's gain, even with "A winning position may lift the limits" on. A book with an ensemble cannot use the consecutive-losses cooldown or risk reduction.
A version that is not on a plateau, whose nearby-settings test has not run, with fewer than two neighbors that kept the edge is not offered one: the answer says which, in the test's own words.
It is a version of the strategy. Test an ensemble under the version's strategy (a test under another card, or as account exploration, is refused). One ensemble per version in a book: a second slot of the same version stays as it is. A member recorded before a change in how SwingSurfer identifies configurations is refused until you re-run the version's robustness tests and take the ensemble again. Taking the neighbors' configurations picks from the version's nearby-settings grid, so every neighbor of that grid is charged as an attempt on the strategy (Attempts).
Research only. A portfolio test can run an ensemble, and "What would each candidate add?" can compare one; a saved portfolio template, an activation and a live book refuse it.
In the Portfolio Builder: Components › Slots, from the open test. Check each for a
plateau reads the grids (nothing is read until you ask); then under each slot that
runs a version of a strategy, the offer (or why there is none) and Use the ensemble for
this slot, which swaps the slot for the ensemble in a group of its own (on the slot's
symbols and weight) and points the next test at the version's strategy. Ask it from the
agent (plateau_ensemble), the ss command line (ss portfolio ensemble <run id>) or the
API (GET /api/v3/research/strategy-runs/{id}/ensemble).
Does your signal priority beat chance?
When more signals fire at the same moment than a group has room for (the book holds as many positions as it may, the risk budget is spent, or the group takes one signal per side), the engine takes them in the order of the group's ranking score. This check asks whether that order beats picking at random.
Every portfolio test now records each such moment: the signals that competed for the room, the score each one had, the risk each one would have taken, how much room and risk budget the book had left, which were taken, why the others were not (no room, no risk budget left, or, never counted as competing, a reason that had nothing to do with the rank: the group's anchor was not in a position, the adding-to-winners rule, a stop that could not be used), and how each signal's own trade turned out, after costs, in R. A skipped signal's outcome is known: each strategy's trades are worked out on their own before the book chooses among them.
The check then replays every such moment: the book's own rules for taking a signal (a free position, then the risk budget) walked through the signals in the ranking's order, against the same walk in a random order (a thousand random orders). When signals risk different amounts, the order can change HOW MANY the budget lets in (one large signal, or several small ones), and both sides follow the same rules, so neither gets a count the other did not earn. It also splits each moment's signals into the top, middle and bottom third by score. The answer is decided on later data the score never saw: the calendar years after the middle of the test's data. The years before are shown, never decided on, since a score is usually chosen on them.
| Answer | When |
|---|---|
| The ranking helps | on the later data the top-ranked picks beat the random picks (better than at least 951 of the 1,000), the thirds are in order (top above middle above bottom), and the advantage holds across the days, not just on a few |
| No better than random | the later data rules out an advantage of +0.05 R per trade or more. Sometimes the top-ranked picks did worse. Rank by a different score, or pick at random: both are honest |
| Too little contention to tell | the later data holds fewer than 20 days with more signals than room, or it can neither show an advantage nor rule one out. It says how many more such days would settle it |
A book that ranks none of its signals, or whose ranking never had to choose, says so instead. Beside the answer: each year's advantage, each ranked side's numbers, and how many times the book could not take a signal and why. Measured on simulated books, a score with no information reads "the ranking helps" about 1 to 4 % of the time (also when signals risk different amounts and the budget is tight), and a score built to carry information reads it nearly always. A score that is strong in some quarters and wrong in others reads "helps" more often than that over a few years: read the years before you keep it. Each of the book's rankings orders its signals by its own score. Each moment the check reads is one decision bar of one group, side and timeframe. Where the book's Risk Policy stopped new entries in the middle of such a moment (because of the book's own entries in it), the check replays the book's room and risk budget there, not the policy, and the answer says how many of the later moments that touched. Choosing a score is a search too: the count of books you have tested is shown beside the answer; trying scores until one helps makes the later data no longer data the score never saw.
In the Portfolio Builder: Simulation › Signal priority, for the open test. Ask it
from the agent ("does this book's ranking beat chance?", signal_priority), the ss
command line (ss portfolio signal-priority RUN_ID) or the API. A test run before
this check existed, or before portfolio engine 4 (its log was retired), has no record of
its contention moments: run it again.
A portfolio card's components
Opening a portfolio card on the Research page opens its Components: each slot of the book as last tested, with the strategy it runs (open it to see its dossier), the version of that strategy the slot runs (the version whose rules and risk the slot's template has exactly), that version's label (as the research board shows it; while the board refreshes a strategy it reads "Label unknown"), and the slot's weight: how many times its strategy's own risk its last rebalance set, and its share of the book's risk. A slot whose template no research run of a strategy holds shows no version; a card whose book was never tested shows its saved book, weights not measured until it is. The Portfolio Builder's Components › Slots shows the same table for the open test (the book as it ran), above the groups and slots being built.
Activation checks the simulation (risk-sim coherence)
The activation door verifies the policy you arm is the policy you simulated:
- Signals-only (moneyless) is never blocked, but if no completed portfolio
simulation ran the template's current Risk Policy, the activation carries a
loud warning (
risk_sim_missing), persisted on the portfolio and badged in the UI. Run a Portfolio Test with the Risk Policy enabled to clear the path forward. - Arming real execution is hard-gated. Enabling any real-execution mode
requires a completed simulation of the template's current Risk Policy (its
weights included, since live applies them). The server refuses otherwise
(
RISK_SIM_REQUIRED; there is no override). Arming is also human-only (see below). - Weights are part of the consent. The arm shows the book's weights and the most a re-estimate may raise a slot to; real orders never size a slot past it.
- Each ranking orders its own signals. A group's long ranking, its short ranking and every other group's rankings each sort by their own score, in a portfolio test and live alike. The activation freezes the book's configuration and code; the ranking itself is the engine's, so an armed book ranks exactly the way a new portfolio test of it does.
- Each signal is ranked on its own timeframe's bars. A 4h signal is scored on the 4h bar it was decided on, a daily signal on its daily bar, never on another timeframe's bar, which could close hours after the decision. A ranking compares signals decided on the same bars, so a group whose ranking scores signals (conditions or a metric) and whose slots (other than its anchor) trade on different timeframes is refused, in the Portfolio Builder and at activation, naming the group and its slots. Put each timeframe's slots in a group of their own (each group ranks its own), or turn that group's ranking off. A daily anchor with 4h slots adding to it is not refused by this rule: each set is ranked on its own bars, and each add is admitted at its own decision, so an add decided before its anchor finds no anchor open (One clock for every trade). A portfolio armed with such a ranking before this rule stops on its next evaluation: it is set to error with "Re-arm needed: ranking spans timeframes" on its card. Fix the template, then stop it and activate it again.
- Every indicator the book runs is frozen into the activation, the signal ranking's too. Activation copies the code of each indicator your strategies and your signal ranking use (the ranking may use one no slot does), through what you can see. One you can no longer see (its author unpublished it) refuses the activation, naming the module and saying when it is the ranking that reads it. A portfolio that is already armed keeps its frozen code. If a signals-only portfolio's snapshot predates a module it needs, it pins just that module at its next evaluation (the code your catalog holds then) and saves it into the snapshot (from then on it is frozen like the rest), and everything else stays as it was; its first evaluation after that catches up on the bars it could not evaluate: signals only, nothing is sent to a broker. A portfolio that can place orders is never given new code on its own: it is set to error, with a notice on its card naming what it lacks, and you re-arm it (stop it and activate the template again: a fresh start and a fresh confirmation).
- The dry-run flip is the same door. Turning
dry_runoff on an execution portfolio's settings requires the same completed simulation (RISK_SIM_REQUIRED), and execution/broker settings themselves are human-only to write: every API key is refused when it tries to authorexecution_configor rebind the exchange connection, anywhere, including at (moneyless) activation.
When a live portfolio decides
A live portfolio evaluates a bar once it is final: closed, and stored by the price feed. A crypto bar is final at its close; a US-equity bar 31 minutes after it (the feed is 15 minutes delayed). A daily bar closes at midnight UTC (the same day boundary your backtests use), so a daily US-equity portfolio decides at 00:31 UTC, the night after each session (Tuesday to Saturday), never during or just after the session, when its bar is still open.
With next-open fills (the default) an entry decided at a bar's close is signalled then, for the next session's open: the fill your backtest gives it. A daily equity entry decided at Tuesday's close is signalled at 00:31 UTC Wednesday and fills at Wednesday's open. The signal shows Tuesday's close as its price; once Wednesday's bar is in, the portfolio's signal book takes the actual open (and the stop and size re-derived there), or drops the entry when the open gapped through its stop, as the backtest does.
When a live exit fires. An exit is signalled after the bar that decided it, never later:
- an exit that fills at the next open (the default): a sell condition true at Tuesday's close is signalled at 00:31 UTC Wednesday as a market-on-open order for Wednesday's open. From that close its slot and its share of the risk budget are free, as in your backtest; its profit or loss enters the portfolio's equity once Wednesday's bar is in, at the backtest's fill (the open, or the stop's when the open gapped through it). Until then the position stays in the list of positions, its exit pending;
- a stop or trailing stop: after the bar that touched it;
- an exit that fills at the close: after its bar.
Several timeframes. A portfolio with daily and 4h strategies is evaluated one timeframe at a time, each bar once it is final, and each evaluation touches only its own timeframe's positions and signals: a 4h bar never signals, exits or moves the stop of a daily position (the daily bar sharing its time closes up to 20 hours later). When bars of several timeframes close together, the longer one is evaluated first (at 00:00 UTC a crypto portfolio's daily bar before its 4h bar), as the backtest orders them. A cooldown runs from the close of the bar that started it.
A strategy that cannot run. If the engine refuses one of the portfolio's strategies (an operand reading an output its indicator does not produce), the portfolio is set to error and its card says why: it would otherwise make no entries and no exits for the positions it holds. Fix the strategy, then re-arm the portfolio.
An evaluation that fails. If an evaluation fails for any other reason, you get an alert with a
reference to quote to support, and it is tried again at the next price update. One failure (a
brief outage) changes nothing else. If three evaluations in a row fail, the portfolio is set to
error: it sends no new order and its stops at your broker stay; once the cause is fixed, stop
it and activate it again. It never sits active while nothing is evaluated.
A bar whose data is not complete. A US-equity bar is decided only once the price feed has stored its data for every symbol of the portfolio (its last session candle, or anything after it), or has fetched that half hour successfully and found no trade in it (a thin share class that did not trade before the close does not hold the bar). If the feed missed it (an evening outage, one symbol's failed fetch), the bar waits (its card says Waiting for a whole bar and names the symbols) and it is retried at every price update; no later bar is decided before it. If it is still missing 12 hours after it was due, the bar is decided with the data stored (what a backtest of it reads) and you are told which symbols it lacked.
A stock split while you hold the stock. A position bought before a split keeps the old price
levels (entry, stop, trail). When the price feed records a split of a stock the portfolio holds
from before it, the portfolio stops being evaluated (it would read a stop breach where there is
none), waits for you (needs_reconcile) and you are alerted: check the position and its stop at
your broker, then close it with Flatten & Reset or reset the portfolio.
Every timeframe the backtester offers from 30 minutes up (30m, 1h, 2h, 4h, 8h, 12h, 1D, 1W, 1M) is decided live, on the same bars.
After a pause or an outage a portfolio catches up on every bar it missed, and their signals are
recorded, and announced once: one notice "N signal(s) recorded for bars the book missed" in the
app, one Telegram message, one webhook call ("event": "catch_up_digest", never a signal event for a
missed bar), naming each signal and, for an execution portfolio, that it was not sent as an order. The
signals-only observation that real money asks for counts the days the portfolio actually recorded
signals: a catch-up counts as the one day it ran. An execution portfolio sends only the newest bar's
decisions as orders: the moment and
the price the older ones were decided at have passed. An entry of a missed bar is never sent, nor
anything for the position it would have opened. An exit of a missed bar is never sent either: when
your broker still holds the position (under its protective stop), the portfolio waits for you
(needs_reconcile) and you are told which exits were not sent (close them at the broker, or flatten
and reset), and the newest bar's orders are held too (shown blocked_needs_reconcile); if the
portfolio cannot be set to wait, nothing of that evaluation is sent. A dry-run portfolio holds nothing
at the broker and never waits for this. A stop the broker itself executed while the portfolio was not
evaluated is recorded as the close; a trailing stop moves to the strategy's current level.
A portfolio armed before this timing existed can hold positions its strategy no longer recognizes: they never exit and they use the portfolio's capacity. Its card says Signal book out of sync and names them; re-arm it (stop it, then activate the template again).
Getting a live portfolio's signals outside the app
Every signal appears in the app. To have it reach you with the tab closed, open the portfolio's Overview and use the Notifications card:
- Telegram: paste the bot token @BotFather gave you and the chat ID, choose entries, exits or both, switch it on and press Save.
- Webhook: enter a public
https://address, choose entries, exits or both, switch it on and press Save. Each signal is posted as JSON ("event": "signal").
Nothing changes until you press Save. A stored bot token or webhook address is never shown again, to anyone: the card says Set (with the token's last 4 characters, or the address's host) and offers Replace. Replacing a webhook's address removes any headers stored for the old one.
Send a test sends one message ("SwingSurfer test notification for" and the portfolio's name) to
every channel that is switched on and saved, and shows what each one answered: Sent, or Failed with
the reason (for Telegram: check the chat ID and that the chat has started the bot; check the bot
token). A test is not a signal: it is not recorded and a webhook receives "event": "test". You can
send one test every 15 seconds.
Last signal on each channel is the delivery the server recorded for the newest signal sent there: Delivered, or Not delivered with the reason. The Signals tab shows the same record on every signal.
Through the API: PUT /api/v3/live/{id}/notifications and
POST /api/v3/live/{id}/notifications/test, both for your session or a key holding live:arm.
A live portfolio's track record
Every live portfolio keeps a track record: one row per UTC day, written once after the day's last evaluation and never changed: the database refuses any edit or deletion. Each day holds:
- The strategy's book at the day's closes: every signal the strategy emitted, whether or not a broker filled it: its equity (realized P&L plus the open positions marked at that day's closing prices), the open positions and the open risk (% of the account), the trades it closed so far and their cumulative R (trade R: each trade's P&L over the risk it took at its arrival price, the signal's own price, as the backtest measures it, never the slipped fill; a trade whose R cannot be computed is counted, never given one) and the trades it closed that day. A trade whose exit fills at the next open is closed on the day it fills, at the R of that open, never at the estimate of the close it was decided on.
- The broker account, for a portfolio with a broker connection: net liquidation, cash and the positions' value as the broker reported them, in the account's base currency, or missing, with the reason (the read failed, no session, no currency code), never a made-up number.
- Whether the day was recorded (written from the live engine's book at the end of the day) or reconstructed (rebuilt from the signal record and marked at the same closes: a portfolio that existed before the track record, or a day the job could not write at its end; the account was not read on those days). A reconstructed day books every gain and loss at the capital in force, as the live book does: after a capital change, what was booked before it scales with the capital, so the change is no gain and no loss on the record. A day is never written on a price read that failed, nor on a bar the price store should hold by then and does not (a gap in the data is never read as "not yet" for ever): it waits for the next pass, which reads it again. A day the live engine's book was at the end of when such a read failed is still written as recorded, from that book, once the read works within the day's recording window.
The Track record tab on the Live page shows the summary: return since activation and the
deepest drawdown (both % of the account, the days chained, each run from its own start; a capital
change scales the book and is no gain), the days on record against the days expected, the days
missing, how many were reconstructed, the broker reads, the trades and their cumulative R (the
same trades, every run on the record). Below it come a chart
(recorded days ●, reconstructed ○, a missing day a visible gap, never filled in) and the days
themselves. The equity curve on the Overview reads the same rows. An agent reads it with
research.get_track_record / ss portfolio track-record <id>
(GET /api/v3/live/{id}/track-record).
A live portfolio's Overview opens on how it is doing: one strip of its figures (equity, return, realized P&L, open positions, trades, win rate, risk in use, starting capital) and its equity by day; a portfolio with execution adds a second strip of its broker fills, with the risk filled at the broker. A signals-only portfolio says in one line that execution is off, with a link to Exchange connections (where a broker is connected; also in the account menu). The weights, the notifications and the rest follow. The Signals tab keeps the open positions and the signal history.
What a signals-only portfolio is worth is its track record's last day: the card, the Overview
and the Signals tab show that day's equity, return, realized and unrealized P&L, and say which close
the open positions are marked at ("as of close 6 Nov 2026"; a position whose symbol has no newer
close is counted as marked at an older one). The return is this run's, since its start, its days
chained: the Track record tab's summary chains every run on the record, so after a Flatten & Reset
the two differ (with one run they are the same number). Each open position shows its own
unrealized P&L at that mark ("not marked yet" for one the last day does not hold: opened after it,
or recorded there at a different entry or size). Before the record holds a day, no value is shown ("no marked
day yet"), never the starting capital at +0.00%. GET /api/v3/live/portfolios and
GET /api/v3/live/{id} carry it as signalBook (status marked / no_marked_day /
unavailable; a marked one names day, runStartedAt, markedThrough and staleMarks); for a signals-only portfolio currentEquity, totalReturn, totalRealizedPnl and
unrealizedPnl are that day's figures, null without one. A portfolio that executes keeps its
broker-side figures.
Orders keep their history. In the Execution tab each order's History lists every change written to it (when, which part of the system wrote it, what changed) and the broker's executions behind its fill (each partial fill with its size, price, commission and currency; a broker correction is kept as its own row and the latest counts). The order's price, size and commission are derived from those executions.
Deleting a portfolio archives it. A stopped portfolio you delete leaves your list for good and
can never be restarted (activating its template again starts a new portfolio), but nothing in its
record is destroyed: its signals, orders, executions and track record stay, read-only, and can be
read by its id (the API's include_archived=true lists it). Every change to an archived portfolio
is refused (409 PORTFOLIO_ARCHIVED).
Incubation: the record against the expected range
The Incubation tab compares the track record, day by day, with the range a backtest of exactly this book expected (the cone), and each strategy's own trades with its version's range. Ten forward days in a row below the 5% line raise a review notice. A day below the 1% line pauses the book through the ordinary pause, which never adds exposure, and asks you to review or resume. Any change to the book's configuration starts a new incubation from day 0. It answers question 8 of each version's scorecard. A book that sizes by grade falls back to flat sizing when its grade order is reversed two months in a row, and only you can restore it. See Incubation.
Adding real-money exposure is your call
Every action that adds real-money exposure is a human action in the web app with a double confirmation: arming a portfolio (activating it in an execution mode, or switching it into one), turning dry run off (or saving any setting while it is off) on an execution portfolio, raising an execution portfolio's capital, pointing it at a different broker connection, resuming it, resuming a portfolio its Risk Policy parked, resetting and restarting it, restoring sizing by grade after its incubation fell it back to flat sizing, and adding a broker connection, changing its credentials or paper/live mode, or connecting it.
- What you see. The app shows the server's own description of what will happen:
the portfolio, the broker account (paper or REAL MONEY), the capital, the
settings. It asks you to tick that you understand and to type a
confirmation: the new amount for a capital increase,
ARM <capital>to arm, the portfolio name for a resume or reset,PAPER/LIVEfor a broker connection. Resuming a parked portfolio also asks why, and records your answer. - The broker check comes first. A portfolio is armed in an execution mode (dry run
included) only after SwingSurfer has read what your broker account can do: cash or
margin, whether it can short. With no broker connected the activation is refused with
BROKER_NOT_CONNECTED(connect it under Exchange connections, or activate signals-only); if the broker does not answer (or its session is still being restored after a restart), withBROKER_PROBE_FAILED(try again in a minute). Nothing is created either way, and the reason is shown before any confirmation. The same check, on what the portfolio trades, runs when you switch a signals-only portfolio into execution, turn dry run off, or move an execution portfolio to another broker connection: refused the same way, nothing changed. - What an API key gets. Every API key (whatever its permissions,
live:armincluded, and including your own in-app agent) is refused withEXPOSURE_HUMAN_ONLY. No MCP tool, agent tool orsscommand can do any of these. - What an API key keeps. A key holding
live:armcan still take the protective actions: pause, stop, flatten-and-reset (itself a two-step confirmation), lowering capital, and disconnecting the broker. Only you, from the browser, can create such a key. - Which broker you can connect. Interactive Brokers and Alpaca (US equities), one
equity broker per account. Alpaca takes paper accounts only, and trades them only while
SwingSurfer's Alpaca paper routing is switched on: see Connecting Alpaca. No crypto exchange executes orders yet, so
adding one (or a broker connection for any market but US equities) is refused
(
BROKER_NOT_SUPPORTED) and nothing is stored. A crypto connection saved earlier stays listed, is not used, and can be removed; it cannot be changed. - Removing or disconnecting a broker connection. Without its broker session
every order of an execution portfolio is rejected, exits included, and nothing
records what fills at the broker. So Remove and Disconnect (account menu,
Exchange connections) are refused, for you and for a key alike, while an
execution portfolio that is not stopped trades through that connection: the
message names each one (
CONNECTION_IN_USE). Remove is also refused while a portfolio still holds a position (a dry run's simulated positions do not count) or has an order working at the broker: an entry, or a stop or exit of a position it holds. The message says what each one still has and what to do first. Disconnect stays available once the portfolios are stopped, and says which ones it leaves with stops resting at the broker and no fills recorded until you reconnect; switching a connected account between paper and live says the same. You have one broker session, so on an Interactive Brokers connection that is not disconnected every such portfolio counts, whichever connection it is bound to. Stop the portfolio, then close what it holds with Flatten & Reset (connected first). It closes every position on the whole broker account, not only that portfolio's. Wait for a closing order to fill, then remove. - Changing a portfolio's broker account. In Execution settings the account is part of the form like every other field: picking one changes nothing, and closing the form drops the choice. Saving asks first, naming the portfolio, the account it moves to and the one it uses today. An execution portfolio is then confirmed like any other change of exposure.
Connecting Alpaca
Alpaca is a US broker you connect with an API key: a key id and a secret you create in Alpaca's dashboard and paste into SwingSurfer. Nothing else is installed or kept open.
Create a paper key. Sign in at alpaca.markets, switch the dashboard to your Paper account, and open the API keys panel on its home page. Generate a key: Alpaca shows the key id and the secret once, so copy both straight away (if you lose the secret, generate a new key).
One equity broker at a time. Your account holds one equity broker connection: Interactive Brokers or Alpaca. With Interactive Brokers saved, Exchange connections shows Switch to Alpaca. It asks first, then removes the Interactive Brokers connection: the IBKR session ends and its saved login is deleted. It is refused, with each portfolio named and what to do first, while an execution portfolio that is not stopped trades through it, or a portfolio still holds a position or has an order working there. A signals-only portfolio keeps producing its signals; one bound to the removed connection loses that binding (it is left with no broker account) and can be bound again in its Execution settings. Switch to Interactive Brokers works the same way from Alpaca.
Paste it. Account menu, Exchange connections: with no equity broker saved, pick Alpaca,
paste the key id and the secret, and choose Check and save the key. SwingSurfer asks you to
confirm (type PAPER), then reads your Alpaca account with the key before it stores
anything:
- Alpaca refuses the key:
BROKER_KEY_REJECTED, nothing stored. A paper key works only in Alpaca's paper environment, so check you copied the paper account's key. - Alpaca does not answer:
BROKER_UNREACHABLE, nothing stored; try again in a minute. - Alpaca answers: the key is stored encrypted. It is never shown again, never sent back to your browser and never written to a log: the panel shows its last four characters, and the account as Alpaca reports it (status, equity, buying power, margin and shorting, whether it can trade). Alpaca retired its pattern-day-trader flag in 2026, so the panel says "not reported" when Alpaca sends none.
Paper only, for now. A real-money Alpaca key is refused (ALPACA_LIVE_NOT_OPEN):
"Real-money Alpaca trading opens after the paper run is on record". Nothing is stored.
Trading on Alpaca paper. An execution portfolio on your Alpaca paper account trades
as on Interactive Brokers, with one difference: a LIMIT entry with a protective stop is
refused by name (Alpaca would keep that entry working past the close with its stop), so
use market or next-open entries there. Next-open entries go to Alpaca's opening auction (sent
between 09:20 and 09:28 New York; a signal that misses that window is never sent, as on
IBKR), each entry carries a protective stop that rests good till cancelled, a trailing stop
is moved up at Alpaca (never down), exits, Pause, Stop and Flatten & Reset work the same,
and the Execution tab shows each fill at Alpaca's price. Alpaca reports no commission on a
fill, so the commission shows n/a ("not reported"), never 0. Arming one asks for the same
confirmation as any broker. This routing is new and switched on by SwingSurfer for its paper
run: while it is off, arming a portfolio on Alpaca is refused with BROKER_NOT_ROUTED, and
nothing changes. A real-money Alpaca account is refused either way.
Delete the keys or remove the connection. Delete the keys removes the stored key id and secret (the connection stays, and you can paste a key again); Remove deletes the connection. Both ask first, and both are refused while an execution portfolio that is not stopped is bound to it, as for any broker. To change keys, paste the new ones and choose Replace the key: Alpaca checks them first. If you revoke a key in Alpaca, the panel shows the connection in error at the next check.
Reading the Execution tab
The Execution tab (and GET /api/v3/exchange-connections/orders/{portfolio_id} /
…/summary) lists what your broker actually did. A few figures are not known the moment
a fill happens, and the tab says so rather than rounding them into certainty:
- Commission is reported by the broker after the fill. The Commission figure sums
the commissions reported so far:
$3.40+means "at least this much: N fills have no commission recorded yet" (hover or focus it for the count), andn/ameans none has been reported. It is never shown as free. The API says the same withtotal_commissionandunrecorded_commission_fills; the total is the whole cost only when that count is 0. The Performance Decomposition's Commission row works the same way. - A modeled price. A position closed by the broker's resting stop can be saved before
the broker reports the stop's fill; its price is then the strategy's stop level, marked
modeled, and is replaced by the broker's price automatically once it is reported (the equity curve says how many of its fills still use a modeled price). - Flatten & Reset closes. Flatten & Reset closes every position on your broker
account, also those another of your portfolios holds on the same account; the confirmation
lists them. Each close is recorded on the portfolio that holds the position (a position no
single portfolio holds is recorded on the flattened one, marked unowned). Another portfolio
whose positions were closed this way has its stops for them cancelled first, waits for you
(
needs_reconcile), and you are alerted. Running Flatten & Reset on any portfolio of the account cancels every flatten close still working on that account before it closes again. Because it acts on the whole account, Flatten & Reset is refused for a signals-only portfolio whose records show no position at your broker, preview and execute alike (409 FLATTEN_SIGNALS_ONLY, nothing changed): from it a flatten could only close what your other portfolios and you hold. Its control on the Live page is disabled and says why. Use Stop to end such a portfolio: it cancels an entry order still waiting. A stop or exit order of the portfolio still working at your broker is cancelled at your broker. A portfolio switched to signals-only that still holds broker positions keeps Flatten & Reset. The same holds for a portfolio running its execution as a dry run whose records show no position at your broker (409 FLATTEN_DRY_RUN_BOOK, nothing changed): the refusal names the portfolios whose records show a position at your broker, the ones to run Flatten & Reset from (or tells you to close at your broker when there is none). A dry-run portfolio that still holds broker positions (switched from real orders) keeps Flatten & Reset. Each closing order Flatten & Reset sends is an order like any other: it appears in the order list (taggedFLATTEN; no strategy signal produced it), gets its commission and execution time, and counts in the fill statistics and the realised P&L. After hours the close is a market-on-open order that stayssubmittedat the broker until the open. The portfolio keeps that position (marked as closing, with no stop beside its close) until the close fills; you cannot delete it meanwhile. If the broker rejects or cancels the close at the open, SwingSurfer protects the position again with one protective stop, the portfolio waits for you (needs_reconcile), and you get an alert naming the stop: run Flatten & Reset again. Pausing or stopping the portfolio leaves that close working (cancelling it would leave the position open). Running Flatten & Reset again cancels it and re-reads your broker before closing what is left. A position whose protective stop (or another closing order) the broker would not confirm cancelled is NOT closed: a close beside it could sell twice. The result names the order to cancel at your broker, you get an alert, the flatten never reads as flat, and the portfolio keeps that position (with its stop) and waits for you (needs_reconcile) instead of stopping. Cancel the named order at your broker, then run Flatten & Reset again: it cancels every protective stop SwingSurfer placed before it closes what your broker holds. Closing the position at your broker alone can leave one of those stops working. While it waits, SwingSurfer never places a new stop for that position. A protective stop that had already filled when Flatten & Reset came to cancel it is not a failure: the result lists it under the stops that had already filled, and its order shows the fill (or names the exit that recorded it). The Performance Decomposition counts these closes separately (they answer to no signal, so they are in none of its buckets). - Rejections are split three ways: blocked by mode (your allowed-sides setting),
policy (an engine safety rail: an entry it cannot size in whole shares,
Adjusted shares = 0; an entry of a portfolio that is not trading; an exit while Flatten & Reset closes the portfolio; or a venue that cannot carry the order, for example a crypto symbol) and error (the broker or the connection failed). The fill rate leaves out mode blocks, policy refusals and dry runs (none of them is an order that was tried at the broker) and counts errors against it. No order of 0 shares is ever queued or sent. - Pause and stop cancel entries only. Pausing or stopping a portfolio cancels its working
entry orders. Its protective stops stay, and so does an exit already working at your broker:
the exit lifted the position's stop when it went out, so cancelling it would leave the position
without one. Until it fills, that position has no stop; if your broker ends the exit without
filling it, a protective stop is placed for what is still held (paused or stopped alike) and
you are notified. A next-open exit stays queued with the stop still armed, and goes out at the
open whether the portfolio is active, paused or stopped by then: the strategy left that
position when it decided the exit, and an exit only closes it (its stop is cancelled first).
A portfolio switched to signals-only or to dry run sends no orders, so its queued exit is not
sent (below): the position stays at your broker under its stop. Close it yourself. The
response lists each order left working and why. An
entry the portfolio decided before you paused, stopped or flattened it is never sent: it shows
rejectedwithEntry not sent: the book is paused(or stopped, stopping); if one reached your broker in the very moment you paused, you are told which order to cancel. - A queued order goes out only as it was queued. An order waiting for the next open
records how the portfolio was set when it was queued (its mode, whether it was a dry run,
the broker connection it is bound to) and the broker account it would go out on. It is
sent only while all of that is still the same and none of those settings was changed in
between. Switching the portfolio to dry run or to signals only, or binding it to another
connection, cancels it, even if you switch back before the open; so does reaching the open
through another broker connection or another account (the order is never sent there). It
shows
cancelled, withNot sent: queued under another execution stateand what changed; nothing reaches any broker for it. A cancelled next-open exit leaves its position at the broker that holds it, under its stop, and you are notified to close it there. Changing the account behind a connection (new credentials, paper to live or back) is refused while one of its portfolios has an order waiting for the open or working at the broker: wait for it to fill or end, or stop the portfolio first. An order the portfolio decided before you switched to dry run or to signals only, and that was still waiting to be placed, is not sent either: it showsrejectedwithNot sent: the book no longer sends real orders, and an exit refused that way is handed to you to close. - A partial fill before a cancel. When the broker fills part of an order and then cancels
the rest (or fills part of it before your pause, stop or flatten cancels it), the order shows
cancelledwith the size that filled: those shares, their executions and their commission are on record and count in the commission figures (partially_filledin the summary) and in the execution performance. An entry's filled shares become the position; an exit's remainder is re-protected with a stop of its size and the portfolio waits for you. - Every protective stop is on record. Each stop SwingSurfer places (the entry's, one it
places for a position that lost or never had one, one it re-arms after an exit that did not
close) is an order in the Execution tab, so every close (an exit, a Risk Policy flatten,
Flatten & Reset) cancels it before closing, and an exit is never sent while a stop it could not
cancel may still act: the order says
Exit not sentand the portfolio waits for you. Only the position's own stops count: the stop of an earlier trade in the same slot is never mistaken for the current one's. A stop that fired and closed its position showscancelledwith the note "…, filled at the broker; its fill is recorded on the exit row" when the exit row carries that fill, orfilledwith its own fill when no exit records the close (for example after a reset). If SwingSurfer places a stop and then cannot keep it on record and cannot cancel it, you get an alert naming the order to cancel at your broker: a close of the position may not cancel it for you. - A market-on-open order that missed its open. A market-on-open order is for one opening
auction (the first one after its signal's bar), and the exchange takes such orders until
09:28 New York. If it could not be sent by then (the system or the broker connection was
down), it is never sent later: it shows
rejectedwithMOO expired, not submitted, and you are notified within minutes. For an exit, the position is still held at your broker under its protective stop (re-placed first if the exit had already lifted it; if that fails, the order and the notice say so), the portfolio waits for you (needs_reconcile) and its other orders that morning are not sent either. Exits are always sent before entries. - An exit that filled only in part. If a market-on-open exit sells only part of the position before the broker cancels the rest, the order keeps the part that filled, the shares still held get a protective stop of their own size, and the portfolio waits for you.
- An exit the broker closed first. When a position's protective stop fires at the open
before its market-on-open exit, the exit shows
filled_at_broker_stopwith the stop's real fill and no second order is sent. If the broker cannot confirm what happened, the portfolio waits for you (needs_reconcile) and you are notified rather than the system guessing. - An entry sized at the open as the test sizes it. A market-on-open entry is sized just
before the open from the risk its signal decided (in dollars, with your position cap) and
the distance from the pre-market price to its stop (the way the backtest sizes a fill at
the open), and never above the shares the signal decided. If the pre-market price is already
at or through the stop, nothing is sent (the backtest takes no trade there either): the order
shows
rejectedwith "research takes no trade". A protective stop that has to be placed again (the broker lost it, an exit did not close the position) goes back at the level the stop held: a trailed stop's, never the looser entry stop. - An exit that could not be sent at the open. If a portfolio holding a position needs
your attention (
needs_reconcile), is inerror, or was switched to signals-only before its market-on-open exit, the exit is not sent: the system's view of the position may be wrong. The position keeps its protective stop at your broker, and you are notified: close it with Flatten & Reset (or at your broker). The exit is not sent again later.
Live enforcement (E-C)
When you activate a portfolio, its Risk Policy is frozen into the activation
snapshot (the same snapshot that pins the strategy/runtime config, covered by the
config_hash). From then on the armed policy is the simulated policy, frozen:
- Immutable while armed. Editing the template's Risk Policy afterward does not change the running portfolio: the live engine reads the frozen snapshot, not the editable template. To change an armed policy: edit → re-simulate → re-arm (a new activation re-freezes a fresh snapshot).
- What automation can and cannot do. No endpoint edits an armed policy in place,
and everything that adds exposure is yours alone (above). Pausing, stopping and
flattening a live portfolio are gated by the
live:armpermission plus ownership, and an API key can hold that permission. Treat a key carryinglive:armas able to take those protective actions on a running portfolio. - Enforced every bar, most-restrictively. The live engine evaluates the frozen rungs against your live account each bar on the same marked basis as the backtest (realized + unrealized), and composes with the existing cooldown / risk-reduction so the tightest control wins; it never loosens your risk. On any evaluation error it fails safe by blocking new entries.
flatten_and_parkparks until you resume it. A park firing flattens the whole book and parks the portfolio. It keeps blocking every new entry (a reconcile reset keeps the park) until you resume the portfolio from its Risk Policy card (with a written reason and the confirmation) or re-arm it. Resuming restarts the policy from your current equity, so every rung, the park included, can fire again.- Read-only + history. The live page shows the frozen policy read-only, a firing history (which rung fired, when, the observed value vs its threshold, and the action taken) and every resume after a park with the reason you gave.
- Reset keeps the record. Resetting a reconcile-blocked portfolio archives its
signal history instead of deleting it; the live page shows the new run, and the
API returns the archive with
include_archived=true. Market-on-open orders the previous run queued but never sent are cancelled, so none of them fires into the new run; orders already at your broker are left alone (the confirmation counts them: use Flatten & Reset to close those).