PromptBase
PromptBase SelectGet Select
Close icon
General
Home
Marketplace
Create
Hire
Login
Chat
Sell
Explore

Prompt Details

Model
(claude-5-sonnet)
Token size
1,620
Example input
[PASTE YOUR LEGACY PINE SCRIPT CODE]: //@version=3 study("Legacy Dual Timeframe Trend", overlay=true) fastLength = input(10, minval=1, title="Fast SMA Length") slowLength = input(30, minval=1, title="Slow SMA Length") higherTimeframe = input("D", type=resolution, title="Higher Timeframe") higherClose = security(tickerid, higherTimeframe, close, lookahead=barmerge.lookahead_off) fastAverage = sma(close, fastLength) slowAverage = sma(higherClose, slowLength) bullishSignal = crossover(fastAverage, slowAverage) plot(fastAverage, title="Fast Average", color=blue, linewidth=2, transp=20) plot(slowAverage, title="Higher Timeframe Average", color=orange, linewidth=2, transp=20) bgcolor(bullishSignal ? green : na, transp=85) alertcondition(bullishSignal, title="Bullish Trend Alert", message="Fast average crossed above the higher timeframe average") [DESCRIBE WHAT THE SCRIPT SHOULD DO AND ANY KNOWN BEHAVIOR TO PRESERVE]: This old indicator plots a 10-period SMA from the chart and a 30-period SMA using daily closing data. It highlights the background green when the fast average crosses above the daily average and includes an alert for that signal. Please convert it to Pine Script v6 without changing the calculations, signal timing, inputs, plot appearance, or alert. I want it to behave the same as the original.
Example output
## Step 1 — Source Assessment **Declared version:** `//@version=3` **Syntax consistency check:** The syntax is consistent with a v3 (or early v4) script — `study()`, bare `security()`, bare `sma()`/`crossover()`, `type=resolution` on `input()`, and unnamespaced color constants (`blue`, `orange`, `green`) with a `transp=` argument are all patterns from the pre-namespace era of Pine (roughly v2–v4). Nothing in the script uses syntax that postdates v4 (no `var`, no `ta.*`, no `input.*`, no `indicator()`), so the `//@version=3` declaration is plausible and I have no evidence contradicting it. **Completeness:** The script is short and self-contained — no external function calls, no `study`/`library` exports, no missing closing brackets. It appears complete enough for a reliable line-by-line conversion. **Compilation claim:** I have not compiled this script and cannot confirm it actually compiles under Pine v3 in TradingView's current editor (the v3 compiler path itself may behave differently today than it did historically). I'm treating it as a representative v3-style script based on syntax pattern-matching only. ## Step 2 — Sequential Migration Audit Relevant transitions: **v3→v4→v5→v6** (v2→v3 not applicable, nothing pre-v3 present). | Construct | Transition where it changed | |---|---| | `study()` | v4→v5: renamed to `indicator()` | | `security()` | v4→v5: moved into `request.security()` namespace | | `sma()`, `crossover()` | v4→v5: moved into `ta.*` namespace | | `input(..., type=resolution)` | v4→v5: generic typed `input()` split into dedicated functions; the `resolution` type became `input.timeframe()` | | bare `tickerid` | v3→v4: symbol/ticker info consolidated under `syminfo.*` (`syminfo.tickerid`) | | bare color constants (`blue`, `orange`, `green`) | v3→v4: moved under `color.*` namespace | | `transp=` argument on `plot()`/`bgcolor()` | v3→v4 onward: deprecated in favor of embedding alpha in the color itself via `color.new()` | | `alertcondition()` | Unchanged across all versions — no migration needed | | `lookahead=barmerge.lookahead_off` | Unchanged — `barmerge.*` namespace and this constant are stable across v4–v6 | **On the `security()`/lookahead point specifically:** the source already sets `lookahead=barmerge.lookahead_off` explicitly, which is the non-repainting choice. I'm preserving that exactly — I am not silently changing lookahead behavior. However, I flag (see Step 3) that TradingView's historical-bar alignment for `request.security()` has changed in subtler ways since v3/v4 independent of the `lookahead` argument, so identical *numeric* output on historical daily-close values is not guaranteed without a chart comparison. ## Step 3 — Preservation Risks | Item | Classification | |---|---| | `study()` → `indicator()` | Syntax-only conversion | | `sma()` → `ta.sma()`, `crossover()` → `ta.crossover()` | Syntax-only conversion | | `security()` → `request.security()`, `tickerid` → `syminfo.tickerid` | Syntax-only conversion | | `input(..., type=resolution)` → `input.timeframe()` | Syntax-only conversion (same default `"D"`, same UI control type) | | Bare color names → `color.*` | Behavior preserved through explicit rewrite — I could not verify with certainty that bare `blue`/`orange`/`green` still resolve in v6, so I used the namespaced form, which is guaranteed valid. | | `transp=` → `color.new(color.X, N)` | Behavior preserved through explicit rewrite — same reasoning; `transp` is deprecated and I'm not certain it's still accepted in v6, so I moved the transparency value into the color argument. The numeric transparency scale (0–100) is identical between `transp=` and `color.new()`'s second argument, so the visual result should match. | | Higher-timeframe historical value alignment via `request.security` | Original behavior uncertain without TradingView testing — Pine's internal handling of historical vs. realtime security requests has evolved since v3/v4 independent of the explicit `lookahead` setting; I did not alter the call, but exact historical bar values should be spot-checked. | | Overall signal timing (`ta.crossover` on the same series) | Behavior preserved directly | No lookahead bias is being introduced or removed — the explicit `barmerge.lookahead_off` is carried through unchanged. ## Step 4 — Migration Map | Original construct | Source-version meaning | v6 replacement | Reason | Expected behavioral effect | |---|---|---|---|---| | `study("Legacy Dual Timeframe Trend", overlay=true)` | Declares an indicator (v3/v4 naming) | `indicator("Legacy Dual Timeframe Trend", overlay=true)` | `study` renamed to `indicator` in v5 | None — identical script declaration | | `input(10, minval=1, title="Fast SMA Length")` | Generic numeric input | Unchanged | Generic `input()` is still valid in v6 | None | | `input("D", type=resolution, title="Higher Timeframe")` | Typed input for a timeframe/resolution string | `input.timeframe("D", title="Higher Timeframe")` | Typed `input()` split into dedicated functions in v5; `resolution` type became `input.timeframe` | None — same default, same UI dropdown behavior | | `tickerid` | Built-in variable for the chart's ticker ID | `syminfo.tickerid` | Symbol/ticker built-ins consolidated under `syminfo.*` starting v4 | None — same value | | `security(tickerid, higherTimeframe, close, lookahead=barmerge.lookahead_off)` | Requests higher-timeframe data | `request.security(syminfo.tickerid, higherTimeframe, close, lookahead=barmerge.lookahead_off)` | `security()` moved to `request.*` namespace in v5 | None expected; verify historical values manually (see Step 3) | | `sma(close, fastLength)` / `sma(higherClose, slowLength)` | Simple moving average | `ta.sma(...)` | Moved to `ta.*` namespace in v5 | None | | `crossover(fastAverage, slowAverage)` | Crossover detection | `ta.crossover(...)` | Moved to `ta.*` namespace in v5 | None | | `color=blue` / `color=orange` | Bare color constant | `color=color.blue` / `color=color.orange` | Color constants namespaced under `color.*` starting v4 | None — same RGB value | | `transp=20` (on `plot`) | 20% transparency | `color.new(color.blue/orange, 20)` | `transp=` deprecated in favor of embedding alpha in the color | None — same numeric transparency | | `bgcolor(bullishSignal ? green : na, transp=85)` | 85% transparent green background on signal bars | `bgcolor(bullishSignal ? color.new(color.green, 85) : na)` | Same as above | None — same numeric transparency | | `alertcondition(...)` | Static alert condition | Unchanged | No change across versions | None | ## Step 5 — Converted Script ```pinescript //@version=6 indicator("Legacy Dual Timeframe Trend", overlay=true) // v6: study() renamed to indicator() in Pine v5 fastLength = input(10, minval=1, title="Fast SMA Length") slowLength = input(30, minval=1, title="Slow SMA Length") higherTimeframe = input.timeframe("D", title="Higher Timeframe") // v6: input(..., type=resolution) replaced by dedicated input.timeframe() higherClose = request.security(syminfo.tickerid, higherTimeframe, close, lookahead=barmerge.lookahead_off) // v6: security() renamed to request.security(); bare tickerid replaced with syminfo.tickerid fastAverage = ta.sma(close, fastLength) // v6: sma() moved to ta.sma() slowAverage = ta.sma(higherClose, slowLength) // v6: sma() moved to ta.sma() bullishSignal = ta.crossover(fastAverage, slowAverage) // v6: crossover() moved to ta.crossover() plot(fastAverage, title="Fast Average", color=color.new(color.blue, 20), linewidth=2) // v6: bare color constant + transp= replaced with color.* namespace and color.new() transparency plot(slowAverage, title="Higher Timeframe Average", color=color.new(color.orange, 20), linewidth=2) // v6: bare color constant + transp= replaced with color.* namespace and color.new() transparency bgcolor(bullishSignal ? color.new(color.green, 85) : na) // v6: bare color constant + transp= replaced with color.* namespace and color.new() transparency alertcondition(bullishSignal, title="Bullish Trend Alert", message="Fast average crossed above the higher timeframe average") ``` ## Step 6 — Migration Report **Required changes (all necessary for v6 compilation):** - `study` → `indicator`, `security` → `request.security`, `sma`/`crossover` → `ta.sma`/`ta.crossover`, typed `input(...,type=resolution)` → `input.timeframe`, `tickerid` → `syminfo.tickerid`, bare colors → `color.*`, `transp=` → `color.new()`. Each is expected to preserve observable behavior exactly — these are namespace/rename changes, not calculation or logic changes. **No optional improvements were made** — no default values, calculation order, plot styling, or alert wording were altered beyond what the rename required. **Suspected pre-existing issues:** None identified. The script's logic (fast SMA vs. daily SMA crossover) is straightforward and was preserved as-is; I did not detect a latent bug worth flagging. **Still requires TradingView confirmation:** - Whether bare `tickerid`, bare color names, and `transp=` would actually still have compiled under a real v6 environment (I used the guaranteed-safe namespaced forms instead of assuming). - Exact historical numeric equivalence of `request.security` daily-close values versus what the legacy `security()` call would have produced, since bar-alignment internals have shifted since v3/v4 even with `lookahead` held constant. ## Step 7 — Validation Checklist - [ ] Confirm compilation in the Pine Editor with no errors/warnings - [ ] Confirm both length inputs and the timeframe input dropdown behave identically (defaults 10, 30, "D") - [ ] Compare `fastAverage` and `slowAverage` plotted values on at least 10–15 historical bars against the legacy script - [ ] Confirm plot colors and transparency (blue/orange lines, green background) visually match at the pixel/color level - [ ] Confirm `bullishSignal` fires on the same bars in both versions (no timing shift) - [ ] Confirm the alert fires at the same bar/time as the legacy alert - [ ] Check historical vs. realtime bar behavior for the higher-timeframe SMA (does the daily value update identically as the current day progresses?) - [ ] Verify no lookahead/repainting was introduced by the `request.security` conversion - [ ] Test on at least one additional symbol and one additional lower timeframe (e.g., 15m, 1h) to confirm the higher-timeframe request behaves consistently **Overall status:** Expected to preserve behavior, with the color/transparency and ticker-reference constructs converted to their explicit v6-safe namespaced equivalents rather than relying on unverified legacy aliases. This is a static-inspection conversion only — it must be compiled and run side-by-side against the legacy script in TradingView before it replaces it.
Claude

Pine Script Version Converter

Add to Cart
PromptBase Select
Get this prompt + 9 more with Select$14 your first month, then $19/mo$14 first month, then $19/mo
View Select
Instant accessInstant access
Usage rightsCommercial use
Money-back guaranteeMoney‑back
By purchasing this prompt, you agree to our terms of service
CLAUDE-5-SONNET
Tested icon
Guide icon
4 examples icon
Free credits icon
Convert legacy TradingView Pine Script from v2, v3, v4, or v5 to Pine Script v6. This prompt audits the real source version, applies each required migration stage, handles deprecated functions and changed language behavior, and returns a complete v6 script with a migration report and chart-validation checklist. Ideal for old scripts, mixed-version code, and migrations that fail or behave differently after automatic conversion.
...more
Added over 1 month ago
Report
Browse Marketplace