Skip to main content

Official TVH Boilerplate Pine Strategy

We maintain a Pine v5 strategy template on GitHub. It already contains the TVH webhook integration — every input you would normally hand-code (exchange, sizing, SL/TP, DCA, leverage, margin mode) is exposed as a TradingView input setting. Drop your entry logic in, get a TVH-ready strategy in under five minutes.

TL;DR
  • Repo: tradingview-hub/tvhub-boilerplate-strategy
  • One file: tvhub-boilerplate-strategy.pine — paste into Pine Editor, save, add to chart.
  • The reference strategy is Parabolic SAR + Regression Channels + Supertrend; replace the entry conditions with your own.
  • Alert Message: {{strategy.order.alert_message}} — same dispatch pattern as on Strategy Alerts.
View on GitHub →

What you get

Open the boilerplate and you find:

  • A complete TV-Hub input-settings section (token, exchange, pair, sizing, leverage, margin, take-profit ladder, stop-loss, trailing, DCA, advanced flags).
  • Runtime buy_command, sell_command, and close_command strings — assembled from the inputs at every bar. No JSON to hand-write.
  • A demonstration strategy (Parabolic SAR + Regression Channels + Supertrend) wired with strategy.entry / strategy.close_all calls that already pass alert_message=.
  • Visual confirmation: every signal plots on the chart so you can sanity-check before going live.
  • Compatible with {{strategy.order.alert_message}} — one TradingView alert handles every event.

Step-by-step setup

  1. Open the file. Visit the GitHub repo and open tvhub-boilerplate-strategy.pine. Click Raw, then copy the full contents.

  2. Open Pine Editor in TradingView. Bottom panel → Pine Editor → New → Empty strategy.

  3. Paste and save. Replace the empty template, click Save (Ctrl+S), name it (e.g. "TVH Boilerplate v1").

  4. Add to chart. Click Add to chart. The strategy plot appears on the active symbol.

  5. Configure the inputs. Click the gear icon next to the strategy name in the chart. Fill in:

    TVH boilerplate strategy input fields — Webhook, Order Type, Risk Management

    TVH boilerplate strategy input fields — Take Profit, Stop Loss, DCA, Advanced

  6. Replace the entry condition. Scroll down past the input section to the "Open orders" block. The default uses the demo PSAR/Regression strategy. Replace buySignal and sellSignal with your own conditions (see Customising the entry logic below).

  7. Create the TV alert. Bell icon → Create Alert → Condition = your strategy. Tick Webhook URL, paste the TVH endpoint. Message: literally {{strategy.order.alert_message}}.

  8. Smoke test. Run on the 1-minute chart of a low-cap pair you do not mind hitting. Watch the TVH Activity Log to confirm receipt.

Input fields reference

These are the inputs exposed in the current boilerplate (tvhub-boilerplate-strategy.pine, extracted directly from the GitHub source):

Webhook TV-Hub Settings

InputTypeNotes
Access-KeystringYour TVH user token. Find it on the Account & API Keys page.
API Key NamestringThe label of the API key as saved on TVH (e.g. binance-main).
ExchangeenumBybit, Bybit-Testnet, Binance, Binance-Futures, Binance-Futures-Testnet, Bitmex, Bitmex-Testnet, OKX.

Order Type

InputTypeNotes
Order-TypeenumMarket or Limit.
Use best price (Best Bid/Ask)boolWhen Limit, sets limitPriceType:"bestPrice".
Enable order chasingboolWhen Limit + Best Bid/Ask, turns on chaseLimitOrder:true.
Order chasing intervalfloat (sec)Default 20 s. Min 1 s, total chase count fixed (180 → 1h budget at default).

Risk Management

InputTypeNotes
Units TypeenumUse Fixed Size (USD), Use Absolute Value, Use Percent (Available), Use Percent (Wallet), Risk.
Position SizefloatInterpreted per Units Type — see the Sizing page.
Margin TypeenumCROSSED or ISOLATED. Lowercase on the wire (cross / isolated) — the boilerplate handles the casing.
Leverageint1–125. Defaults to 10.

Take Profit

InputTypeNotes
Take-Profit TypeenumPercent or Absolute.
Enable Take Profit + Distancebool + floatMaster toggle + first-target distance (e.g. 0.3 = 0.3 %).
Distribution Sizebool + floatWhen on, splits the position across enabled TPs by percentage.
TP1TP5boolEnable additional ladder rungs. Each rung's distance is set per row.

Stop Loss and Trailing

InputTypeNotes
Stop-Loss TypeenumPercent or Absolute.
Enable Stop-Loss + Valuebool + floatMaster toggle + SL distance.
Enabled Trailing + Valuebool + floatTrailing stop percent (Pine's trailingPercent).
Enabled Break EvenboolAdds break-even SL movement (exchange support varies — see Stop Loss).

DCA Order Mesh

InputTypeNotes
DCA distance %floatSpacing between DCA legs.
Enter DCA OrdersintNumber of additional limit legs (1–10).

Advanced

InputTypeNotes
Close Current PositionboolCloses opposite-side positions on a flip. Maps to closePosition:true.
Prevent PyramidingboolBlocks stacking same-direction entries.
Cancel Pending OrdersboolCancels pre-existing limit orders before placing the new one.
Hedge ModeboolSets hedgeMode:true (used by Binance Futures). Bybit hedge is account-level and ignores this flag.

The complete dropdown list lives in the source — when in doubt, open the Pine file and read the input.*(...) declarations directly.

Customising the entry logic

Scroll past the input section. You will see a comment block:

//==============================================================================//
//======================= End TV-Hub Input Settings ============================//
//==============================================================================//

//==============================================================================//
// The following strategy is just for demonstration purpose.
// Start to build your own trade logic here.
//=========================|====|====|====|====|====|===========================//

Below that, the demo defines:

buySignal = ... // PSAR / Regression / Supertrend combination
sellSignal = ...

And lower down:

if buySignal
strategy.entry("Long", strategy.long, alert_message=buy_command)
// ... TP/SL bookkeeping ...

if sellSignal
strategy.entry("Short", strategy.short, alert_message=sell_command)
// ... TP/SL bookkeeping ...

To plug in your own logic, replace only the buySignal / sellSignal expressions. The strategy.entry(...) lines and the entire input section above stay untouched.

Minimal replacement — EMA crossover:

// Replace the demo signals near the bottom of the file.
fast = ta.ema(close, 9)
slow = ta.ema(close, 21)
buySignal = ta.crossover(fast, slow)
sellSignal = ta.crossunder(fast, slow)

With that one swap, every input on the gear icon now drives an EMA-crossover bot through TVH.

Updating the boilerplate

The repo evolves. Watch it (GitHub → Watch → Releases only) to get notifications when a new version ships. Releases include:

  • New input fields (e.g. when TVH adds a new trade-command parameter).
  • Bug fixes in the JSON assembly.
  • Compatibility tweaks for new Pine versions.

Upgrade procedure:

  1. Save your customised strategy under a versioned name (e.g. My Strategy v3 - 2026-05).
  2. Copy the new boilerplate from GitHub.
  3. Diff against your saved version. Re-apply your buySignal / sellSignal block.
  4. Save as a new version. Re-attach the alert.

Contributing

Pull requests are welcome — typo fixes, new input options, new exchange entries in the dropdown. Open an issue first for larger changes. See the repo's readme.md for contribution guidelines.

Next