en un clic
porting-pine-versions
// Migrate Pine Script v4 / v5 source to v6 — analyze, apply migration rules, compile-check, iterate until clean. Use when the user hands over an older script or asks to "upgrade to v6" / "port this Pine code".
// Migrate Pine Script v4 / v5 source to v6 — analyze, apply migration rules, compile-check, iterate until clean. Use when the user hands over an older script or asks to "upgrade to v6" / "port this Pine code".
Analyze a chart — set up symbol/timeframe, add indicators, scroll to key dates, annotate, and screenshot. Use when the user wants technical analysis or chart review.
Post-trade review — pull losing trades from the strategy tester, screenshot each entry in context, and cluster common failure patterns. Use when the user asks "why am I losing?", "review my losses", or "what's wrong with my strategy?".
Daily morning scan — load saved morning layout, screenshot watchlist symbols, and summarize overnight pre-market state. Use when the user says "good morning", "morning prep", or asks for a pre-open briefing.
Cross-asset reasoning across a multi-pane layout — set a 2x2 grid, assign correlated symbols to each pane, and identify leader/laggard/divergence. Use when the user asks to "compare indices", "watch the complex", or wants correlated-asset reasoning.
Scan multiple symbols for setups, patterns, or strategy performance. Use when comparing across instruments or screening for opportunities.
Full Pine Script development loop — write code, compile, fix errors, iterate. Use when building a new indicator or strategy in TradingView.
| name | porting-pine-versions |
| description | Migrate Pine Script v4 / v5 source to v6 — analyze, apply migration rules, compile-check, iterate until clean. Use when the user hands over an older script or asks to "upgrade to v6" / "port this Pine code". |
You are migrating an older Pine Script to v6. Work iteratively: analyze → rewrite → compile → fix.
Power-toolkit shortcut:
pine_checkdoes a server-side compile without touching the chart — use it between rewrite passes to fail fast on syntax errors before doing a fullpine_smart_compileround.pine_analyze(offline) covers v4/v5 deprecation flags.
pine_get_source — read the current source (skip if the user pasted it in chat)pine_analyze — the analyzer flags v<6 scripts explicitly; also surfaces deprecated calls//@version=4 → v4//@version=5 → v5//@version=6 → nothing to doUpdate the version header first: //@version=6. Then apply these rewrites.
| v4 | v6 |
|---|---|
study("Name", overlay=true) | indicator("Name", overlay=true) |
security(...) | request.security(...) |
sma(x, n) | ta.sma(x, n) |
ema(x, n) | ta.ema(x, n) |
rsi(x, n) | ta.rsi(x, n) |
crossover(a, b) | ta.crossover(a, b) |
crossunder(a, b) | ta.crossunder(a, b) |
highest(x, n) | ta.highest(x, n) |
lowest(x, n) | ta.lowest(x, n) |
atr(n) | ta.atr(n) |
tostring(x) | str.tostring(x) |
tonumber(x) | str.tonumber(x) |
nz(x) | nz(x) (unchanged) |
input(..., type=input.integer) | input.int(...) |
input(..., type=input.float) | input.float(...) |
input(..., type=input.bool) | input.bool(...) |
iff(cond, a, b) | ternary cond ? a : b |
valuewhen(cond, src, n) | ta.valuewhen(cond, src, n) |
Most ta.*, str.*, math.*, array.*, input.* namespaces already exist in v5. Main v6 changes:
//@version=5 → //@version=6plot.style_* constants: verify they still exist; the compiler will flag dropsfloat, int, bool) on var declarations where the compiler now requires themrequest.security lookahead param default tightened; be explicit: lookahead=barmerge.lookahead_offindicator(), strategy(), or library()input.int(..., defval=14) instead of raw int assignmentsEdit the source as a single coherent pass — don't piecemeal if the script is short. For long scripts (500+ lines), port function-by-function and re-check after each.
pine_check — server-side compile of the rewritten source. Cheaper than a full pine_set_source + pine_smart_compile cycle because it doesn't mutate the live editor.Could not find function 'xxx' → likely still a v4 bareword; prefix with ta. / str. / math.Cannot call 'input' with arguments... → switch to the typed variants input.int / input.float / input.bool / input.stringSyntax error at input 'study' → rename to indicatorSeries type required → explicit cast, e.g., float src = closeLoop:
pine_check againDon't push to the editor until pine_check is clean — saves round-trips.
pine_set_source — inject the clean v6 sourcepine_smart_compile — final in-editor compile (catches anything pine_check missed)pine_get_errors — confirm zerocapture_screenshot — visual sanity check that plots still render as expecteddata_get_strategy_results — compare metrics vs the v4/v5 baseline the user recorded previously (regressions here usually indicate a subtle porting bug like lookahead semantics)study→indicator, security→request.security, ta.* prefix adds, input.* typed conversions, etc.lookahead, barmerge, or math.round_to_mintick changes that could shift backtest numbersPINE_COMPILE_ERROR — iterate; don't declare donepine_get_source returns a huge blob, work in the local file and avoid re-reading unless needed (see CLAUDE.md rule 4 on context)