Skip to content

Known issue in PineForge Codegen 1.9.1: str.tostring of built-in boolean flags, and of variables holding them or a ta.* boolean result, returns "1" / "0" #315

Closed

Description

@luisleo526

In Pine Script, str.tostring of a boolean returns "true" or "false". In PineForge 1.9.1, some boolean values print as "1" or "0" instead. In every case we measured, the boolean values themselves are correct; only their text is wrong. Any string built from that text is affected, for example an order comment.

Measured as wrong in 1.9.1 (the list is a lower bound):

  • the built-in flags: str.tostring(session.isfirstbar), session.islastbar, session.isfirstbar_regular, session.islastbar_regular, barstate.islast, barstate.isfirst, barstate.isnew, barstate.isconfirmed, barstate.islastconfirmedhistory, barstate.isrealtime
  • a variable that holds one of these flags, for example fl = session.isfirstbar followed by str.tostring(fl)
  • a variable that holds a boolean ta.* result, for example ok = ta.crossover(close, ta.sma(close, 5)) followed by str.tostring(ok). The same happens with ta.crossunder, ta.cross, ta.rising and ta.falling, and with a variable assigned from a user function that returns such a result.
  • concatenation, for example "first=" + str.tostring(session.isfirstbar) returns first=0

Measured as correct in 1.9.1:

  • str.tostring(true), str.tostring(false), a var bool
  • a comparison, inline or stored (x = close > open), a logical expression, a boolean carried across bars (including x[1]), and a boolean assigned in an if
  • a user function returning a comparison, a boolean field of a user-defined type, an array<bool> element and a map<string, bool> value
  • fl = barstate.islast and close > open
  • ta.crossover, ta.crossunder, ta.rising and ta.falling used directly inside str.tostring, for example str.tostring(ta.crossover(close, ta.sma(close, 5)))
  • str.format with boolean arguments, for example str.format("{0} {1}", close > open, session.isfirstbar_regular) prints true / false for both arguments

Example, measured on NYSE:F 60-minute bars from 2024-01-02 to 2024-02-29: a script writes str.tostring(session.isfirstbar_regular) and str.tostring(session.islastbar_regular) into 97 exit comments. TradingView printed false / true. PineForge 1.9.1 printed 0 / 1, so the text matched in 0 of 97 comments while the values agreed in all 97.

Not yet checked: other boolean ta.* calls (for example the pivot functions), boolean members of syminfo.* and timeframe.*, request.* results, and these values stored in a user-defined type field or an array.

Workaround: none verified yet. A fix is in progress.

Addition 2026-11-03: further cases measured in 1.9.1.

Also wrong ("1" / "0"):

  • a function parameter that receives session.isfirstbar or a boolean ta.* result, passed to str.tostring inside the function (a parameter that receives barstate.isconfirmed printed correctly);
  • an array<bool> element created with array.from(...) from such a flag or ta.* result;
  • a variable holding a boolean request.security result.

Wrong in a different way: a variable holding timeframe.isintraday printed a non-printable character (byte 0x01) instead of true. Variables holding timeframe.isdaily, timeframe.isweekly, timeframe.ismonthly or timeframe.isseconds printed an empty string instead of false. These were measured on a 1-hour chart.

Measured as correct: a boolean field of a user-defined type and a map<string, bool> value assigned from a flag or a ta.* result; a stored not na(ta.pivothigh(...)); a stored ternary; a parameter that receives a comparison; and timeframe.isintraday used directly inside str.tostring.

Activity

  1. luisleo526 commented on Nov 3, 2026

    @luisleo526
    ContributorAuthor

    Fixed on main by #319 ("Print true or false when a bool becomes text, and let a bool input be read through a parameter"), merged 2026-11-03. The fix ships in PineForge Codegen 1.10.0, the next release (planned for tonight, Taipei time). Closing as fixed; please reopen if you still see it after upgrading.

  2. luisleo526 commented on Nov 3, 2026

    @luisleo526
    ContributorAuthor
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

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions