CONTRACT
CONTRACT is a ProBacktest and ProOrder quantity unit that sets order size in contracts, as in BUY 5 CONTRACTS AT MARKET, interchangeable with SHARES or LOT.
Syntax
x CONTRACTUsed inside an order instruction:
BUY 5 CONTRACTS AT MARKETParameters
| Name | Type | Default | Description |
|---|---|---|---|
x | numeric | 1 on entry, full position on exit | Number of contracts for the order. Accepts literals or numeric expressions. |
How it works
CONTRACT declares how many contracts an order trades. It carries no direction of its own: BUY 5 CONTRACTS AT MARKET opens or adds to a long, SELLSHORT 5 CONTRACTS AT MARKET opens or adds to a short, and SELL 2 CONTRACTS AT MARKET reduces a long by two contracts.
The keyword is one of several interchangeable unit words. SHARE, CONTRACTS, PERPOINT, LOT and LOTS are accepted in the same position on any instrument type, and singular or plural spelling makes no functional difference. On Forex the stated quantity is multiplied by the size of one lot.
When no quantity is given, defaults apply. An entry order such as BUY AT MARKET trades one unit. An exit order such as SELL AT MARKET or EXITSHORT AT MARKET closes the entire open position, whatever its size.
The quantity may be a variable, which is how position sizing rules, for example a contract count derived from volatility or from account equity, are wired into the order flow.
Examples
Example 1, Fixed five-contract entry (ProBacktest)
long = close crosses over Average[50](close)
IF NOT LongOnMarket AND long THEN
// Order size fixed at five contracts
BUY 5 CONTRACTS AT MARKET
ENDIF
SET STOP PLOSS 40The moving average cross triggers a long entry of exactly five contracts, the size given by the CONTRACT unit.
Example 2, Volatility-scaled contract count (ProOrder)
DEFPARAM CumulateOrders = false
// Fewer contracts when the market is volatile
atr = AverageTrueRange[14](close)
n = MAX(1, ROUND(200 / atr))
IF NOT OnMarket AND RSI[14](close) crosses over 50 THEN
BUY n CONTRACT AT MARKET
ENDIF
SET STOP %LOSS 2The contract count is a variable recomputed each bar: a calm market allows more contracts, a volatile one fewer, with a floor of one.
Example 3, Partial exit in contracts (ProOrder)
DEFPARAM CumulateOrders = false
IF NOT OnMarket AND close crosses over Highest[20](high)[1] THEN
BUY 4 CONTRACTS AT MARKET
ENDIF
// Bank half the position after a favorable move, keep the rest running
IF LongOnMarket AND close >= TRADEPRICE * 1.02 THEN
SELL 2 CONTRACTS AT MARKET
ENDIF
SET STOP %TRAILING 1.5Stating a quantity on the exit order closes only that many contracts, here two of the four, while the remainder stays open under the trailing stop.
Common errors and gotchas
- CONTRACT sets size, not direction. The keyword never opens or closes anything by itself. The surrounding instruction,
BUY,SELL,SELLSHORTorEXITSHORT, decides the side of the trade. - Forex lot multiplication. On Forex instruments the quantity is multiplied by the lot size, so
BUY 1 CONTRACTtrades one full lot, not one unit of currency. Check the instrument's lot definition before sizing. - Unstated quantities fall back to defaults.
BUY AT MARKETquietly trades one unit andSELL AT MARKETcloses the whole position. A missing number is not an error, so a typo that drops the quantity changes the position size without warning. - Fractional counts are rounded. A computed expression such as
capital / pricerarely yields an integer. Wrap sizing formulas inROUND, or add an explicit floor, to keep the requested quantity deliberate.
Related instructions
CASH, order quantity as a money amount.LOT, order quantity in lots.SHARES, order quantity as a number of shares.BUY, opens or adds to a long position.SELL, closes or reduces a long position.SELLSHORT, opens or adds to a short position.EXITSHORT, closes or reduces a short position.MARKET, immediate execution at the current price.COUNTOFPOSITION, size of the open position in units.
