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 (1)

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