Portfolio · condition block
Trailing stop
The trailing stop block follows a trade up. It tracks the highest price since the position opened and is true once price falls X% below that peak. The stop starts X% below the entry, rises with every new high and never moves down.
How the engine evaluates it
The block is false when the bot holds nothing. When a position opens from flat, the peak starts at the entry fill price. Buying more while holding (stacking) does not reset it; it starts again only after a full exit.
On the close (the default), the peak is the higher of the entry price and every close since, including the current candle. The block fires when the close is at or below peak × (1 − X/100), and a sell in the same rule fills at the close like any market order, with the bot's fee and slippage.
on wick reacts inside the candle. The peak is the higher of the entry price and the highs of the candles since the entry, up to the previous candle, and the stop level is peak × (1 − X/100). The block fires when this candle's low reaches the level. The sell fills as a stop: at the level, or at the open if the candle opened below it, less slippage.
close trigger: peak = max(entry price, closes since entry)
fires when close ≤ peak × (1 − X / 100)
wick trigger: peak = max(entry price, highs since entry up to the previous candle)
level = peak × (1 − X / 100), fires when low ≤ level
fill = min(open, level) less slippage
Botscript syntax
In the Lab you pick this block from the Portfolio group and fill in its fields. In the code view the same condition is written like this:
trailing 5%
trailing 5% on wick
trailing 10%
Settings
| Setting | Values | Default | Notes |
|---|---|---|---|
| Percent | 0.1 – 100% | 5% | Distance below the peak. |
| Trigger | close, wick | close | on wick reacts inside the candle and fills as a stop. |
How traders use it
- Let winners run:
trailing 8%withsell 100%instead of a fixed take profit. - Pair a tight first stop with a looser trail:
pnl down 3% on wickandtrailing 6% on wick, each withsell 100%. - Trail only after a trade has had time to work:
trailing 3% and held >= 6. - Scale out:
trailing 4%withsell 50%, thentrailing 8%withsell 100%.
Example bot
bot "Breakout Trailer"
when trailing 6% on wick
then sell 100%
when breakout high 48
then buy 100%
- The exit comes first, so it is checked before any new entry on the same candle.
- Buys when a close breaks above the high of the previous 48 candles.
- Sells as soon as a wick falls 6% below the highest high since the entry, at that level (or at the open if the candle opened below it).
Pitfalls
- A close-triggered trailing stop waits for the close, so after a sharp drop it can fill well below its level.
on wickreacts sooner but is hit more easily by brief spikes. - Too tight a percentage turns normal noise into exits. The ATR and volatility blocks show how far price usually swings on your candle size.
- The peak does not reset when you add to a position, so after stacking the stop is still measured from the earlier high.
Trailing stop: frequently asked questions
How is this different from a stop loss?
A stop loss (pnl down 8%) is measured from the average entry and stays put. A trailing stop is measured from the highest price since the entry, so it rises as the trade moves in your favour.
How is it different from the Chandelier exit?
The Chandelier exit trails a multiple of ATR below the highest high of the last N candles, whatever your position. The trailing stop trails a fixed percentage below the peak of your own open trade.
Does adding to a position reset the peak?
No. The peak starts at the first entry after being flat and only starts again after a full exit.
At what price does it fill?
With the close trigger, at the close with slippage. With the wick trigger, at the stop level, or at the open if the candle opened below it, less slippage. The bot's fee applies either way.
Is it ever true while I hold nothing?
No. The block is false when the bot is flat.
Related blocks
Simulated results are hypothetical. They include only the fee and slippage you set on the bot, not every real-world cost or market condition, and past performance does not guarantee future results. Nothing here is financial advice.