Risk and exposure limits¶
size: describes a desired position or portfolio objective. A top-level risk: declaration places supported exposure caps on that objective. Price protection and planned stop-loss sizing are separate decisions.
Read the two supported caps¶
risk: max 20% per instrument, gross <= 60%
| Part | Meaning |
|---|---|
max 20% per instrument |
Limit one instrument's exposure. |
gross <= 60% |
Limit combined absolute exposure across the strategy. |
Use either cap alone or both, separated by a comma. Percentages must be positive and at most 100%. Declare each cap kind once. The cap basis follows current marked strategy equity, with the configured Max capital ceiling if present; it is distinct from selecting a starting-capital basis for the size objective.
With current equity of 10,000 and no extra ceiling, a 20% instrument cap corresponds to 2,000, and a 60% gross cap to 6,000 before execution constraints. Long 2,000 and short 2,000 consume 4,000 of gross exposure; their net exposure of zero does not make the gross cap irrelevant.
Add caps to independent signals¶
//@version=1
universe: [AAPL, MSFT, NVDA, AMZN]
run: daily
size: 10% of portfolio per instrument
risk: max 15% per instrument, gross <= 30%
entry:
long when: close > ema(20)
exit:
long when: close < ema(20)
Four simultaneous independent targets desire 40% combined, but the gross cap restricts admitted exposure to 30%. Which orders can be admitted depends on existing holdings, pending increases, costs, quantities and the run's ordering. Do not assume all four receive an equal 7.5% share: this is independent sizing with a cap, not a shared allocator.
A statically contradictory declaration such as size: 20% per instrument with risk: max 10% per instrument is rejected. Make the target and cap compatible rather than relying on a cap to repair contradictory intent.
Allocation, planned loss and protection¶
| Declaration | What its percentage measures |
|---|---|
size: 5% per instrument |
Desired allocation for each entry. |
size: risk 1% with stop 5% |
Planned 1% loss budget with a 5% price-stop distance. |
stop: 5% |
Price movement from entry. |
risk: max 20% per instrument |
Maximum instrument exposure. |
risk: gross <= 60% |
Maximum combined absolute exposure. |
A gross cap does not create a combined planned-stop-risk cap. Three trades each sized to a 1% planned loss budget can represent approximately 3% planned open risk. Stops and caps do not guarantee a realised loss bound through gaps or changing prices.
What a cap changes¶
Known caps constrain increases along with available strategy capacity. Percentage targets can be reduced to fit known limits. Fixed quantities, lots and stop-risk need their full calculated target or skip under known local limits. Pending increases reserve capacity; a requested reduction does not free capacity until execution and settlement permit it.
Continuing independent holdings are not automatically resized to fund another entry. Price drift can also move an existing holding above a cap; the declaration is not a separate instruction to sell on every price change. Target-book strategies have deliberate rebalance semantics. Inspect desired amounts, admission outcomes and confirmed fills separately.
Stay within the supported grammar¶
This risk: section currently accepts the instrument and gross caps above. Daily-loss, sector, beta-neutral, combined planned-risk and advanced solver declarations are not additional supported phrases here. Python has separate read-only risk helpers, whose actions must be explicitly authored.
Next topic Trade several instruments →