Documentation/AlgoCode/Function reference
risk
Initial quantity from a percent of initial capital and the stop distance.
risk 1 percent
risk amount = initial capital × N / 100. quantity = risk amount / stop distance. The capital is initial capital, default 100000, after a backtest capital override. It is not running equity. The quantity is calculated at the simulated fill, from that fill and the initial stop, and it is not changed by a later trail or breakeven. stop N points, stop N with no unit, and stop N atr (after the existing series ATR becomes points) use a constant distance. stop N percent uses fill × N / 100, the same percent-stop distance as the protective stop. The engine keeps the raw division. It does not round to an integer or a lot. A missing stop, stop 0, stop at, or an ATR stop that does not resolve keeps qty and warns. risk 0 percent and risk -1 percent are rejected. risk 100 percent and higher are accepted. A same-side re-entry still adds qty. The webhook qty field receives the initial risk quantity.
Return value
—
Note
- Entry 100 and stop 95 size 200, because 1000 / 5 = 200. A short with stop 105 sizes 200 the same way.
- stop at is not a sizing distance. risk 1000 and risk 1 points are not accepted.
Example
initial capital 100000 risk 1 percent stop 5 points when close > 0 and flat buy