Hold a portfolio¶
Use hold: when you describe a target portfolio rather than separate entry and exit signals.
Equal weights¶
//@version=1
universe: [AAPL, MSFT, NVDA, AMZN]
run: monthly
size: 80% in total
hold: equal weight
This requests one 80% budget shared by four names. Each desires 20% of the strategy portfolio basis before constraints and rounding. Monthly evaluation can rebalance the target portfolio.
hold: equal weight selects the whole fixed list and supplies the equal split itself, so no separate allocate: is needed. With a basis of 10,000, the desired book is 2,000 per name and 2,000 outside the allocation. Costs, limits and rounding can change the achieved amounts.
size: 80% has the same shared-budget meaning in a hold strategy. size: 20% per instrument instead requests 20% for every selected name; the total then depends on how many names are selected.
Select by a score¶
//@version=1
universe: [AAPL, MSFT, NVDA, AMZN]
run: monthly
size: 80% in total
allocate: equal weight
hold: long top half by momentum
top half selects two names by the supplied momentum score. They share the budget. The score must be available in the running environment; a catalog name does not itself supply data.
Membership versus allocation¶
hold: answers which instruments should be held. allocate: answers how the selected instruments share the budget. In the example, two names share 80% equally, so each desires 40% of the basis.
| Selection | Meaning |
|---|---|
hold: long top 2 by momentum |
Select the two highest-scoring eligible names. |
hold: long top half by momentum |
Select the upper half of the eligible list. |
hold: long bottom 2 by momentum |
Select the two lowest scores, still as long positions. |
hold: short top 2 by momentum |
Select the highest two scores as shorts, subject to instrument/account support. |
top and bottom describe ranking, not trade direction. Use long or short to choose direction. A count must be a positive integer. Selection operates on the eligible list, so using an even-sized list makes top half easy to interpret.
You may replace the supplied score with a named calculation from reusable definitions. Every input still needs appropriate data. Equal allocation is the default for a ranked shared percentage book; allocate: inverse volatility over 63 bars changes the relative weights using valid signal-bar history. Dictionary allocation with hold is currently unsupported.
What a rebalance changes¶
On an eligible evaluation, a hold strategy can close names that leave the selection, enter new members, and resize continuing members to their targets. A selected name whose score changes is not necessarily removed: its rank relative to the other names determines membership.
Use entry: / exit: when each position should follow its own signal lifecycle. Use hold: when the whole portfolio should follow a target selection and allocation. Protection and sizing combinations have additional constraints; consult sizing details.
Choose one strategy shape¶
Do not mix independent entry: signals with hold:. exit: clauses on a hold strategy are ignored with a warning. Membership and the target portfolio govern this form.
Use a fixed eligible list. Dynamic universes, pairs, options and advanced solver forms are outside the supported authoring path. See supported features.
Choose a fraction or an exact count¶
Supported fraction words are half, third, quartile, quintile and decile. They divide the full eligible list size by 2, 3, 4, 5 and 10 respectively, round down and select at least one. For five eligible names, top half requests two; for three names, top quartile requests one. An exact count such as top 2 is capped by the list size.
These are selection counts, not money percentages. A two-name selection sharing an 80% budget differs from two independent 80% targets. Missing score inputs can prevent the intended selection; inspect the actual scores and membership rather than assuming every eligible name was rankable.
Select by a condition¶
//@version=1
universe: [AAPL, MSFT, NVDA, AMZN]
run: daily
size: 40% in total
allocate: equal weight
hold: long where close > ema(50)
This selects names whose own close is above their 50-period EMA, then shares one 40% target budget among the selected members. The selection is evaluated as a portfolio target. It can add or remove membership and resize continuing names on an eligible evaluation; it does not give each new entry a permanently independent allocation.