Skip to content

PyneComp v6.1.1 vs the Pine Script v6 specification: 2 valid scripts refused, 50 invalid scripts compiled #120

Closed

Description

@tripolskypetr

PyneComp v6.1.1 checked against the Pine Script v6 specification: 288 small Pine scripts, one topic each, written from the Pine Script v6 User Manual and measured on TradingView (BINANCE:BTCUSDT 1D, 2026-11-14/15). PyneComp's Python was run on PyneCore on the same bars and compared with the TradingView measurement.

Values match TradingView on 889 of 891 measured rows (the 2 other rows are a runtime difference, below). Wherever TradingView stops a script with a runtime error, PyneComp's code stops too. PyneComp refuses 121 scripts that TradingView refuses. The problems are below.

PyneComp does not compile valid Pine Script

  1. PyneComp refuses: Expected the end of the line, found `close`. at once close > 0. TradingView compiles and runs it. Sent alone, refused the same way.

    //@version=6
    // The once structure (v6): its block runs the first time its condition is true and never again.
    indicator("spec 07 conditional once", overlay = true)
    
    var table t = table.new(position.top_right, 2, 16, border_width = 1)
    show(int i, string k, string v) =>
        table.cell(t, 0, i, k, text_color = color.black, bgcolor = color.silver)
        table.cell(t, 1, i, v, text_color = color.black, bgcolor = color.white)
    tf(bool b) => b ? "T" : "F"
    
    var int onceRuns = 0
    var int onceNoCond = 0
    var int ifRuns = 0
    var int onceBar = -1
    once close > 0
        onceRuns += 1
        onceBar := bar_index
    once
        onceNoCond += 1
    if close > 0
        ifRuns += 1
    // the same with an if and a flag
    var bool fired = false
    var int flagRuns = 0
    if not fired and close > 0
        fired := true
        flagRuns += 1
    
    if barstate.islast
        show(0, "once close > 0: runs", str.tostring(onceRuns))
        show(1, "once close > 0: on bar", str.tostring(onceBar))
        show(2, "once without condition: runs", str.tostring(onceNoCond))
        show(3, "if close > 0: runs == bars", tf(ifRuns == bar_index + 1))
        show(4, "if + flag: runs", str.tostring(flagRuns))
    
  2. PyneComp refuses: `aggressor` is not declared. at the first line that reads aggressor.buy. TradingView compiles and runs it. Sent alone, refused the same way.

    //@version=6
    // Built-in variables the v6 Reference Manual lists that the first probes did not touch: the aggressor
    // constants of footprint rows, runtime.calculation.mode and its constants.
    indicator("spec 09 builtins reference", overlay = true)
    
    var table t = table.new(position.top_right, 2, 16, border_width = 1)
    show(int i, string k, string v) =>
        table.cell(t, 0, i, k, text_color = color.black, bgcolor = color.silver)
        table.cell(t, 1, i, v, text_color = color.black, bgcolor = color.white)
    tf(bool b) => b ? "T" : "F"
    
    if barstate.islast
        show(0, "aggressor.buy, aggressor.sell", str.tostring(aggressor.buy) + " " + str.tostring(aggressor.sell))
        show(1, "runtime.calculation.mode", runtime.calculation.mode)
        show(2, "runtime.calculation.mode.chart, .alert", runtime.calculation.mode.chart + " " + runtime.calculation.mode.alert)
        show(3, "mode == mode.chart", tf(runtime.calculation.mode == runtime.calculation.mode.chart))
    

PyneComp compiles invalid Pine Script

  1. PyneComp compiles it. TradingView: CE10039: The "str.repeat()" function cannot have a negative "repeat" value. Use a positive value in the function call.

    //@version=6
    indicator("spec 18 strings repeat negative error", overlay = true)
    s = str.repeat("a", -1)
    plot(str.length(s))
    
  2. PyneComp compiles it. TradingView: CE10276: Invalid value "2" for "begin_pos" parameter of the "str.substring" function. It must be >= 0 or lower than the "end_pos": (1)

    //@version=6
    indicator("spec 18 strings substring end before error", overlay = true)
    var t = table.new(position.top_right, 2, 16, border_width = 1)
    show(row, name, value) =>
        table.cell(t, 0, row, name)
        table.cell(t, 1, row, value)
    if barstate.islast
        show(0, "substring_end_before_begin", "[" + str.substring("abc", 2, 1) + "]")
    
  3. PyneComp compiles it. TradingView: CE10276: Invalid value "-1" for "begin_pos" parameter of the "str.substring" function. It must be >= 0 or lower than the "end_pos": (2)

    //@version=6
    indicator("spec 18 strings substring neg error", overlay = true)
    plot(str.length(str.substring("abc", -1, 2)))
    
  4. PyneComp compiles it. TradingView: CE10275: timestamp(s): unrecognized datetime format

    //@version=6
    indicator("spec 19 time string z error", overlay = true)
    plot(timestamp("2024-02-29T10:30:00Z"))
    
  5. PyneComp compiles it. TradingView: CE10077: Input's "defval" value must be between "minval" and "maxval"

    //@version=6
    indicator("spec 24 inputs minval error", overlay = true)
    belowMin = input.int(5, "below", minval = 10)
    plot(belowMin)
    
  6. PyneComp compiles it. TradingView: CE10079: input's defval should be in options, but 5 is not in [1, 2, 3]

    //@version=6
    indicator("spec 24 inputs options error", overlay = true)
    notInOptions = input.int(5, "not listed", options = [1, 2, 3])
    plot(notInOptions)
    
  7. PyneComp compiles it. TradingView: CE10040: The "input.int()" function cannot have a "step" value less than 1. Use a value of 1 or greater in the function call.

    //@version=6
    indicator("spec 24 inputs step zero error", overlay = true)
    stepZero = input.int(5, "step zero", step = 0)
    plot(stepZero)
    
  8. PyneComp compiles it. TradingView: CE10099: Only libraries can contain exported functions.

    //@version=6
    indicator("spec 03 declaration export in indicator error", overlay = true)
    export f(float x) => x + 1
    plot(f(close))
    
  9. PyneComp compiles it. TradingView: CE10127: A variable declared with the "simple" keyword cannot accept values of the "series float" form. Assign a "simple" value to this variable or remove the "simple" keyword from its declaration.

    //@version=6
    indicator("spec 04 type system qualifiers error", overlay = true)
    simple float rand = math.random()
    plot(rand)
    
  10. PyneComp compiles it. TradingView: CE10123: Cannot call "array.push" with argument "value"="s". An argument of "literal string" type was used but a "series float" is expected.

    //@version=6
    indicator("spec 04 types array push wrong type error", overlay = true)
    a = array.new<float>()
    array.push(a, "s")
    plot(array.size(a))
    
  11. PyneComp compiles it. TradingView: CE10187: Cannot compare a value to "na" directly. Use the "na()" function instead.

    //@version=6
    indicator("spec 04 types compare with na error", overlay = true)
    plot(close == na ? 1 : 0)
    
  12. PyneComp compiles it. TradingView: CE10173: Cannot assign a value of the "string" type to the "x" variable. The variable is declared with the "int" type.

    //@version=6
    indicator("spec 04 types reassign other type error", overlay = true)
    x = 1
    x := "s"
    plot(1)
    
  13. PyneComp compiles it. TradingView: CE10088: Cannot modify global variable "counter" in function

    //@version=6
    indicator("spec 05 variable declarations error", overlay = true)
    int counter = 0
    bump() =>
        counter := counter + 1
    bump()
    plot(counter)
    
  14. PyneComp compiles it. TradingView: CE10235: Return type of one of the "if" or "switch" blocks is not compatible with return type of other block(s) (series float; literal string)

    //@version=6
    indicator("spec 07 conditional structures error", overlay = true)
    x = if close > open
        close
    else
        "open"
    plot(close)
    
  15. PyneComp compiles it. TradingView: CE10135: "break" is only allowed inside loops.

    //@version=6
    indicator("spec 08 loops break outside error", overlay = true)
    break
    plot(close)
    
  16. PyneComp compiles it. TradingView: CE10136: "continue" is only allowed inside loops.

    //@version=6
    indicator("spec 08 loops continue outside error", overlay = true)
    continue
    plot(close)
    
  17. PyneComp compiles it. TradingView: CE10174: Variable "i" cannot be mutable

    //@version=6
    indicator("spec 08 loops counter assign error", overlay = true)
    float s = 0
    for i = 0 to 3
        i := i + 10
        s += i
    plot(s)
    
  18. PyneComp compiles it. TradingView: CE10174: Variable "x" cannot be mutable

    //@version=6
    indicator("spec 08 loops for in assign error", overlay = true)
    float s = 0
    a = array.from(1, 2, 3)
    for x in a
        x := x + 10
        s += x
    plot(s)
    
  19. PyneComp compiles it. TradingView: CE10123: Cannot call "foreach" with argument "id"="close". An argument of "series float" type was used but a "array<type>" is expected.

    //@version=6
    indicator("spec 08 loops for in series error", overlay = true)
    total = 0.0
    for v in close
        total += v
    plot(total)
    
  20. PyneComp compiles it. TradingView: CE10113: Function "f" already defined. The "f" function has overloads using the same number of required parameters without them having distinct types. Function overloads with the same number of required parameters must have explicit parameter types that are unique among overloads.

    //@version=6
    indicator("spec 10 functions duplicate error", overlay = true)
    f(x) => x + 1
    f(x) => x + 2
    plot(f(1))
    
  21. PyneComp compiles it. TradingView: CE10110: The "f" function has overloads with the same parameters. The type of parameters must be different in overloaded versions of functions.

    //@version=6
    indicator("spec 10 functions same types error", overlay = true)
    f(float x) => 1
    f(float y) => 2
    plot(f(close))
    
  22. PyneComp compiles it. TradingView: CE10092: Invalid assignment. Cannot assign a tuple to a variable "a".

    //@version=6
    indicator("spec 10 functions tuple to scalar error", overlay = true)
    f() => [1, 2]
    a = f()
    plot(a)
    
  23. PyneComp compiles it. TradingView: CE10271: Could not find function or function reference 'gcd'

    //@version=6
    indicator("spec 10 user-defined functions error", overlay = true)
    gcd(int x, int y) => y == 0 ? x : gcd(y, x % y)
    plot(gcd(12, 8))
    
  24. PyneComp compiles it. TradingView: CE10186: Duplicated field: 'x'.

    //@version=6
    indicator("spec 11 objects duplicate field error", overlay = true)
    type P
        float x
        float x
    p = P.new()
    plot(p.x)
    
  25. PyneComp compiles it. TradingView: CE10185: Duplicated field: "a".

    //@version=6
    indicator("spec 12 enums duplicate field error", overlay = true)
    enum E
        a
        a
    e = E.a
    plot(e == E.a ? 1 : 0)
    
  26. PyneComp compiles it. TradingView: CE10236: The "this" argument is not used. The first method argument should be used.

    //@version=6
    indicator("spec 13 methods error array", overlay = true)
    method kind(array<float> this) => "array<float>"
    array<float> a = array.new<float>(1, 1.0)
    plot(close, title = a.kind())
    
  27. PyneComp compiles it. TradingView: CE10236: The "this" argument is not used. The first method argument should be used.

    //@version=6
    indicator("spec 13 methods error line", overlay = true)
    method kind(line this) => "line"
    var line l = line.new(0, 0, 1, 1)
    plot(close, title = l.kind())
    
  28. PyneComp compiles it. TradingView: CE10236: The "this" argument is not used. The first method argument should be used.

    //@version=6
    indicator("spec 13 methods error udt", overlay = true)
    type P
        float v = 0.0
    method kind(P this) => "P"
    P p = P.new(1.0)
    plot(close, title = p.kind())
    
  29. PyneComp compiles it. TradingView: CE10192: The first method argument must be explicitly typed

    //@version=6
    indicator("spec 13 methods untyped receiver error", overlay = true)
    method m(x) => x + 1
    plot(m(1))
    
  30. PyneComp compiles it. TradingView: CE10123: Cannot call "array.new" with argument "initial_value"="x". An argument of "literal string" type was used but a "series float" is expected.

    //@version=6
    indicator("spec 14 arrays wrong element type error", overlay = true)
    a = array.new<float>(2, "x")
    plot(array.get(a, 0))
    
  31. PyneComp compiles it. TradingView: CE10123: Cannot call "map.put" with argument "key"="1". An argument of "literal int" type was used but a "series string" is expected.

    //@version=6
    indicator("spec 16 maps wrong key type error", overlay = true)
    m = map.new<string, float>()
    map.put(m, 1, 2.0)
    plot(map.size(m))
    
  32. PyneComp compiles it. TradingView: CE10040: The "plot()" function cannot have a "linewidth" value less than 1. Use a value of 1 or greater in the function call.

    //@version=6
    indicator("spec 40 to v6 linewidth error", overlay = true)
    plot(close, linewidth = 0)
    
  33. PyneComp compiles it. TradingView: CE10167: The history-referencing operator can not be used on literals or built-in constants.

    //@version=6
    indicator("spec 40 to v6 literal history error", overlay = true)
    plot(6[1])
    
  34. PyneComp compiles it. TradingView: CE10123: Cannot call "ta.ema" with argument "length"="len". An argument of "series int" type was used but a "simple int" is expected.

    //@version=6
    indicator("spec 40 to v6 mutable length counter error", overlay = true)
    int len = 5
    for i = 0 to 2
        len := i + 5
    plot(ta.ema(close, len))
    
  35. PyneComp compiles it. TradingView: CE10123: Cannot call "ta.ema" with argument "length"="len". An argument of "series int" type was used but a "simple int" is expected.

    //@version=6
    indicator("spec 40 to v6 mutable length error", overlay = true)
    int len = 5
    if bar_index > 10
        len := 6
    plot(ta.ema(close, len))
    
  36. PyneComp compiles it. TradingView: CE10123: Cannot call "ta.ema" with argument "length"="len". An argument of "series int" type was used but a "simple int" is expected.

    //@version=6
    indicator("spec 40 to v6 mutable length loop error", overlay = true)
    int len = 5
    for i = 0 to 2
        len := len + 1
    plot(ta.ema(close, len))
    
  37. PyneComp compiles it. TradingView: CE10103: Return type of the "if" or "switch" blocks of constant type should have "else" or "default" block.

    //@version=6
    indicator("spec 40 to v6 switch default error", overlay = true)
    style = switch
        bar_index % 2 == 0 => plot.style_line
        bar_index % 2 == 1 => plot.style_circles
    plot(close, style = style)
    
  38. PyneComp compiles it. TradingView: CE10139: const built-in variable can not be used as return value in if statement in case its condition is not constant.

    //@version=6
    indicator("spec 40 to v6 switch style series", overlay = true)
    style = switch
        bar_index % 2 == 0 => plot.style_line
        => plot.style_circles
    plot(close, "styled", style = style)
    
  39. PyneComp compiles it. TradingView: CE10150: "class" cannot be used as a variable or function name.

    //@version=6
    indicator("spec 41 to v5 reserved v6 class", overlay = true)
    class = 5.0
    do = 7.0
    var t = table.new(position.top_right, 2, 16, border_width = 1)
    show(row, name, value) =>
        table.cell(t, 0, row, name)
        table.cell(t, 1, row, value)
    if barstate.islast
        show(0, "class", str.tostring(class))
        show(1, "do", str.tostring(do))
    
  40. PyneComp compiles it. TradingView: CE10150: "text" cannot be used as a variable or function name.

    //@version=6
    indicator("spec 41 to v5 reserved v6", overlay = true)
    text = "a"
    range = high - low
    var t = table.new(position.top_right, 2, 16, border_width = 1)
    show(row, name, value) =>
        table.cell(t, 0, row, name)
        table.cell(t, 1, row, value)
    if barstate.islast
        show(0, "text", text)
        show(1, "range_pos", range >= 0 ? "T" : "F")
    
  41. PyneComp compiles it. TradingView: CE10150: "range" cannot be used as a variable or function name.

    //@version=6
    indicator("spec 41 to v5 reserved v6 local error", overlay = true)
    f(float x) =>
        range = x > 0
        [x, range]
    [a, b] = f(close)
    plot(b ? a : 0)
    
  42. PyneComp compiles it. TradingView: CE10150: "range" cannot be used as a variable or function name.

    //@version=6
    indicator("spec 41 to v5 reserved v6 range", overlay = true)
    range = high - low
    var t = table.new(position.top_right, 2, 16, border_width = 1)
    show(row, name, value) =>
        table.cell(t, 0, row, name)
        table.cell(t, 1, row, value)
    if barstate.islast
        show(0, "range_pos", range >= 0 ? "T" : "F")
    
  43. PyneComp compiles it. TradingView: CE10274: color.new: transp argument value should be between 0 and 100

    //@version=6
    indicator("spec 32 colors transparency range error", overlay = true)
    c = color.new(color.red, 150)
    plot(close, color = c)
    
  44. PyneComp compiles it. TradingView: CE10041: Invalid value "6000" for "num" parameter of the "max_bars_back()" function. It must be between 0 and 5000

    //@version=6
    indicator("spec 39 limitations history max bars back", overlay = true)
    
    var table t = table.new(position.top_right, 2, 16, border_width = 1)
    show(int i, string k, string v) =>
        table.cell(t, 0, i, k, text_color = color.black, bgcolor = color.silver)
        table.cell(t, 1, i, v, text_color = color.black, bgcolor = color.white)
    tf(bool b) => b ? "T" : "F"
    
    max_bars_back(close, 6000)
    float back = close[5999]
    
    if barstate.islast
        show(0, "max_bars_back(close, 6000): close[5999] ran", "ok")
        show(1, "na(close[5999])", tf(na(back)))
    
  45. PyneComp compiles it. TradingView: 'class' cannot be used as a variable or function name. (Pine v5, no error code)

    //@version=5
    indicator("spec 41 to v5 reserved class error", overlay = true)
    class = 5.0
    plot(class)
    
  46. PyneComp compiles it. TradingView: 'do' cannot be used as a variable or function name. (Pine v5, no error code)

    //@version=5
    indicator("spec 41 to v5 reserved do error", overlay = true)
    do = request.security(syminfo.tickerid, "D", open)
    plot(do)
    
  47. PyneComp compiles it. TradingView: 'text' cannot be used as a variable or function name. (Pine v5, no error code)

    //@version=5
    indicator("spec 41 to v5 reserved error", overlay = true)
    text = "a"
    plot(close)
    
  48. PyneComp compiles it. TradingView: CE10245: A library must contain at least one exported function, method, or type.

    //@version=6
    library("spec03DeclarationLibraryNoExport")
    f(x) => x + 1
    plot(f(close))
    
  49. PyneComp compiles it. TradingView: CE10292: Invalid argument "title" in "library" call. It cannot contain spaces, special characters or begin with a digit.

    //@version=6
    library("spec 03 declaration library title error")
    export f(float x) => x + 1
    
  50. PyneComp compiles it. TradingView: CE10041: Invalid value "6000" for "max_bars_back" parameter of the "indicator()" function. It must be between 0 and 5000

    //@version=6
    indicator("spec 03 max bars back range error", overlay = true, max_bars_back = 6000)
    plot(close)
    

Runtime

  1. PyneCore runtime, not the compiler (PyneComp's code and an independent transpiler's code give the same): ta.linreg(close, 1, 0) returns close. TradingView returns na.

    //@version=6
    indicator("linreg length 1")
    v = ta.linreg(close, 1, 0)
    plot(na(v) ? 1 : 0)
    

Not checked yet

PyneComp did not answer these: compilation was disabled for the account before they were sent.

  1. Libraries — TradingView compiles; values measured

    //@version=6
    // Libraries: importing a published library by user/name/version with an alias and calling its
    // exported functions (ZenAndTheArtOfTrading/ZenLibrary/2, also kept in assets/pine/lib).
    indicator("spec 25 libraries", overlay = true)
    import ZenAndTheArtOfTrading/ZenLibrary/2 as zen
    
    var table t = table.new(position.top_right, 2, 16, border_width = 1)
    show(int i, string k, string v) =>
        table.cell(t, 0, i, k, text_color = color.black, bgcolor = color.silver)
        table.cell(t, 1, i, v, text_color = color.black, bgcolor = color.white)
    tf(bool b) => b ? "T" : "F"
    
    float decimals = zen.getDecimals()
    float truncated2 = zen.truncate(1.23456)
    float truncated3 = zen.truncate(1.23456, 3)
    float pips = zen.toPips(0.05)
    float bodySize = zen.getBodySize()
    float ma = zen.getMA(3, "SMA")
    float sma3 = ta.sma(close, 3)
    
    if barstate.islast
        show(0, "zen.getDecimals()", str.tostring(decimals))
        show(1, "zen.truncate(1.23456)", str.tostring(truncated2))
        show(2, "zen.truncate(1.23456, 3)", str.tostring(truncated3))
        show(3, "zen.toPips(0.05)", str.tostring(pips))
        show(4, "zen.getBodySize() == |c - o| / mintick", tf(bodySize == math.abs(close - open) / syminfo.mintick))
        show(5, "zen.getMA(3, \"SMA\") == ta.sma(close, 3)", tf(ma == sma3))
    
  2. Strategy — compiles; values measured

    //@version=6
    // Strategies: one long entry on bar 5 filled at the next bar's open, closed on bar 10 at the next
    // bar's open; the position, trade counters, prices and profit are read through plots (a strategy's
    // table is not visible in the measuring layout).
    strategy("spec 29 strategy", overlay = true, initial_capital = 100000, default_qty_type = strategy.fixed,
         default_qty_value = 1, commission_type = strategy.commission.percent, commission_value = 0)
    
    if bar_index == 5
        strategy.entry("L", strategy.long)
    if bar_index == 10
        strategy.close("L")
    
    plot(strategy.position_size, "position_size")
    plot(strategy.closedtrades, "closedtrades")
    plot(strategy.opentrades, "opentrades")
    plot(strategy.initial_capital, "initial_capital")
    plot(strategy.closedtrades.entry_price(0), "entry_price")
    plot(strategy.closedtrades.exit_price(0), "exit_price")
    plot(strategy.closedtrades.profit(0), "profit")
    plot(strategy.netprofit, "netprofit")
    plot(strategy.equity, "equity")
    plot(strategy.closedtrades.entry_bar_index(0), "entry_bar")
    plot(strategy.closedtrades.exit_bar_index(0), "exit_bar")
    
  3. Strategy with alert_message — compiles; values measured

    //@version=6
    // The @strategy_alert_message annotation: the default message of a strategy's order-fill alerts, with
    // {{placeholders}} replaced when the alert fires; it compiles like a comment and changes no value.
    //@strategy_alert_message {{strategy.order.action}} {{ticker}} {{strategy.order.contracts}} at {{strategy.order.price}}
    strategy("spec 29 strategy alert message", overlay = true, initial_capital = 100000, default_qty_type = strategy.fixed, default_qty_value = 2)
    
    if bar_index == 5
        strategy.entry("L", strategy.long)
    
    plot(strategy.position_size, "position_size")
    plot(strategy.opentrades, "opentrades")
    
  4. Strategy with a fixed quantity — compiles; values measured

    //@version=6
    // strategy() with an explicit fixed quantity of 1: the size an entry takes against the default
    strategy("spec 29 strategy qty fixed", overlay = true, default_qty_type = strategy.fixed, default_qty_value = 1)
    if bar_index == 10
        strategy.entry("L", strategy.long)
    plot(strategy.position_size, "position_size")
    plot(strategy.position_size * strategy.opentrades.entry_price(0) / strategy.initial_capital, "size_x_price_over_capital")
    
  5. indicator() declaration — compiles; values measured

    //@version=6
    // Declaration statement of an indicator: title, shorttitle, overlay, format, precision,
    // max_bars_back. precision = 3 shows three decimals in the legend: 1 / 3 reads 0.333.
    indicator("spec 03 declaration indicator", "s03", overlay = true, format = format.price, precision = 3,
         max_bars_back = 100, explicit_plot_zorder = true)
    
    plot(1 / 3, "one third", color.blue, display = display.data_window + display.status_line)
    plot(hlc3, "hlc3", color.gray, display = display.data_window + display.status_line)
    
  6. max_labels_count = 600 — refuses: CE10178: The script max_labels_count value (600) is greater than the maximum possible value (500)

    //@version=6
    indicator("spec 03 max labels range error", overlay = true, max_labels_count = 600)
    plot(close)
    
  7. max_lines_count = 600 — refuses: CE10178: The script max_lines_count value (600) is greater than the maximum possible value (500)

    //@version=6
    indicator("spec 03 max lines range error", overlay = true, max_lines_count = 600)
    plot(close)
    
  8. max_polylines_count = 200 — refuses: CE10041: Invalid value "200" for "max_polylines_count" parameter of the "indicator()" function. It must be between 1 and 100

    //@version=6
    indicator("spec 03 max polylines range error", overlay = true, max_polylines_count = 200)
    plot(close)
    
  9. Negative precision — refuses: CE10039: The "indicator()" function cannot have a negative "precision" value. Use a positive value in the function call.

    //@version=6
    indicator("spec 03 negative precision error", overlay = true, precision = -1)
    plot(close)
    
  10. indicator() inside an if — refuses: CE10188: Cannot use "indicator" in local scope

    //@version=6
    if close > 0
        indicator("spec 05 scopes indicator in if error", overlay = true)
    plot(close)
    
  11. request.*() in a loop or conditional with dynamic_requests = false — refuses: CE10054: Cannot use "request.*()" call within loops or conditional structures, when "dynamic_requests" is "false" in the "indicator()" function.

    //@version=6
    indicator("spec 40 to v6 static request error", overlay = true, dynamic_requests = false)
    float v = na
    if bar_index % 2 == 0
        v := request.security(syminfo.tickerid, "1W", close)
    plot(v)
    
  12. when = in strategy.entry (v6) — refuses: CE10120: The "strategy.entry" function does not have an argument with the name "when"

    //@version=6
    strategy("spec 40 to v6 when error", overlay = true)
    strategy.entry("L", strategy.long, when = bar_index == 5)
    plot(strategy.position_size)
    
  13. Migration to v5: no commission — compiles; values measured

    //@version=4
    // Pine v4: commission_type is a string; a v4 script of the corpus passes the literal 'strategy.commission_percent' (none)
    strategy("spec 41 to v5 commission none", overlay = true, initial_capital = 100000, default_qty_type = strategy.fixed, default_qty_value = 1)
    if bar_index % 20 == 0
        strategy.entry("L", strategy.long)
    if bar_index % 20 == 10
        strategy.close("L")
    plot(strategy.netprofit, "netprofit")
    plot(strategy.closedtrades, "closed")
    
  14. Migration to v5: commission in percent — compiles; values measured

    //@version=4
    // Pine v4: commission_type is a string; a v4 script of the corpus passes the literal 'strategy.commission_percent' (percent)
    strategy("spec 41 to v5 commission percent", overlay = true, initial_capital = 100000, default_qty_type = strategy.fixed, default_qty_value = 1, commission_type = strategy.commission.percent, commission_value = 0.1)
    if bar_index % 20 == 0
        strategy.entry("L", strategy.long)
    if bar_index % 20 == 10
        strategy.close("L")
    plot(strategy.netprofit, "netprofit")
    plot(strategy.closedtrades, "closed")
    
  15. Migration to v5: commission given as a string — refuses: Invalid strategy properties. Please remove the strategy from the chart and add it again.

    //@version=4
    // Pine v4: commission_type is a string; a v4 script of the corpus passes the literal 'strategy.commission_percent' (string)
    strategy("spec 41 to v5 commission string error", overlay = true, initial_capital = 100000, default_qty_type = strategy.fixed, default_qty_value = 1, commission_type = 'strategy.commission_percent', commission_value = 0.1)
    if bar_index % 20 == 0
        strategy.entry("L", strategy.long)
    if bar_index % 20 == 10
        strategy.close("L")
    plot(strategy.netprofit, "netprofit")
    plot(strategy.closedtrades, "closed")
    
  16. Migration to v5: iff and offset — compiles; values measured

    //@version=4
    // Pine v4: iff() is a function, both arms run on every bar (a global array counts the arms); offset(s, n) is s[n]
    study("spec 41 to v5 iff offset", overlay = true)
    var arms = array.new_int(0)
    f() =>
        array.push(arms, 1)
        1
    g() =>
        array.push(arms, 2)
        2
    picked = iff(bar_index % 2 == 0, f(), g())
    ternary = bar_index % 2 == 0 ? f() : g()
    prev = offset(close, 1)
    var t = table.new(position.top_right, 2, 16, border_width = 1)
    show(row, name, value) =>
        table.cell(t, 0, row, name)
        table.cell(t, 1, row, value)
    if barstate.islast
        show(0, "arms_per_bar", tostring(array.size(arms) / (bar_index + 1)))
        show(1, "picked", tostring(picked))
        show(2, "ternary", tostring(ternary))
        show(3, "offset_eq_history", prev == close[1] ? "T" : "F")
    
  17. Migration to v5: inputs — compiles; values measured

    //@version=4
    // Pine v4: one input() with type = input.* constants; v5 splits it into input.int(), input.float(), ...
    study("spec 41 to v5 inputs", overlay = true)
    i = input(5, type = input.integer, title = "i")
    f = input(1.5, type = input.float, title = "f")
    b = input(true, type = input.bool, title = "b")
    s = input("A", type = input.string, title = "s")
    src = input(close, type = input.source, title = "src")
    res = input("D", type = input.resolution, title = "res")
    sess = input("0930-1600", type = input.session, title = "sess")
    sym = input("BINANCE:BTCUSDT", type = input.symbol, title = "sym")
    plain = input("AAPL", title = "plain")
    var t = table.new(position.top_right, 2, 16, border_width = 1)
    show(row, name, value) =>
        table.cell(t, 0, row, name)
        table.cell(t, 1, row, value)
    if barstate.islast
        show(0, "i", tostring(i))
        show(1, "f", tostring(f))
        show(2, "b", b ? "T" : "F")
        show(3, "s", s)
        show(4, "src_eq_close", src == close ? "T" : "F")
        show(5, "res", res)
        show(6, "sess", sess)
        show(7, "sym", sym)
        show(8, "plain", plain)
    
  18. Migration to v5: lookahead as a bool — compiles; values measured

    //@version=4
    // Pine v4: lookahead takes a bool; v5 requires barmerge.lookahead_on / lookahead_off
    study("spec 41 to v5 lookahead bool", overlay = true)
    secTrue = security(syminfo.tickerid, "W", close[1], lookahead = true)
    secOn = security(syminfo.tickerid, "W", close[1], lookahead = barmerge.lookahead_on)
    secFalse = security(syminfo.tickerid, "W", close, lookahead = false)
    secOff = security(syminfo.tickerid, "W", close, lookahead = barmerge.lookahead_off)
    var t = table.new(position.top_right, 2, 16, border_width = 1)
    show(row, name, value) =>
        table.cell(t, 0, row, name)
        table.cell(t, 1, row, value)
    if barstate.islast
        show(0, "true_eq_on", secTrue == secOn ? "T" : "F")
        show(1, "false_eq_off", secFalse == secOff ? "T" : "F")
    
  19. Migration to v5: renamed built-ins — compiles; values measured

    //@version=4
    // Pine v4: study() and the bare technical, math and string names v5 moved into ta., math., str.
    study("spec 41 to v5 names", overlay = true)
    s3 = sma(close, 3)
    manual = (close + close[1] + close[2]) / 3
    h5 = highest(high, 5)
    hman = max(high, high[1], high[2], high[3], high[4])
    r14 = rsi(close, 14)
    a = abs(-2)
    sq = sqrt(16)
    ts = tostring(10.5)
    tn = tonumber("3")
    var t = table.new(position.top_right, 2, 16, border_width = 1)
    show(row, name, value) =>
        table.cell(t, 0, row, name)
        table.cell(t, 1, row, value)
    if barstate.islast
        show(0, "sma3_eq_manual", abs(s3 - manual) < 1e-6 ? "T" : "F")
        show(1, "highest5_eq_manual", h5 == hman ? "T" : "F")
        show(2, "rsi14_in_range", r14 > 0 and r14 < 100 ? "T" : "F")
        show(3, "abs", tostring(a))
        show(4, "sqrt", tostring(sq))
        show(5, "tostring", ts)
        show(6, "tonumber", tostring(tn))
    
  20. Migration to v5: reserved words — compiles; values measured

    //@version=4
    // Pine v4: text, range and in are not reserved; v5 reserves them (catch class do ellipse in is polygon range return struct text throw try)
    study("spec 41 to v5 reserved", overlay = true)
    text = "a"
    range = high - low
    var t = table.new(position.top_right, 2, 16, border_width = 1)
    show(row, name, value) =>
        table.cell(t, 0, row, name)
        table.cell(t, 1, row, value)
    if barstate.islast
        show(0, "text", text)
        show(1, "range_pos", range >= 0 ? "T" : "F")
    
  21. Migration to v5: rsi overload — compiles; values measured

    //@version=4
    // Pine v4: rsi(x, y) of two series is 100 - 100 / (1 + x / y); v5 removed the overload
    study("spec 41 to v5 rsi overload", overlay = true)
    u = rma(max(change(close), 0), 14)
    d = rma(-min(change(close), 0), 14)
    pair = rsi(u, d)
    formula = 100.0 - (100.0 / (1.0 + u / d))
    single = rsi(close, 14)
    var t = table.new(position.top_right, 2, 16, border_width = 1)
    show(row, name, value) =>
        table.cell(t, 0, row, name)
        table.cell(t, 1, row, value)
    if barstate.islast
        show(0, "pair_eq_formula", abs(pair - formula) < 1e-6 ? "T" : "F")
        show(1, "pair_eq_single", abs(pair - single) < 1e-6 ? "T" : "F")
    
  22. Migration to v5: session days — compiles; values measured

    //@version=4
    // Pine v4: a session without days means weekdays ("23456"); v5 reads it as every day
    study("spec 41 to v5 session days", overlay = true)
    t1 = time("D", "0000-2359")
    t2 = time("D", "0000-2359:1234567")
    cnt_default = cum(na(t1) ? 0 : 1)
    cnt_all = cum(na(t2) ? 0 : 1)
    bars = bar_index + 1
    var t = table.new(position.top_right, 2, 16, border_width = 1)
    show(row, name, value) =>
        table.cell(t, 0, row, name)
        table.cell(t, 1, row, value)
    if barstate.islast
        show(0, "cnt_default", tostring(cnt_default))
        show(1, "cnt_all", tostring(cnt_all))
        show(2, "bars", tostring(bars))
        show(3, "all_eq_bars", cnt_all == bars ? "T" : "F")
        show(4, "default_lt_all", cnt_default < cnt_all ? "T" : "F")
    
  23. Migration to v5: session days in a v5 script — compiles; values measured

    //@version=5
    // Pine v5: a session without days means every day ("1234567")
    indicator("spec 41 to v5 session days v5", overlay = true)
    t1 = time("D", "0000-2359")
    cnt_default = ta.cum(na(t1) ? 0 : 1)
    bars = bar_index + 1
    var t = table.new(position.top_right, 2, 16, border_width = 1)
    show(row, name, value) =>
        table.cell(t, 0, row, name)
        table.cell(t, 1, row, value)
    if barstate.islast
        show(0, "cnt_default", str.tostring(cnt_default))
        show(1, "bars", str.tostring(bars))
        show(2, "default_eq_bars", cnt_default == bars ? "T" : "F")
    
  24. Migration to v5: strategy.exit — compiles; values measured

    //@version=4
    // Pine v4: strategy.exit() without profit/limit/loss/stop/trail compiles (and does nothing); v5 refuses it
    strategy("spec 41 to v5 strategy exit", overlay = true, pyramiding = 1)
    if bar_index % 20 == 0
        strategy.entry("L", strategy.long)
    strategy.exit("x", "L")
    plot(strategy.closedtrades, "closed")
    plot(strategy.opentrades, "open")
    
  25. Migration to v5: strategy.exit without any exit level — refuses: strategy.exit must have at least one of the following parameters: 'profit', 'limit', 'loss', 'stop' or one of the following pairs: 'trail_offset' and 'trail_price' / 'trail_points'. To close the position at market price, use 'strategy.close'

    //@version=5
    strategy("spec 41 to v5 strategy exit error", overlay = true)
    if bar_index % 20 == 0
        strategy.entry("L", strategy.long)
    strategy.exit("x", "L")
    plot(strategy.closedtrades, "closed")
    
  26. Lines and boxes — compiles; values measured

    //@version=6
    // Lines, boxes, linefills, polylines: getters, line.get_price() along and beyond the segment,
    // copies are independent, *.all, delete; the style, extend and xloc constants are strings.
    indicator("spec 34 lines and boxes", overlay = true, max_lines_count = 10, max_boxes_count = 10)
    
    var table t = table.new(position.top_right, 2, 16, border_width = 1)
    show(int i, string k, string v) =>
        table.cell(t, 0, i, k, text_color = color.black, bgcolor = color.silver)
        table.cell(t, 1, i, v, text_color = color.black, bgcolor = color.white)
    tf(bool b) => b ? "T" : "F"
    
    if barstate.islast
        line l = line.new(bar_index - 10, 1, bar_index, 11, extend = extend.none, color = color.blue, style = line.style_dashed, width = 2)
        line c = line.copy(l)
        line.set_y1(c, 100)
        box b = box.new(bar_index - 5, 10, bar_index, 2, border_color = color.red, bgcolor = color.new(color.red, 80), text = "box")
        linefill f = linefill.new(l, c, color.new(color.gray, 80))
        chart.point p = chart.point.from_index(bar_index - 3, 7.5)
        array<chart.point> pts = array.from(chart.point.from_index(bar_index - 4, 1.0), chart.point.from_index(bar_index - 2, 3.0), chart.point.from_index(bar_index, 2.0))
        polyline pl = polyline.new(pts, line_color = color.purple)
        int linesBefore = line.all.size()
        line.delete(c)
        show(0, "line x1 y1 x2 y2 (x rel. bar_index)", str.tostring(line.get_x1(l) - bar_index) + " " + str.tostring(line.get_y1(l)) + " " + str.tostring(line.get_x2(l) - bar_index) + " " + str.tostring(line.get_y2(l)))
        show(1, "get_price(l, bar_index - 5)", str.tostring(line.get_price(l, bar_index - 5)))
        show(2, "get_price(l, bar_index + 10) (beyond)", str.tostring(line.get_price(l, bar_index + 10)))
        show(3, "copy then set_y1(copy, 100): original y1", str.tostring(line.get_y1(l)))
        show(4, "line.all.size() before/after delete", str.tostring(linesBefore) + " " + str.tostring(line.all.size()))
        show(5, "box left top right bottom", str.tostring(box.get_left(b) - bar_index) + " " + str.tostring(box.get_top(b)) + " " + str.tostring(box.get_right(b) - bar_index) + " " + str.tostring(box.get_bottom(b)))
        show(6, "box.all.size(), polyline.all.size()", str.tostring(box.all.size()) + " " + str.tostring(polyline.all.size()))
        show(7, "linefill.get_line1(f) == l", tf(linefill.get_line1(f) == l))
        show(8, "chart.point index price", str.tostring(p.index - bar_index) + " " + str.tostring(p.price))
        show(9, "line.style_solid dotted dashed", line.style_solid + " " + line.style_dotted + " " + line.style_dashed)
        show(10, "line.style_arrow_left right both", line.style_arrow_left + " " + line.style_arrow_right + " " + line.style_arrow_both)
        show(11, "extend.none left right both", extend.none + " " + extend.left + " " + extend.right + " " + extend.both)
        show(12, "xloc.bar_index bar_time", xloc.bar_index + " " + xloc.bar_time)
    
  27. Text and shapes — compiles; values measured

    //@version=6
    // Text and shapes: label getters and setters, label.all and delete, the label.style_*, yloc.*,
    // shape.* and location.* constants; plotshape(), plotchar() and plotarrow() compile.
    indicator("spec 35 text and shapes", overlay = true, max_labels_count = 10)
    
    var table t = table.new(position.top_right, 2, 16, border_width = 1)
    show(int i, string k, string v) =>
        table.cell(t, 0, i, k, text_color = color.black, bgcolor = color.silver)
        table.cell(t, 1, i, v, text_color = color.black, bgcolor = color.white)
    tf(bool b) => b ? "T" : "F"
    
    plotshape(bar_index % 10 == 0, "shape", shape.circle, location.top, color.blue, size = size.tiny)
    plotchar(bar_index % 10 == 5, "char", "x", location.top, color.orange, size = size.tiny)
    plotarrow(close - open, "arrow", color.teal, color.orange, display = display.none)
    
    if barstate.islast
        label lb = label.new(bar_index, high, "hi", style = label.style_label_down, yloc = yloc.price, textcolor = color.white, size = size.small, tooltip = "tip")
        label cp = label.copy(lb)
        label.set_text(cp, "copy")
        label.set_xy(cp, bar_index - 2, low)
        int before = label.all.size()
        label.delete(cp)
        show(0, "label.get_text", label.get_text(lb))
        show(1, "get_x == bar_index, get_y == high", tf(label.get_x(lb) == bar_index) + " " + tf(label.get_y(lb) == high))
        show(2, "copy: set_text/set_xy: original text", label.get_text(lb))
        show(3, "label.all.size() before/after delete", str.tostring(before) + " " + str.tostring(label.all.size()))
        show(4, "label.style_label_up down none", label.style_label_up + " " + label.style_label_down + " " + label.style_none)
        show(5, "label.style_circle arrowup xcross", label.style_circle + " " + label.style_arrowup + " " + label.style_xcross)
        show(6, "yloc.price abovebar belowbar", yloc.price + " " + yloc.abovebar + " " + yloc.belowbar)
        show(7, "shape.circle xcross triangleup", shape.circle + " " + shape.xcross + " " + shape.triangleup)
        show(8, "shape.labelup flag diamond", shape.labelup + " " + shape.flag + " " + shape.diamond)
        show(9, "location.abovebar belowbar top absolute", location.abovebar + " " + location.belowbar + " " + location.top + " " + location.absolute)
        show(10, "text.align_left, size.normal", text.align_left + " " + size.normal)
    
  28. Drawing limits — compiles; values measured

    //@version=6
    // Drawing limits: labels beyond max_labels_count (default ~50) are garbage-collected, the oldest first;
    // lines likewise; one table per position, a new table.new() at a taken position replaces the old one.
    // Two table ids cannot be compared: `t2 == t3` is compile error CE10123 (measured 2026-11-14).
    indicator("spec 39 limitations drawings", overlay = true, max_labels_count = 60, max_lines_count = 50)
    
    var table t = table.new(position.top_right, 2, 16, border_width = 1)
    show(int i, string k, string v) =>
        table.cell(t, 0, i, k, text_color = color.black, bgcolor = color.silver)
        table.cell(t, 1, i, v, text_color = color.black, bgcolor = color.white)
    tf(bool b) => b ? "T" : "F"
    
    if barstate.islast
        for i = 0 to 79
            label.new(bar_index - i, high, str.tostring(i), style = label.style_none)
        for i = 0 to 69
            line.new(bar_index - i, low, bar_index - i, high, color = color.new(color.gray, 90))
        table t2 = table.new(position.bottom_left, 1, 1)
        table t3 = table.new(position.bottom_left, 1, 1)
        table t4 = table.new(position.bottom_right, 1, 1)
        label oldest = label.all.get(0)
        line oldestLine = line.all.get(0)
        show(0, "labels after 80 label.new (max 60)", str.tostring(label.all.size()))
        show(1, "oldest surviving label text", label.get_text(oldest))
        show(2, "lines after 70 line.new (max 50)", str.tostring(line.all.size()))
        show(3, "oldest surviving line x1 rel. bar_index", str.tostring(line.get_x1(oldestLine) - bar_index))
        show(4, "tables: 1 top_right + 2 bottom_left + 1 bottom_right", str.tostring(table.all.size()))
    
  29. Drawing count caps — compiles; values measured

    //@version=6
    // How many drawings survive past the declared maximum: labels with max_labels_count = 10, lines with
    // max_lines_count = 500, boxes with the default (about 50); all created in one loop on the last bar.
    indicator("spec 39 limitations drawings caps", overlay = true, max_labels_count = 10, max_lines_count = 500)
    
    var table t = table.new(position.top_right, 2, 16, border_width = 1)
    show(int i, string k, string v) =>
        table.cell(t, 0, i, k, text_color = color.black, bgcolor = color.silver)
        table.cell(t, 1, i, v, text_color = color.black, bgcolor = color.white)
    
    if barstate.islast
        for i = 0 to 29
            label.new(bar_index - i, high, str.tostring(i), style = label.style_none)
        for i = 0 to 519
            line.new(bar_index - i, low, bar_index - i, high, color = color.new(color.gray, 95))
        for i = 0 to 79
            box.new(bar_index - i, high, bar_index - i, low, border_color = color.new(color.gray, 95))
        show(0, "labels after 30 label.new (max 10)", str.tostring(label.all.size()))
        show(1, "lines after 520 line.new (max 500)", str.tostring(line.all.size()))
        show(2, "boxes after 80 box.new (default max)", str.tostring(box.all.size()))
    
  30. Drawing count caps for boxes — compiles; values measured

    //@version=6
    // The surviving count past a declared maximum for boxes and polylines (labels and lines keep max + 2).
    indicator("spec 39 limitations drawings caps boxes", overlay = true, max_boxes_count = 10, max_polylines_count = 10)
    
    var table t = table.new(position.top_right, 2, 16, border_width = 1)
    show(int i, string k, string v) =>
        table.cell(t, 0, i, k, text_color = color.black, bgcolor = color.silver)
        table.cell(t, 1, i, v, text_color = color.black, bgcolor = color.white)
    
    if barstate.islast
        for i = 0 to 29
            box.new(bar_index - i, high, bar_index - i, low, border_color = color.new(color.gray, 95))
        for i = 0 to 29
            polyline.new(array.from(chart.point.from_index(bar_index - i, low), chart.point.from_index(bar_index - i, high)), line_color = color.new(color.gray, 95))
        show(0, "boxes after 30 box.new (max 10)", str.tostring(box.all.size()))
        show(1, "polylines after 30 polyline.new (max 10)", str.tostring(polyline.all.size()))
    

Activity

  1. tripolskypetr commented on Nov 15, 2026

    @tripolskypetr
    Author

    Perhaps this is the last time I can reproduce anything cause I am banned

    image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions