Skip to content

size.*, position.*, line.style_*, shape.* and order.* used as values: C++ that does not build, a one-character "\0" string, an input that cannot be set, or a crash #389

Closed

Description

@letiep97

Summary

The engine's coverage table (docs/pine_v6_coverage_detail.md) lists size.*, position.*, line.style_* and label.style_* as parse-and-skip, and they work as direct arguments (label.new(..., size = size.small)). In Pine v6 they are const string constants, and scripts also keep them in variables, return them from functions, list them as input options and pass them to user functions. In those positions Codegen 1.12.0 emits the constant as the integer 0 (shape.* and order.* come out as strings, but the variable or parameter that holds them is typed as a number), with these results:

# Form Result
1 string sz = size.small then sz := size.large C++: use of overloaded operator '=' is ambiguous (with operand types 'std::string' and 'int') on sz = 0;
2 string sz = close > open ? size.large : size.small builds; sz holds the one-character string "\0": str.length(sz) traces 1 on every bar, 5 with the literals "large" / "small"
3 a function whose switch returns line.style_dashed / line.style_solid builds; the function is declared double styleOf(std::string s) and returns 0; str.length() of the result traces 1, 3 with the string literals "dsh" / "sol" in the arms
4 input.string(size.small, "Text size", options = [size.tiny, size.small, size.normal]) builds; the metadata is {"type": "string", "default": "", "options": [], "supported": false} and every value set for the input is refused: input cannot be honoured by this compiled strategy
5 switch arms shape.circle / shape.cross assigned to an untyped variable warning PF-W1078 on each constant, then C++: assigning to 'double' from incompatible type 'std::string' (double shp = 0.0;)
6 order.descending as a parameter default, compared with order.ascending C++: the parameter is declared int sortOrder and the body compares it with std::string("ascending"): invalid operands to binary expression ('int' and 'std::string')
7 size.small passed to a user function's string parameter: note(size.small) builds as note(0); the std::string parameter is constructed from a null pointer and the process stops with SIGSEGV (exit 139) on the bar of the call

position.top_right / position.bottom_left in a variable fail as case 1. txtSize == size.tiny after case 4's input fails with use of overloaded operator '==' is ambiguous. Case 4 has the effect of #372 case 4 (an input whose defval is not a literal), here with a built-in constant as the defval; its "supported": false is the marking #179 introduced for a string input whose default or options are these constants.

In 1.12.0, pineforge_codegen/codegen/visit_expr.py lowers a member of DRAWING_STYLE_NS (line, box, label) or of SKIP_NAMESPACES (size, position) to "0", and docs/codegen-coverage-gaps.md lists the SKIP_NAMESPACES lowering to "0" as a placeholder defect. The seven forms are where that constant is used as a value.

Versions

pineforge-codegen 1.12.0 with pineforge-engine v1.12.0 (6e27d0f2). Apple clang 17.0.0, macOS 15.8 arm64. BTCUSDT 1h bars from 2024-01-01 to 2024-03-01 (1,441 bars), initial capital 10000, no commission or slippage.

TradingView: BINANCE:BTCUSDT, 1h, Deep Backtesting over the same dates, measured on 2026-11-14: the seven scripts and their controls save without error and give the same 26 trades (the last one still open at the end of the range), net profit 29.93, as the controls on PineForge. str.length(sz) in case 2 is 5 and str.length(st) in case 3 is 3 on each of the 1,360 bars up to the last entry, in the script and in its control; in case 4 the input lists tiny, small and normal and the script runs with each. The values were read through the order comment of each entry, as the minimum and maximum over the bars so far. On TradingView size.tiny / small / normal / large are the strings "tiny", "small", "normal", "large", line.style_solid / line.style_dashed are "sol" / "dsh", shape.circle / shape.cross are "shape_circle" / "shape_cross" and position.top_right is "top_right"; order.ascending and order.descending are of the type const sort_order and can be compared with == but not used as strings.

Reproduction

Each control replaces the constants with the string literals of their values ("small", "dsh", "shape_circle"; in case 6, the order parameter with a bool) and changes nothing else; every control builds and runs with 26 trades and net profit 29.93.

1. In a variable

//@version=6
strategy("size constant in a variable", overlay = true, initial_capital = 10000)
fast = ta.ema(close, 10)
slow = ta.ema(close, 30)
string sz = size.small
if close > open
    sz := size.large
label.new(bar_index, high, "x", size = sz)
if ta.crossover(fast, slow)
    strategy.entry("Long", strategy.long, qty = 0.01)
if ta.crossunder(fast, slow)
    strategy.close("Long")
error: use of overloaded operator '=' is ambiguous (with operand types 'std::string' and 'int')
    sz = 0;

Control: string sz = "small" and sz := "large".

2. From a ternary

//@version=6
strategy("size constant from a ternary", overlay = true, initial_capital = 10000)
fast = ta.ema(close, 10)
slow = ta.ema(close, 30)
string sz = close > open ? size.large : size.small
label.new(bar_index, high, "x", size = sz)
// @pf-trace len=str.length(sz)
if ta.crossover(fast, slow)
    strategy.entry("Long", strategy.long, qty = 0.01)
if ta.crossunder(fast, slow)
    strategy.close("Long")

It builds and runs; len traces 1 on every bar. Control: close > open ? "large" : "small"; len traces 5 on every bar.

3. Returned from a function

//@version=6
strategy("line style returned by a function", overlay = true, initial_capital = 10000)
fast = ta.ema(close, 10)
slow = ta.ema(close, 30)
styleOf(string s) =>
    switch s
        "Dashed" => line.style_dashed
        => line.style_solid
string st = styleOf("Dashed")
line.new(bar_index, high, bar_index + 1, high, style = st)
// @pf-trace len=str.length(st)
if ta.crossover(fast, slow)
    strategy.entry("Long", strategy.long, qty = 0.01)
if ta.crossunder(fast, slow)
    strategy.close("Long")

It builds and runs; len traces 1 on every bar. Control: the arms return "dsh" and "sol"; len traces 3 on every bar.

4. As input options

//@version=6
strategy("size constants as input options", overlay = true, initial_capital = 10000)
fast = ta.ema(close, 10)
slow = ta.ema(close, 30)
txtSize = input.string(size.small, "Text size", options = [size.tiny, size.small, size.normal])
label.new(bar_index, high, "x", size = txtSize)
if ta.crossover(fast, slow)
    strategy.entry("Long", strategy.long, qty = 0.01)
if ta.crossunder(fast, slow)
    strategy.close("Long")

It builds. Setting Text size to "small", or to "tiny", is refused by the engine:

input cannot be honoured by this compiled strategy

The generated C++ reads txtSize = get_input_string("Text size", std::string(""));. Control: input.string("small", "Text size", options = ["tiny", "small", "normal"]).

5. shape.* from a switch

//@version=6
strategy("shape constant from a switch", overlay = true, initial_capital = 10000)
fast = ta.ema(close, 10)
slow = ta.ema(close, 30)
shapeIn = input.string("Circle", "Shape", options = ["Circle", "Cross"])
shp = switch shapeIn
    "Circle" => shape.circle
    "Cross" => shape.cross
plotshape(ta.crossover(fast, slow), style = shp)
if ta.crossover(fast, slow)
    strategy.entry("Long", strategy.long, qty = 0.01)
if ta.crossunder(fast, slow)
    strategy.close("Long")

Codegen translates it with warning PF-W1078 on shape.circle and on shape.cross (a style constant "is only accepted as an argument to visual calls"); here the variable is used only as the style of plotshape(). The C++ then fails:

error: assigning to 'double' from incompatible type 'std::string'

on shp = std::string("circle");, with the member declared double shp = 0.0;. Control: the arms return "shape_circle" and "shape_cross".

6. order.* as a default argument

//@version=6
strategy("order constant as a default argument", overlay = true, initial_capital = 10000)
fast = ta.ema(close, 10)
slow = ta.ema(close, 30)
pick(array<float> a, sortOrder = order.descending) =>
    sortOrder == order.ascending ? a.min() : a.max()
var arr = array.new<float>()
arr.push(close)
if arr.size() > 5
    arr.shift()
plot(pick(arr))
if ta.crossover(fast, slow)
    strategy.entry("Long", strategy.long, qty = 0.01)
if ta.crossunder(fast, slow)
    strategy.close("Long")

The function is generated as double pick(std::vector<double>& a, int sortOrder) with sortOrder == std::string("ascending") in its body:

error: invalid operands to binary expression ('int' and 'std::string')

Control: pick(array<float> a, bool ascending = false) with ascending ? a.min() : a.max().

7. Passed to a string parameter

//@version=6
strategy("size constant passed to a string parameter", overlay = true, initial_capital = 10000)
fast = ta.ema(close, 10)
slow = ta.ema(close, 30)
note(string sz) =>
    label.new(bar_index, high, "x", size = sz)
if barstate.islast
    note(size.small)
if ta.crossover(fast, slow)
    strategy.entry("Long", strategy.long, qty = 0.01)
if ta.crossunder(fast, slow)
    strategy.close("Long")

The run ends with SIGSEGV; the control (note("small")) runs with 26 trades. With a debug build the fault is in strlen under the std::string constructor called for note(0).

Expected

The constants keep their values wherever they are used, as with the string literals of those values: cases 1, 5 and 6 build, cases 2 and 3 give the constants' text, case 4 is a supported input whose options can be set, and case 7 runs. Each script then gives its control's 26 trades.

Workaround

Use the constants only as direct arguments of the drawing calls, and write the string literal of the constant's value ("small", "dsh", "shape_circle") where a value is stored, returned, compared or listed as an input option.

Activity

  1. luisleo526 commented on Nov 14, 2026

    @luisleo526
    Contributor

    Thank you for the detailed report and the controls; they make each case easy to reproduce.

    We will reproduce each form in your table (size.*, position.*, line.style_*, shape.* and order.* used as values) on Codegen 1.12.0 and on current main, find where the translation goes wrong, and post the findings here by 2026-11-15, with a fix target. We look first at the forms that produce a wrong value (the one-character string and the input that cannot be set), then at the build failures.

    🤖 Generated with Claude Code

  2. luisleo526 commented on Nov 15, 2026

    @luisleo526
    Contributor

    Findings 2026-11-15 (UTC+8), as promised.

    • Your forms reproduce on Codegen 1.12.0 and on current main: depending on the form, the C++ does not build, a value becomes a one-character "\0" string, an input cannot be set, or the translation crashes.
    • Cause: the translator handles size.*, position.*, line.style_*, shape.* and order.* only as arguments of the calls that take them, not as values in their own right (in variables, inputs, ternaries and comparisons).
    • Fix: each constant is translated to the value TradingView itself uses (we measured these on TradingView; for example label.style_label_up is "lup"), and a form TradingView refuses is refused with a clear error instead of producing broken C++. One example: TradingView refuses input.string(defval = order.ascending, options = [order.ascending, order.descending]) at compile time ("const sort_order" where it expects a const string), so the translator will refuse it too.

    Fix target: we cannot give one honestly yet. The fix is written, but a few cases still need TradingView values that our comparison tooling cannot record yet (all plots of a bar and the input settings), and the fix is not in today's batch. We will post the date here as soon as that check has run, and the merge commit when it lands.

  3. luisleo526 commented on Nov 15, 2026

    @luisleo526
    Contributor

    Fixed on main in f848df5 (#411). Built-in size.*, position.*, line.style_*, label.style_* and shape.* constants now keep their string values in variables, selections, function arguments and returns, and in string input defaults and options. That removes the ambiguous C++ assignments, the one-character NUL strings, the unsupported size inputs and the null-pointer string construction in your report. order.ascending and order.descending keep their sort-order type: using one as a string input default or option is refused at its Pine location (PF-E2093), as TradingView refuses it. All seven forms from the report fail on the previous main and pass now. If a constant still comes out wrong on the current main, please post the script here.

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