Building Blocks & Schedules
Presets that call each other, and presets that run on their own schedule
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=EXITScalls another preset and waits for it, like an include or a function call.trigger=EXITSstarts 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 therun=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, soenable=/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 itsabortonly ends the called preset. To report back, use a global variable ($name), as the risk check below does.
?? 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"].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 presetNAME(crontab: every 15 minutes);interval=NAME,+2hruns it once, 2 hours from now, and then switches it off;interval=NAME,0switches it off. Without a name,interval=applies to the running preset itself.
ex= / sym= in the script (or the General Options defaults), the side from the open position if the preset has Detect Side on.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
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*
[if weekend] abort [end] (see Checks & Conditionals).