DEV Community

Cover image for 🌳 Pine Script into readable Python for Free
Petr Tripolsky
Petr Tripolsky

Posted on Edited on

🌳 Pine Script into readable Python for Free

Download the converted 449 strategies and 471 indicators via this link


pine2pyne

I built a free compiler and translated over 1000 popular trading strategies and indicators from TradingView into Python source code!

No need to open TradingView or use a browser; you can run indicators and batch-test trading strategies right on your local machine!

  • 449 trading strategies: Includes TradingView community strategies that can be called directly from Python for testing.
  • 471 technical indicators: Includes publicly available indicators such as SuperTrend and MACD, supporting standalone execution.
  • High-precision conversion: 384 strategies and 458 indicators are bit-for-bit consistent, and the rest are verified with tolerance checks.
  • Multi-exchange data: access candlestick charts from exchanges such as Binance, Bybit and Gate via CCXT.
  • Batch testing: CSV output including trade records, win rate, drawdowns and profit/loss ratios for convenient secondary analysis.
  • AI agent integration: supports integration with tools such as Codex and Claude Code for researching, modifying and testing strategies.

Where the tool's value lies

Its most valuable feature is the mass conversion of publicly available strategies from the TradingView community into programmable research material in Python. For example, to study BTC strategies, you can run various scripts in batches, compare backtest results, and then filter out the trading logic that deserves deeper verification.

Updated EULA

Unfortunately, the updated PyneComp usage agreement does not permit mass conversion of Pine Script, even within a subscription

Canceled Subscription

PyneSys will unilaterally block the subscription you paid for without explanation

Before / After

A classic SMA-crossover strategy, as written in Pine Script v5:

Before

//@version=5
strategy("SMA Crossover", overlay=true)

fastLen = input.int(9, "Fast SMA")
slowLen = input.int(21, "Slow SMA")

fast = ta.sma(close, fastLen)
slow = ta.sma(close, slowLen)

longCond  = ta.crossover(fast, slow)
shortCond = ta.crossunder(fast, slow)

if longCond
    strategy.entry("Long", strategy.long)
if shortCond
    strategy.entry("Short", strategy.short)

plot(fast, "Fast", color=color.green)
plot(slow, "Slow", color=color.red)
Enter fullscreen mode Exit fullscreen mode

Magic

pine2pyne sma_cross.pine -o sma_cross.py
Enter fullscreen mode Exit fullscreen mode

After

"""
@pyne edge

This code was compiled by pine2pyne 0.2.13 — the Pine Script to PyneCore Python transpiler.
Run with open-source PyneCore: https://pynecore.org
Source: https://github.com/pine2pyne
"""
from pynecore.lib import close, color, input, plot, script, strategy, ta


@script.strategy('SMA Crossover', overlay=True, margin_long=0, margin_short=0, initial_capital=1000000, default_qty_type=strategy.fixed, default_qty_value=1, close_by_id=True)
def main(
    fastLen=input.int(9, 'Fast SMA'),
    slowLen=input.int(21, 'Slow SMA')
):
    fast = ta.sma(close, fastLen)
    slow = ta.sma(close, slowLen)
    longCond = ta.crossover(fast, slow)
    shortCond = ta.crossunder(fast, slow)
    if longCond:
        strategy.entry('Long', strategy.long)
    if shortCond:
        strategy.entry('Short', strategy.short)
    plot(fast, 'Fast', color=color.green)
    plot(slow, 'Slow', color=color.red)


if __name__ == "__main__":
    from pynecore.standalone import run
    run(__file__)
Enter fullscreen mode Exit fullscreen mode

OpenSource

If you want to use PyneCore with AI agents for mass analysis of strategies for profitability in a fast-moving market, you have no choice: you will have to use pine2pyne.

Install

pip install pine2pyne
Enter fullscreen mode Exit fullscreen mode

Convert

pine2pyne strategy.pine -o strategy.py
Enter fullscreen mode Exit fullscreen mode

Thank you for your attention

Top comments (2)

Collapse
 
tripolskypetr profile image
Petr Tripolsky • • Edited

Important: it is exactly pine2pyne, not opencode-pine2pyne. The original opencode-pine2pyne has been abandoned by its author and is no longer developed

pypi.org/project/pine2pyne

Collapse
 
kamalmosadegh profile image
Kamal Mosadegh •

This is a genuinely useful bridge — most Pine-to-Python attempts I have seen produce Python that runs but no longer means the same thing, so "readable" matters as much as "converted."

The part I would stress to anyone using the 449 converted strategies is: do not trust a conversion on syntax alone. Pine has a lot of implicit behavior — series values, how strategy.entry / strategy.exit behave bar by bar, lookahead on security() calls, and what happens on the first bars before an indicator has enough data. A converter can translate every line faithfully and still change the strategy if it gets one of those semantics wrong.

What I do when I move a TradingView idea into my own bot code (my DipCatcher bot is TypeScript, but the principle is the same) is:

  1. Run the converted version and the original side by side on the same bars and diff the trade list, not just the final PnL. A matching PnL can hide offsetting errors.
  2. Check the edge bars first — the first trades, the first exit, and any bar where the stop and the limit could both fire. That is where conversion differences usually show up.
  3. Treat any "bit-for-bit consistent" result as a starting claim, not a guarantee — re-check it after any change to the data feed, because exchange data via CCXT will not always match TradingView's feed bar for bar.

The batch-testing angle is the real win here. Being able to run hundreds of strategies through the same CSV pipeline and compare win rate, drawdown, and profit/loss ratio on equal footing is far more valuable than any single conversion. Just make sure the diagnostics flag the constructs that could not be translated cleanly — a silent approximation in a stop or an exit is exactly the kind of thing that looks fine until it costs money.

Thanks for shipping this as open source, and for the clear note on the package name — that kind of naming confusion wastes more time than people admit.

— Kamal