SHORTONMARKET
SHORTONMARKET in ProBacktest and ProOrder is true while a short position is open. Use it to guard short entries and exits, with worked examples.
Syntax
ShortOnMarketHow it works
SHORTONMARKET returns true while the strategy holds an open short position and false when it does not. It is read as a plain boolean, so it slots directly into an IF condition, usually negated with NOT to allow a new short only when none is open.
It reports on short positions only. For long positions use LONGONMARKET, and to test whether any position of either side is open use ONMARKET. Combining SHORTONMARKET with a signal condition is the standard way to control when a short entry or a short exit is allowed.
Examples
Example 1, Guarding a short entry (ProBacktest)
// Sell short when MACD crosses below zero, but only if no short is open
myMACD = MACD[12,26,9](close)
short = myMACD CROSSES UNDER 0
IF NOT ShortOnMarket AND short THEN
SELLSHORT 1 CONTRACT AT MARKET
ENDIFThis is the pattern from the official reference. NOT ShortOnMarket stops the strategy from stacking a second short while one is already running.
Example 2, Managing an open short (ProOrder)
DEFPARAM CumulateOrders = false
// Close the short when price reclaims the 20-period average
IF ShortOnMarket AND close CROSSES OVER Average[20](close) THEN
EXITSHORT AT MARKET
ENDIFThe exit block runs only while a short is open, so the CROSSES OVER condition is checked only when it is relevant.
Example 3, One side at a time (ProOrder)
DEFPARAM CumulateOrders = false
// Allow a long only when neither side is open
IF NOT ShortOnMarket AND NOT LongOnMarket AND close CROSSES OVER Average[50](close) THEN
BUY 1 CONTRACT AT MARKET
ENDIFTesting both SHORTONMARKET and LONGONMARKET keeps the strategy flat before a new entry. NOT OnMarket expresses the same guard more compactly.
Common errors and gotchas
- Short only.
SHORTONMARKETignores long positions. A strategy that trades both sides needsLONGONMARKETas well, orONMARKETfor the combined state. - State, not a count. It reports only whether a short is open, not its size. For share or contract quantities use
COUNTOFSHORTSHARESorCOUNTOFPOSITION. - Same-bar timing. A short opened and closed within a single bar may not leave
SHORTONMARKETtrue the way a multi-bar position would. To detect a fill on the current bar, useShortTriggered. - Forgetting the guard. Omitting
NOT ShortOnMarketon an entry lets a persistent signal add repeated shorts, especially withCumulateOrdersenabled.
Related instructions
LONGONMARKET, true while a long position is open.ONMARKET, true while any position is open.ShortTriggered, true on the bar a short order is filled.NOT, negates the state to guard entries.SELLSHORT, opens a short position.EXITSHORT, closes a short position.COUNTOFSHORTSHARES, size of the open short position.
