Skip to main content

How to Prompt ChatGPT/Claude for TVH Pine + JSON

TL;DR

Always paste the URL https://www.tv-hub.org/llms-full.txt first so the LLM has ground truth. Then ask for one specific strategy with concrete numbers: exchange, pair, sizing mode, stop-loss type, take-profits, and any special features. Vague prompts produce hallucinated field names; specific prompts produce schema-correct JSON.

LLMs without TVH context invent plausible-looking field names. With ground truth in context, the same models produce production-ready payloads. The difference is the first message of your conversation.

The Golden Prompt Template

Copy, paste, fill in the bracketed parts:

I'm using TradingView Hub to automate crypto trading. Read this reference first:
https://www.tv-hub.org/llms-full.txt

Now write a Pine v5 strategy for me with these requirements:
- Exchange: [binance / binance-futures / bybit / bybit-spot / okx / kucoin / coinbase / bitmex]
- Pair: [BTCUSDT / ETH-USDT-SWAP / XBTUSD / EURUSD / etc.]
- API key name in TVH: [the label I set in my dashboard, e.g. "binance-main"]
- Strategy logic: [your indicator/condition in plain English]
- Sizing: [absolute units / percent of balance / percent of wallet / fixed quote / risk percent]
- Stop Loss: [percent value, absolute price, or formula]
- Take Profits: [single level or scale-out ladder]
- Special: [hedge mode / DCA / trailing / scaled orders / closed-source wrapper / etc.]

Output, in this order:
1. The full Pine v5 strategy script (using strategy.entry / strategy.close with alert_message).
2. The resolved JSON payload for the entry alert (one block).
3. The resolved JSON payload for the close alert (one block).
4. TradingView alert setup instructions (Condition, Trigger, Message field, Webhook URL).

The trick is the URL on the second line. ChatGPT-4o, Claude 3.7+, Perplexity, and Gemini all fetch it. Once the model has those 84 properties in context, it stops inventing field names.

Generating the payload vs. everything else

llms-full.txt is the right reference for writing the Pine + JSON — it is the exact TradeCommand schema, which is all the examples below need. If your question also touches setup, exchange choice, or exchange-specific quirks, add the docs map https://www.tv-hub.org/llms.txt as a second reference (see the dual-reference prompt).

Why each element matters

ElementWhat it sets in the JSON
Exchangeexchange field — routes to one of 16 adapters; spot vs futures are distinct slugs.
Pairpair field — exchange-native format, no normalization (see Exchange Quirks).
API key nameapiKey field — case-sensitive, must match your dashboard label exactly.
Sizing modeToggles unitsType between absolute, percent, percentBalance, percentWallet, percentPosition, risk — plus useFixedSize + fixedQuoteSize.
SL formatDetermines stopLossType (absolute or percent) and which value field is populated.
TP formatDetermines targetType, targetAmountInPercent, and the structure of targets[].
Special featuresEnables useDca, useScaledOrders, hedgeMode, useTrailingStopLoss, etc.

If you skip these, the LLM picks defaults that may not match what you want. Specificity is cheaper than debugging.

Four concrete prompt examples

Example 1 — Simple long-only EMA crossover (Binance Spot)

I'm using TradingView Hub. Reference: https://www.tv-hub.org/llms-full.txt

Write a Pine v5 strategy with:
- Exchange: binance
- Pair: BTCUSDT
- API key name: binance-main
- Logic: 9/21 EMA crossover, long-only, exit on reverse cross
- Sizing: 5% of available balance (unitsType: "percent")
- Stop Loss: 2% below entry
- Take Profit: 4% above entry, full exit
- Special: include alertTimestamp for idempotency

Output: full Pine + entry JSON + close JSON.

Expected fields in the entry JSON: exchange, pair, apiKey, isBuy:true, unitsType:"percent", unitsPercent:5, isMarket:true, stopLossType:"percent", stopLossPercent:2, targetType:"percent", targetAmountInPercent:true, targets:[{"takeProfitPercent":4,"amount":100}], alertTimestamp, token.

Example 2 — Risk-based sizing with multi-TP trailing (Bybit Futures)

Reference: https://www.tv-hub.org/llms-full.txt

Pine v5 strategy:
- Exchange: bybit
- Pair: ETHUSDT
- API key name: bybit-main
- Leverage: 5x cross
- Logic: RSI(14) crosses above 30 = long; crosses below 70 = short
- Sizing: 1% account risk per trade (use fixedQuoteSize calculated in Pine from
available equity * 0.01 / sl_distance_pct, since unitsType: "risk" requires
a stop-loss value (either stopLossPercent or absolute stopLoss))
- Stop Loss: ATR(14) * 1.5 below entry, computed in Pine → ship as
stopLossType: "absolute" with the literal price
- Take Profits: 3 levels at 1R, 2R, 3R; scale out 33/33/34
- Special: useTrailingStopLoss after position is open; activate at 1R, trail 0.5%
- Use setTpToPosition: true (Bybit UTA)

Output: Pine + JSON.

This prompt exercises four schema details at once: risk sizing, absolute SL from Pine math, multi-target ladder with targetAmountInPercent, and trailing activation threshold.

Example 3 — DCA grid entry (Binance Futures)

Reference: https://www.tv-hub.org/llms-full.txt

Pine v5 strategy:
- Exchange: binance-futures
- Pair: SOLUSDT
- API key name: bin-fut-main
- Leverage: 3x cross
- Logic: enter long on RSI(14) < 30, exit at +5% above average entry
- Sizing: 25% of balance per leg
- Special: DCA mesh — useDca: true, dcaPercent: 1.5, dcaOrderCount: 4
(so 1 market entry + 4 limit legs spaced 1.5% apart = 5 total legs)
- Stop Loss: 7% below the average entry
- Take Profit: single target at 5%, full exit (targetAmountInPercent: true)

Output: Pine + JSON.

Critical: useDca: true is the master switch. Without it dcaPercent and dcaOrderCount are ignored. The LLM should not generate a dca object or dcaConfig field — those don't exist.

Example 4 — Closed-source strategy wrapper (BitMex)

Reference: https://www.tv-hub.org/llms-full.txt
Also read: https://www.tv-hub.org/docs/pine-script/strategy-alerts#how-to-automate-a-closed-source-tradingview-strategy

I have a purchased Pine strategy I can't edit — only the alert Message field.
The strategy emits {{strategy.order.action}} (= "buy" or "sell") and
{{strategy.order.comment}} (= "Exit Long", "Exit Short", or empty).

Write me ONE alert Message field for TVH that:
- Exchange: bitmex
- Pair: XBTUSD
- API key name: bitmex-main
- Sizing: 50% of wallet
- Orders are market
- Uses strategyComment + strategyCloseValue to auto-detect closes
- One JSON payload that handles all four cases (buy/sell entries + buy/sell exits)
by relying on TVH's auto-mapping.

Output: single JSON string that I paste into the closed-source strategy's
alert Message field.

The LLM should produce a single payload using orderType set from the placeholder, strategyCloseValue:"Exit Long|Exit Short|close|exit", and unitsType:"percentWallet".

Anti-patterns — what NOT to do

PromptProblem
"Make me a TradingView bot"Too vague. LLM invents exchange, pair, sizing, SL — none of which match your account.
"Use TVH and 3Commas together"Mixing systems. The LLM produces payloads that fit neither schema.
"Pick the best parameters for ETHUSDT"LLMs cannot backtest. They fabricate winrates and "optimal" parameter ranges. Use Strategy Finder.
"Write a webhook signature" or "Add an Authorization header"TVH uses token-in-body, not headers. LLMs default to REST conventions and add nonexistent auth.
"Make it work on all exchanges"Symbol formats, futures vs spot routing, leverage semantics differ per adapter. One payload cannot serve all.
"Pick a stop-loss that's safe"Risk choices are yours, not the LLM's. Give a concrete percent or formula.

Verifying LLM output

Even with llms-full.txt in context, models can drift. Verify every payload before going live:

  1. Field-name sanity check. Cross-reference every key against the Parameter Reference. Any unknown key is hallucinated.
  2. Round-trip through TVH's UI. TVH's Trade Command Builder has a Paste Trade Command feature — it parses your JSON and renders it as form fields. If the UI rejects a field, the webhook will too.
  3. Send to demo first. Use a *-testnet exchange slug or Bybit Demo Account (see Demo Trading). The full pipeline runs without risking capital.
  4. Inspect the Activity Log. TVH's dashboard shows the parsed TradeCommand next to the raw payload. Mismatches mean a typo on either side.

What LLMs are good at

  • Writing Pine v5 boilerplate (strategy declaration, request.security, str.format for dynamic JSON).
  • Translating "I want X" into the right combination of TradeCommand fields, once they have the reference.
  • Catching obvious bugs — repaint risks, missing barstate.isconfirmed, double-fires.
  • Refactoring an existing payload into a different sizing mode without missing dependent fields.

What LLMs are bad at

  • Picking optimal parameters. They don't backtest. Use Strategy Finder for that.
  • Predicting market direction. No model does this. Ignore "this will be profitable" claims.
  • Knowing exchange-specific quirks unless you tell them. The reference covers them, but the LLM has to retrieve correctly. Cross-check against Exchange Quirks.
  • Knowing current subscription pricing, affiliate splits, or feature availability. These change. Don't ask the LLM, read Subscriptions.
  • Knowing your real account state. They can't see your balance, open positions, or active orders.

Iterating with the LLM

Once you have a working payload, treat it as a base and ask for variations:

  • "This Pine repaints on a 1H signal. Fix it." — LLM will add barstate.isconfirmed and lookahead=barmerge.lookahead_off.
  • "Add a DCA layer of 3 legs spaced 2% apart." — LLM adds useDca:true, dcaPercent:2, dcaOrderCount:3.
  • "Convert this to hedge mode." — LLM adds hedgeMode:true and refactors close calls to closeLong/closeShort.
  • "Convert from Binance Futures to OKX swap." — LLM updates exchange, pair (adds -SWAP suffix), and adds instrumentType:"swap".

Tell the LLM what changed since the last message. Don't re-paste the whole reference each time — it's still in context.

Next steps