ProBacktest/probacktest · proorder

CASH

CASH is a ProBacktest and ProOrder quantity unit that sizes an order by money amount, as in BUY 1000 CASH, instead of a fixed number of shares or contracts.

Syntax

probuilder
BUY x CASH

Parameters

NameTypeDefaultDescription
xnumericnoneAmount of capital to allocate to the order, in the account's currency. The platform converts it into a quantity at the current price.

How it works

CASH replaces a unit count in an order instruction. Where BUY 5 CONTRACTS AT MARKET fixes the quantity, BUY 1000 CASH AT MARKET fixes the capital and lets the platform derive the quantity by dividing the cash amount by the instrument price. The resulting exposure stays close to the requested amount regardless of whether the instrument trades at 8 or at 800.

Because a cash amount rarely divides into a whole number of units, the computed quantity is rounded. The rounding direction can be forced with ROUNDEDDOWN or ROUNDEDUP immediately after the CASH keyword, for example BUY 1000 CASH ROUNDEDDOWN AT MARKET never spends more than the stated amount.

The amount can be a literal or any numeric expression, which makes CASH the natural unit for equity-proportional sizing: recompute the allocation from starting capital plus STRATEGYPROFIT and each trade automatically scales with the account. CASH is interchangeable with the other quantity units, CONTRACT, SHARES and LOT, in the same order syntax.

Examples

Example 1, Fixed capital allocation per trade (ProBacktest)

probuilder
long = close crosses over Average[50](close)
IF NOT LongOnMarket AND long THEN
    // Allocate 1000 of account currency, whatever the share price is
    BUY 1000 CASH AT MARKET
ENDIF
SET STOP %LOSS 3

Each entry deploys the same 1000 units of capital. On a 50-priced stock that is about 20 shares, on a 250-priced stock about 4 shares, keeping exposure constant across instruments.

Example 2, Equity-proportional sizing with rounding control (ProOrder)

probuilder
DEFPARAM CumulateOrders = false

// Reinvest gains: allocation grows and shrinks with realized performance
startCapital = 10000
allocation = (startCapital + STRATEGYPROFIT) * 0.2

IF NOT OnMarket AND RSI[14](close) < 30 THEN
    // Round down so the order never exceeds the allocation
    BUY allocation CASH ROUNDEDDOWN AT MARKET
ENDIF
SET STOP %LOSS 2

The order size is 20 percent of current equity. ROUNDEDDOWN guarantees the computed quantity stays within the budget.

Example 3, Cash-sized short entry (ProOrder)

probuilder
bearish = close crosses under Average[100](close)
IF NOT ShortOnMarket AND bearish THEN
    // Commit 500 of capital to the short side
    SELLSHORT 500 CASH AT MARKET
ENDIF
SET STOP %TRAILING 2

CASH works with short entries as well; the platform sells short as many units as 500 currency units cover at the current price.

Common errors and gotchas

  • Quantity rounding surprises. The cash amount is converted to a whole number of units, so the actual exposure differs slightly from x. On high-priced instruments the gap can be large; BUY 1000 CASH on an 800-priced share buys a single share. Use ROUNDEDDOWN or ROUNDEDUP to control the direction.
  • Amount below one unit. If x is smaller than the price of one unit and rounding goes down, the computed quantity can be zero and no order is placed. Guard the allocation with a minimum before the order line.
  • Not a stop-loss instruction. CASH sizes entries; it does not cap losses. Limiting the money lost on a trade is the job of SET STOP $LOSS.
  • Exits usually need no quantity. SELL AT MARKET closes the whole position. Re-stating a cash amount on exit closes only the computed quantity, which can leave a residual position when the price has moved since entry.
  • CONTRACT, order quantity as a number of contracts.
  • LOT, order quantity in lots.
  • SHARES, order quantity as a number of shares.
  • BUY, opens or adds to a long position.
  • SELLSHORT, opens or adds to a short position.
  • ROUNDEDDOWN, rounds a cash-derived quantity down.
  • ROUNDEDUP, rounds a cash-derived quantity up.
  • MARKET, immediate execution at the current price.
  • STRATEGYPROFIT, realized profit of the strategy, useful for equity-based sizing.