General information

Building Blocks & Schedules

Presets that call each other, and presets that run on their own schedule

It is always recommended to use testnet/sandbox first!

Presets as building blocks

Instead of one long script per strategy, build small PV Alerts (presets) – entry, exits, trailing, cleanup, risk checks – and combine them, like functions:

  • run=EXITS calls another preset and waits for it, like an include or a function call.
  • trigger=EXITS starts it in parallel and goes on immediately.
  • The called preset inherits the market (exchange, symbol), the account, the defaults and the variables of the caller, and placeholders like [id] and [side] resolve to the caller's. ex= / sym= / a= / side= on the run= line override them.
  • Its own filters and locks are ignored, and it runs even when disabled. The variants runen= / triggeren= only run an enabled preset, so enable= / disable= work as switches for parts of a setup.
  • Local variables (_name) set in the called preset don't come back to the caller, and its abort only ends the called preset. To report back, use a global variable ($name), as the risk check below does.
Note: A preset that is also called on its own may miss a variable of its callers. Since 1.3.110 ?? gives placeholders a fallback: q=[_risk ?? $defaultRisk ?? 1]% uses _risk if it is set (not empty), else the global $defaultRisk, else 1. The last value can also be quoted text, eg. t=[_type ?? "market"].

Example: entry with shared risk check and exits

A unified entry preset named ENTRY_LONG, ENTRY_SHORT that runs two shared presets:

# ENTRY: the shared risk check, the entry, then the shared exits
run=RISK
if=($ok[id] = 0) abort
cancel
[side]=10% lev=5 market err=abort
run=EXITS
# RISK: $ok<id> = 1 only when no position is open and the balance is above 100
set=$ok[id]:0
ifpos=abort
ub minb=100 err=abort
set=$ok[id]:1
# EXITS: separate exit orders, named after the calling preset ([id] and [side] are the caller's)
close sl=[-]1% market id=[id]-SL expect
close tp=[+]1.9% p=[+]2% id=[id]-TP expect
Note: Global variables are shared by all alerts, so the name carries the caller's [id] ($okENTRY) to keep strategies apart.

Scheduled runs

Every preset can also run on its own schedule, without a TradingView signal: Run in Intervals in the PV Alert editor, with the Edit button to build the crontab expression. From a script:

  • interval=NAME,*/15 * * * * sets the schedule of the preset NAME (crontab: every 15 minutes);
  • interval=NAME,+2h runs it once, 2 hours from now, and then switches it off;
  • interval=NAME,0 switches it off. Without a name, interval= applies to the running preset itself.
Note: A scheduled run has no chart: the market comes from ex= / sym= in the script (or the General Options defaults), the side from the open position if the preset has Detect Side on.
The Schedule option of a PV Alert is something else: it doesn't start the alert, it only lets TradingView signals through within the schedule.

Example: timeout after an entry

Add interval=TIMEOUT,+2h as the last line of the entry. Two hours later the TIMEOUT preset closes what is still open, then its interval switches itself off:

# TIMEOUT: runs once, 2 h after an entry (interval=TIMEOUT,+2h), closes what is left
ex=bybit sym=btcusdt
cancel
marketclose
+2h is stored as a date with the year (30 14 24 12 * 2026), which can also be set directly. If the app wasn't running at that time, the run is made up when it's back, up to Maximum delay of missed interval runs late (General Options, default 1 hour). Before version 1.3.110 the date had no year and repeated a year later, so end the preset with interval=0 there.

Example: periodic maintenance

A preset that runs every 15 minutes (*/15 * * * *): without a position it cancels the stale entry orders (ids starting with ENTRY) and stops, with a position more than 1% in profit it moves the stop to break-even, otherwise it stops. The one check line covers all three cases with a single exchange request:

# MAINTAIN: every 15 minutes (Run in Intervals: */15 * * * *)
ex=bybit sym=btcusdt
check=pos minpl=1% nopos=cancelall cancelid=ENTRY ifnomatch=abort
close sl=0 market
Note: close sl=0 market sets the position's own stop loss on Bybit, see Stops-on-fill for the other exchanges.

Example: no new entries over the weekend

Two scheduled presets switch the entry presets off on Friday evening and on again on Monday:

# WEEKEND_OFF: Fridays at 22:00 (0 22 * * 5)
disable=ENTRY*
# WEEKEND_ON: Mondays at 00:00 (0 0 * * 1)
enable=ENTRY*
For a simple time filter inside one preset, the preprocessor works too: [if weekend] abort [end] (see Checks & Conditionals).
Attention: Always double check that you are using the right syntax/alert!