ProBacktest/probacktest · proorder

SELLSHORT

SELLSHORT in ProBacktest and ProOrder opens a short position at market or with pending orders. SELLSHORT opens shorts while SELL closes longs. Examples inside.

Syntax

probuilder
SELLSHORT quantity SHARES AT MARKET
probuilder
SELLSHORT x CONTRACT AT MARKET
probuilder
SELLSHORT x CONTRACT AT price LIMIT
SELLSHORT x CONTRACT AT price STOP

Parameters

NameTypeDefaultDescription
quantitynumbernoneNumber of units to short. The unit keyword that follows, SHARES, CONTRACT, or LOT, matches the instrument type.
pricenumbernoneTrigger level for the pending LIMIT or STOP forms.

How it works

SELLSHORT is the short-side entry instruction. SELLSHORT quantity SHARES AT MARKET opens a short position of the stated size at the next available price. The unit keyword adapts to the instrument, SHARES for stocks, CONTRACT for futures and CFDs, LOT for forex.

Pending forms are also available. SELLSHORT ... AT price LIMIT waits to short at a stated level or better above the current market, entering into strength. SELLSHORT ... AT price STOP shorts once price falls through a level below the market, a breakdown entry. As with all pending orders in ProBacktest and ProOrder, an order that is not filled by the end of the next bar is cancelled and must be resubmitted while the entry rule remains valid.

The distinction with SELL matters. SELL closes an open long position and never opens anything; SELLSHORT opens a new short position. The four order instructions pair up as BUY with SELL for the long side, and SELLSHORT with EXITSHORT for the short side. A strategy that issues SELL when it means to go short does nothing when flat, and the mistake is silent because the order is simply ignored.

Examples

Example 1, Conditional short entry at market (ProBacktest)

probuilder
// Short when the trend filter turns down and no short is open
ShortConditions = close CROSSES UNDER Average[50](close)
IF NOT ShortOnMarket AND ShortConditions THEN
    SELLSHORT 1 SHARES AT MARKET
ENDIF

The guard NOT ShortOnMarket prevents stacking a second short on top of an existing one; the order fires only when the entry rule is met while no short is open. This follows the example from the official reference, with the entry condition made explicit.

Example 2, Short with a full exit bracket (ProOrder)

probuilder
DEFPARAM CumulateOrders = false

// Short an RSI overbought signal
IF NOT onmarket AND RSI[14](close) > 70 THEN
  SELLSHORT 1 CONTRACT AT MARKET
ENDIF

// Protective bracket, stop above and target below the entry
SET STOP PLOSS 30
SET TARGET PPROFIT 60

The short opens at market and carries a 30-point stop with a 60-point target. For a short position the stop sits above the entry price and the target below it.

Example 3, Pending breakdown entry (ProOrder)

probuilder
// Short a breakdown through the 20-bar low
supportLevel = lowest[20](low)

IF NOT onmarket THEN
  // Resubmit the pending order each bar while flat
  SELLSHORT 1 CONTRACT AT supportLevel STOP
ENDIF

The pending STOP order rests below the market and fills only if price breaks the 20-bar low. Resubmitting it every bar keeps the level current as the low moves.

Common errors and gotchas

  • SELLSHORT is not SELL. SELLSHORT opens shorts; SELL closes longs. Using SELL to open a short position fails silently, the order is ignored while the strategy is flat, and no error is reported.
  • Closing a short takes EXITSHORT. A short opened with SELLSHORT is closed with EXITSHORT, not with BUY. On platforms where CumulateOrders is off, a BUY against an open short reverses the position rather than simply flattening it, which is rarely the intent.
  • Pending entries expire after one bar. A resting SELLSHORT ... STOP or SELLSHORT ... LIMIT order is cancelled if unfilled after the next bar. Resubmit it on every bar while the setup is valid, as in example 3.
  • Unguarded entries stack positions. With CumulateOrders enabled, a SELLSHORT that fires on consecutive bars keeps adding to the short. Guard entries with NOT ShortOnMarket or NOT onmarket, or disable cumulation with DEFPARAM.
  • BUY, opens a long position.
  • SELL, closes an open long position.
  • EXITSHORT, closes an open short position.
  • SHARES, quantity unit keyword for stock orders.
  • CONTRACT, quantity unit keyword for derivatives.
  • MARKET, immediate execution at the current price.
  • LIMIT, pending order at a stated price or better.
  • SHORTONMARKET, true while a short position is open.
  • ONMARKET, true while any position is open.
  • TRADEPRICE, the entry price of the current position.