ProBacktest/probacktest · proorder

MAXORDER

MAXORDER is a DEFPARAM setting in ProBacktest and ProOrder that caps the size of any single order. Orders above the limit are clipped to the maximum size.

Syntax

probuilder
DEFPARAM MAXORDER = value

Parameters

NameTypeDefaultDescription
valuenumericnoneMaximum number of units, contracts, or lots allowed in a single order.

How it works

DEFPARAM statements configure the execution environment of a strategy and must appear at the top of the code, before any executable instruction. MAXORDER is one of these settings: it defines an upper bound on the quantity of a single order.

The cap applies at order level, not position level. Whenever an order statement produces a quantity above the configured value, the engine executes the maximum allowed size instead of rejecting the order. A dynamically sized order of 25 contracts under DEFPARAM MAXORDER = 10 fills as 10 contracts.

The main use case is realism. Formula-driven position sizing, for example dividing available capital by price, can produce order sizes that no broker or market would absorb at one price. Capping the single-order size keeps a backtest closer to executable conditions and protects a live system against a runaway sizing formula.

Because the limit is per order, a strategy that accumulates positions with DEFPARAM CumulateOrders = true can still build a total position larger than MAXORDER across several orders.

Examples

Example 1, Capping order size at ten units (ProBacktest)

probuilder
// no single order may exceed 10 units
DEFPARAM MAXORDER = 10

IF NOT OnMarket AND close crosses over Average[50](close) THEN
  BUY 20 CONTRACTS AT MARKET
ENDIF

The strategy requests 20 contracts, but the MAXORDER setting clips the order to 10. The backtest therefore simulates the constrained size, not the requested one.

Example 2, Guarding a capital-based sizing formula (ProOrder)

probuilder
DEFPARAM MAXORDER = 5

// size grows with capital but can never exceed 5 contracts per order
positionsize = MAX(1, ROUND(strategyprofit / 10000))

IF NOT OnMarket AND RSI[14](close) < 30 THEN
  BUY positionsize CONTRACTS AT MARKET
ENDIF

The sizing formula scales with accumulated profit. MAXORDER acts as a hard ceiling, so a large equity value cannot push a single order beyond 5 contracts.

Example 3, Order cap with position accumulation (ProBacktest)

probuilder
DEFPARAM CumulateOrders = true
DEFPARAM MAXORDER = 2

// add on each pullback to the 20-bar average, 2 contracts at most per order
IF close crosses over Average[20](close) AND CountOfPosition < 6 THEN
  BUY 2 CONTRACTS AT MARKET
ENDIF

Each individual add-on order respects the 2-contract cap, while the accumulated position can reach 6 contracts across three orders. The cap constrains orders, not the total position.

Common errors and gotchas

  • Clipping is silent. Orders above the cap are reduced, not rejected, and no warning is produced. A backtest can quietly trade smaller sizes than the sizing formula suggests, which distorts profit expectations if the clipping goes unnoticed.
  • Per order, not per position. With CumulateOrders enabled, several capped orders can stack into a position far larger than MAXORDER. Limiting total exposure requires an explicit check on CountOfPosition or equivalent.
  • DEFPARAM placement. All DEFPARAM statements must come before the first executable line of the strategy. A DEFPARAM MAXORDER placed after other code fails to compile.
  • Not a broker limit. The setting constrains what the strategy sends, it does not model exchange or broker maximums. Live orders within MAXORDER can still exceed a broker's own size limits.
  • MINORDER, minimum order size executed during a backtest.
  • DEFPARAM, declares strategy-level execution parameters.
  • CumulateOrders, allows several orders to accumulate into one position.
  • BUY, opens or adds to a long position.
  • SELLSHORT, opens or adds to a short position.
  • LOT, order quantity expressed in lots.
  • CONTRACT, order quantity expressed in contracts.
  • SHARES, order quantity expressed in shares.