Portfolio · condition block
Trade age (time stop)
The trade age block counts how many candles the open position has lasted. Use it as a time stop that closes trades that go nowhere, or to give a new trade room before other exits apply.
How the engine evaluates it
The age is the number of candles since the position opened from flat: 0 on the entry candle, 1 on the next, and so on. For a limit or stop entry, the entry candle is the one where the order filled.
Adding to the position (stacking) does not reset the age; a full exit does.
held >= N is true when the age is at least N, and held < N when it is under N. Both are false when the bot holds nothing.
age = current candle − candle where the position opened
held >= N: holding and age ≥ N
held < N: holding and age < N
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:
held >= 48
held < 12
Settings
| Setting | Values | Default | Notes |
|---|---|---|---|
| Comparison | at least (>=), under (<) | at least | — |
| Candles | 1 – 100,000 | 48 | Counted in candles of the run's candle size. |
How traders use it
- Time stop:
held >= 72withsell 100%closes any trade after three days of hourly candles. - Hold for a minimum time before taking profit:
rsi(14) > 70 and held >= 12. - Protect a new trade only at the start:
pnl down 3% and held < 6.
Example bot
bot "Breakout Or Bust"
when pnl up 8%
then sell 100%
when held >= 48
then sell 100%
when breakout high 24
then buy 100%
- Takes profit when a close is 8% above the average entry.
- Otherwise closes the trade 48 candles after the entry, whatever its result: two days on hourly candles.
- Enters when a close breaks above the high of the previous 24 candles.
Pitfalls
- The age counts candles, not hours:
held >= 48is two days on 1h candles and eight days on 4h candles. - A time stop sells winners and losers alike. Pair it with a take profit if you don't want to give back gains.
- The age keeps counting while you add to a position, so stacked buys don't buy extra time.
Trade age: frequently asked questions
Is the age counted in hours?
No, in candles of the run's candle size.
What is the age on the entry candle?
0. On the next candle it is 1.
Does buying more reset it?
No. It counts from when the position opened from flat and resets only after a full exit.
Can I use it on a buy rule?
It is false while the bot is flat, so it only matters on an entry with stacking on, for example to stop adding to a trade after a while: held < 24.
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.