ProBacktest/probacktest · proorder

STOP

STOP in ProBacktest and ProOrder is the stop order type for entries and exits, placing a pending order that fills once price crosses a level. Examples included.

Syntax

probuilder
[BUY|SELLSHORT] quantity unit AT price STOP

How it works

STOP follows a price in a BUY or SELLSHORT order to make it a pending stop order rather than an immediate one. A buy stop is placed above the current price and triggers when price trades up through the level, the usual form for breakout entries. A sell stop is placed below the current price and triggers when price trades down through the level.

STOP is one of the three order-type keywords, alongside MARKET for immediate execution and LIMIT for a pending order that waits for a better price. A pending stop that does not fill on the next bar is cancelled, so a persistent stop entry must be resubmitted each bar while the setup holds.

Do not confuse this order type with SET STOP LOSS, which sets a stop-loss level on a position already open. This page documents the STOP entry and exit order type. For the separate pending-stop protective mechanism see STOP (pending).

Examples

Example 1, Breakout entry with a buy stop (ProBacktest)

probuilder
DEFPARAM CumulateOrders = false
// Buy a break of the 20-bar high
entryLevel = Highest[20](high)
IF NOT OnMarket THEN
    BUY 1 CONTRACT AT entryLevel STOP
ENDIF

The pending stop rests above the market and fills only if price trades up through the previous 20-bar high, so the entry follows a confirmed breakout.

Example 2, Short breakdown with a sell stop (ProOrder)

probuilder
DEFPARAM CumulateOrders = false
// Sell short a break below the 20-bar low
level = Lowest[20](low)
IF NOT ShortOnMarket THEN
    SELLSHORT 1 CONTRACT AT level STOP
ENDIF

The sell stop sits below the market and triggers when price breaks the 20-bar low, entering short on the downside break.

Example 3, Stop entry with a protective stop loss (ProOrder)

probuilder
DEFPARAM CumulateOrders = false
// Enter on a breakout, then protect the position
entryLevel = Highest[20](high)
IF NOT LongOnMarket THEN
    BUY 1 CONTRACT AT entryLevel STOP
ENDIF
SET STOP LOSS 30

Here the STOP order type places the entry, while SET STOP LOSS attaches a 30-point protective stop to the resulting position. The two uses of the word "stop" are different mechanisms.

Common errors and gotchas

  • Order type versus stop loss. AT price STOP places a pending entry or exit order. SET STOP LOSS protects an open position. They are separate and easy to mix up.
  • Level on the wrong side. A buy stop must sit above the current price and a sell stop below it. A stop placed on the wrong side of the market is not a valid stop order.
  • Pending orders expire after one bar. A STOP order that does not fill on the next bar is cancelled. Resubmit it each bar while the setup remains valid.
  • Stop versus limit. STOP buys as price rises through a level, LIMIT buys as price falls to a better level. Swapping them reverses the entry logic.
  • MARKET, immediate execution at the current price.
  • LIMIT, pending order at a stated price or better.
  • BUY, opens a long position, which a stop order can trigger.
  • SELLSHORT, opens a short position, which a stop order can trigger.
  • SELL, EXITSHORT, close positions and can also use a stop level.
  • SET, attaches a protective stop or target to an open position.
  • TARGET, the profit-target counterpart of a protective stop.