Skip to main content

Pine Script & extras

Default for everyone (no Pine): URL + entry/exit Message. Auth stays on ?key= — no "key" in JSON.

Use this page to import helpers into your own script. Only required fields are sent by default. SL / target / trail are optional — if you don’t add them, that is fine; TradePod uses strategy Settings.

Download helpers: /pine/tradepod-webhook.pine

AI agents — write Pine for me​

Paste this prompt into Claude / ChatGPT / Cursor, or ask Claude on your connected pod to call MCP tool get_tradingview_pine_helpers (needs Claude connector + Allow analysis).

Download prompt: /pine/tradepod-ai-prompt.txt

You write Pine Script v5 for TradePod TradingView webhooks.

## Auth (critical)
- Auth is ONLY on the TradingView Webhook URL as ?key=…
- Do NOT put "key" in the alert JSON body.
- No custom HTTP headers (TradingView cannot send them).

## JSON contract
Required on entry: action ("BUY"|"SELL"), symbol, price.
Optional on entry: sl, target, trail_sl — include ONLY when > 0. Omitting is fine; TradePod strategy Settings apply.
Exit: action "EXIT", symbol, price (separate alert from entry).
Optional: MODIFY (sl/target/trail_sl), FORCE_EXIT (flatten).
NEVER add unless the user explicitly asks: key, order_mode, qty, lots.

## trail_sl
- Unit is price points (₹), NOT percent.
- Requires sl to be present (> 0).

## alert() rules
- Build JSON with string concatenation (Pine has no JSON type).
- Strings quoted, numbers unquoted.
- Separate alert() for entry and exit.
- Prefer alert.freq_once_per_bar_close.
- Use straight ASCII quotes only.

## Helpers (prefer these)
Use tp_entry / tp_exit / tp_modify / tp_flatten from TradePod helpers.
Call examples:
alert(tp_entry("BUY", close, 0, 0, 0), alert.freq_once_per_bar_close)
alert(tp_entry("BUY", close, sl, tp, 0), alert.freq_once_per_bar_close)
alert(tp_exit(close), alert.freq_once_per_bar_close)

## Output
Return a complete //@version=5 script the user can paste into TradingView Pine Editor.
Include the helper functions unless the user already has them.
Explain briefly how to create the alert and paste the TradePod Webhook URL (with ?key=).

Then describe your strategy (e.g. “SMA 9/21 long only, no SL”).

Strategy examples (import these)​

Open the file in TradingView → Pine Editor → Add to chart → create alert from the strategy → paste TradePod Webhook URL.

ExampleWhat it sendsFile
SMA long — entry + exit onlyBUY / EXIT (no SL/TP)tradepod-sma-entry-exit.pine
SMA long — optional SL / target / trailSame + toggles for brackets (trail_sl in points ₹)tradepod-sma-sl-tp.pine
SMA long + shortBUY/SELL + EXIT each side; SL/TP off by defaulttradepod-sma-long-short.pine

None of these send key, order_mode, qty, or lots. Size and order type stay in TradePod Settings.

Required vs optional​

FieldsIf missing
Entry requiredaction (BUY/SELL), symbol, priceEntry fails without these
Entry optionalsl, target, trail_slOmit or pass 0 → fine. trail_sl is points (₹), not % (needs sl)
Exit requiredaction (EXIT), symbol, price
Never needed in Pinekey, order_mode, qty, lotsLeave to Webhook URL + TradePod Settings

Do not send order_mode: AUTO or size unless you intentionally override Settings.

Helpers to paste​

//@version=5
// Paste into your script. Webhook URL has ?key= — do not add "key".

tp_sym() => syminfo.ticker
tp_n(v) => str.tostring(v)

// sl / tp / trail: pass 0 to omit from JSON
tp_entry(action, px, sl, tp, trail) =>
s = '{"action":"' + action + '","symbol":"' + tp_sym() + '","price":' + tp_n(px)
s := sl > 0 ? s + ',"sl":' + tp_n(sl) : s
s := tp > 0 ? s + ',"target":' + tp_n(tp) : s
s := trail > 0 ? s + ',"trail_sl":' + tp_n(trail) : s
s + '}'

tp_exit(px) =>
'{"action":"EXIT","symbol":"' + tp_sym() + '","price":' + tp_n(px) + '}'

tp_modify(sl, tp, trail) =>
s = '{"action":"MODIFY","symbol":"' + tp_sym() + '"'
s := sl > 0 ? s + ',"sl":' + tp_n(sl) : s
s := tp > 0 ? s + ',"target":' + tp_n(tp) : s
s := trail > 0 ? s + ',"trail_sl":' + tp_n(trail) : s
s + '}'

tp_flatten() => '{"action":"FORCE_EXIT"}'

Call them​

// Entry only (no SL / TP) — OK
if longEntry
alert(tp_entry("BUY", close, 0, 0, 0), alert.freq_once_per_bar_close)

// Entry + SL + target (trail omitted)
if longEntry
alert(tp_entry("BUY", close, close * 0.99, close * 1.02, 0), alert.freq_once_per_bar_close)

// Exit — separate condition
if longExit
alert(tp_exit(close), alert.freq_once_per_bar_close)

Message-box JSON (same rules)​

Entry only:

{
"action": "BUY",
"symbol": "{{ticker}}",
"price": {{close}}
}

Entry + SL + target (optional):

{
"action": "BUY",
"symbol": "{{ticker}}",
"price": {{close}},
"sl": {{plot("SL")}},
"target": {{plot("Target")}}
}

Exit:

{
"action": "EXIT",
"symbol": "{{ticker}}",
"price": {{close}}
}

Payload reference · TradingView alerts · AI agents