Your Pine comments now come through to Python

Until now, when PyneComp compiled a Pine script, the Python it gave back had none of the comments you wrote. PyneComp 6.1.3, released on November 16, 2026, keeps them. I have wanted this for a long time, and the new compiler I wrote about last week is what made it possible.

An example

Here is a small Pine indicator:

// Trend band: an EMA with an ATR envelope around it.
//@version=6
indicator("Trend band", overlay=true)

// Inputs
len  = input.int(20, "Length")         // EMA and ATR length
mult = input.float(2.0, "Multiplier")  // band width in ATRs

//@function The band around a center line.
//@param center The center line
//@param width The distance of each edge from the center
//@returns The upper and the lower edge
band(float center, float width) =>
    [center + width, center - width]

basis = ta.ema(close, len)
[upper, lower] = band(basis, ta.atr(len) * mult)

// A close above the upper edge starts an uptrend,
// a close below the lower edge ends it.
var bool up = false
if close > upper
    up := true
else if close < lower
    up := false

plot(basis, "Basis", up ? color.green : color.red)
plot(upper, "Upper", color.gray)
plot(lower, "Lower", color.gray)

And here is what PyneComp 6.1.3 compiles it to:

"""
@pyne edge

This code was compiled by PyneComp v6.1.3 — the Pine Script to Python compiler.
Run with open-source PyneCore: https://pynecore.org
Compile Pine Scripts online at PyneSys: https://pynesys.io
"""
# Trend band: an EMA with an ATR envelope around it.

from pynecore.lib import close, color, input, plot, script, ta
from pynecore.types import Persistent


@script.indicator("Trend band", overlay=True)
def main(
    # Inputs
    len=input.int(20, "Length"),  # EMA and ATR length
    mult=input.float(2.0, "Multiplier")  # band width in ATRs
):
    def band(center: float, width: float):
        """
        The band around a center line.

        :param center: The center line
        :param width: The distance of each edge from the center
        :return: The upper and the lower edge
        """
        return (center + width, center - width)

    basis = ta.ema(close, len)
    upper, lower = band(basis, ta.atr(len) * mult)

    # A close above the upper edge starts an uptrend,
    # a close below the lower edge ends it.
    up: Persistent[bool] = False
    if close > upper:
        up = True
    elif close < lower:
        up = False

    plot(basis, 'Basis', color.green if up else color.red)
    plot(upper, 'Upper', color.gray)
    plot(lower, 'Lower', color.gray)


if __name__ == "__main__":
    from pynecore.standalone import run
    run(__file__)

The docstring at the top is the one PyneComp has always written: @pyne marks the file as Pyne code for PyneCore. Your header comment comes right after it. Before 6.1.3 you got the same code without any of the # lines and without the docstring of band.

Where each comment goes

The compiler moves your code around: inputs become the parameters of main, a type becomes a class at the top of the module, a switch becomes an if chain. A comment goes with the code it belongs to.

  • A comment on its own line goes above the statement that follows it, at that statement’s indentation. An input’s comment ends up in the parameter list of main, a type’s above its class, an import’s above the import line.
  • A comment at the end of a line stays at the end of that line, 2 spaces after the code, as PEP 8 asks.
  • The comments at the top of your script, like a license or your name, go to the top of the Python file. The //@version line is the only comment that is dropped.
  • //@function, //@param and //@returns, and //@type, //@enum and //@field for types and enums, become the docstring of the function or class. Your editor shows it when you hover over a call, so if you publish a library, its users can read your documentation in Python too.
  • //#region and //#endregion become # region and # endregion, which PyCharm can fold.

Cleaner spacing

The empty lines changed too. With the old compiler you could find 2 empty lines in a row inside a function, and none before a function defined inside main. The output now follows PEP 8, the Python style guide: at most 1 empty line inside a function, 1 around each function inside main, and 2 around every function and class at the top level. On the 1,090 real-world scripts I tested, the old output broke these rules 449 times. The new output breaks them nowhere.

The program stays the same

Comments and docstrings don’t change what the code does. I compiled the same 1,090 scripts with the old and the new version and compared the Python they produced, statement by statement: apart from the new docstrings, it is identical in every script. All 52,255 comments of these scripts are in the output. I also ran 2 of them on the same data with both versions, and the results matched to the last digit.

Why it took a new compiler

The old compiler’s parser was built to run Pine, and a program that runs code has no use for comments, so they were gone before the compiler saw the script. The new compiler reads your script as you wrote it, comments included, and knows which statement each comment belongs to. When it moves a statement, the comment moves with it.

This website uses cookies and similar technologies. By continuing to use the site, you accept this. Details in our Privacy Policy.