ProBacktest/probacktest · proorder

ShortTriggered

ShortTriggered in ProBacktest and ProOrder is true on the bar a short entry order is filled. Use it to run once-per-fill setup logic, with the optional bar index.

Syntax

probuilder
ShortTriggered[N]

How it works

ShortTriggered returns true on the bar where a short position was opened. The optional index N looks back a number of bars: ShortTriggered[1] checks the previous bar, and ShortTriggered with no index, equivalent to ShortTriggered[0], checks the current bar.

It is useful when a pending short order, a Working Order, fills part way through a candlestick and the strategy needs to know it happened on that bar, for example to set a stop or a target immediately after entry. Unlike SHORTONMARKET, which stays true for as long as the short is held, ShortTriggered is true only on the fill bar itself.

Examples

Example 1, Reacting on the previous fill bar (ProOrder)

probuilder
// Run logic if a short was opened on the previous bar
IF ShortTriggered[1] THEN
    // actions to take one bar after the short filled
ENDIF

This is the pattern from the official reference. ShortTriggered[1] is true when a short filled exactly one bar back.

Example 2, Setting a stop right after entry (ProOrder)

probuilder
DEFPARAM CumulateOrders = false
// Enter short on a break of the 20-bar low, then place a protective stop
IF NOT ShortOnMarket AND close CROSSES UNDER Lowest[20](low) THEN
    SELLSHORT 1 CONTRACT AT MARKET
ENDIF
// On the bar the short fills, attach a stop above the entry
IF ShortTriggered THEN
    SET STOP LOSS 20
ENDIF

The ShortTriggered block runs only on the fill bar, which is the natural moment to attach a protective stop to the fresh position.

Example 3, Counting recent short fills (ProBacktest)

probuilder
// Detect a short fill within the last three bars
recentShort = ShortTriggered[0] OR ShortTriggered[1] OR ShortTriggered[2]
IF recentShort THEN
    // a short was opened within the last three bars
ENDIF

Checking several indices covers a short window after entry when the strategy needs to act soon after a fill rather than only on the exact bar.

Common errors and gotchas

  • Fill bar only. ShortTriggered is true just on the bar of execution. To test whether a short is currently held across bars, use SHORTONMARKET.
  • Short side only. It reports short fills. For long entries use LongTriggered.
  • Index direction. N counts bars back into the past. ShortTriggered[1] is one bar ago, not one bar ahead.
  • Same-bar pending orders. The value is designed for pending orders that fill within a candlestick. A market order that opens and closes in the same bar can behave differently, so verify the timing in a backtest.