strategy.risk.max_position_size() - Pine Script Function
strategy.risk.max_position_size()
Section titled “strategy.risk.max_position_size()”Overview
Section titled “Overview”The purpose of this rule is to determine maximum size of a market position. The rule affects the following function: strategy.entry. The ‘entry’ quantity can be reduced (if needed) to such number of contracts/shares/lots/units, so the total position size doesn’t exceed the value specified in ‘strategy.risk.max_position_size’. If minimum possible quantity still violates the rule, the order will not be placed.
Syntax
Section titled “Syntax”strategy.risk.max_position_size(contracts) → voidParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| contracts | simple int/float | A required parameter. Maximum number of contracts/shares/lots/units in a position. |
Examples
Section titled “Examples”Example 1
Section titled “Example 1”//@version=6strategy("risk.max_position_size Demo", default_qty_value = 100)strategy.risk.max_position_size(10)if open > closestrategy.entry("buy", strategy.long)plot(strategy.position_size) // max plot value will be 10