Pine2Py · Examples
Conversion examples
Example conversion · Published November 11, 2026
Every example on this page is a real conversion: the Pine source and the Python output are verbatim from the Pine2Py converter, with semantic notes on what translates cleanly and what quietly changes meaning. In our testing, 1,909 real scripts convert at a 99.7% compile rate and 98.4% fully translated — the examples below are twelve of them, chosen because each one teaches a specific lesson.
Strategies
- EMA crossover strategy — the classic dual-EMA (9/21) crossover, converted with zero diagnostics. Teaches: the decorator, hoisted inputs,
round()on integer arguments, and why the fill timing lives in the emulator, not in the code. - RSI mean-reversion strategy — RSI bounce with an ATR bracket and a
varbar counter, converted with zero diagnostics. Teaches:Persistentcounters — and the correction that the exit bracket is in ticks, not points, with the full measured consequence. - MACD crossover strategy — MACD line crossing its signal line (12/26/9), converted with zero diagnostics. Teaches: tuple destructuring —
ta.macdreturns three series, and the converter computes it once and unpacks by index — plus the honest run: 154 trades, PF 1.12, in our testing. - Bollinger Bands mean-reversion strategy — buy the cross under the lower band (20, 2.0), exit on the cross back over the basis, converted with zero diagnostics. Teaches: the same
ta.bbtuple unpacking with the order that matters (basis, upper, lower) — plus the honest run: 68 trades, a 63% win rate that still loses money, in our testing. - Clockwork entries — the same RSI strategy with its entry rule replaced by a clock (
bar_index % 83 == 0), converted with zero diagnostics. Teaches:bar_indexsurvives translation untouched — and the placebo control itself, which still made $706.11, in our testing, plus one tick the runtime silently dropped over $26.73. - Order fill policy — the same RSI strategy under three fill policies (drop / fill at the close / size on the fill price), each with the fee on and off, converted with zero diagnostics. Teaches: the policy is a one-line change with a $2,001.53 headline, the fee costs 4.4× what it charges under the drop policy, and the shrink never fired once, in our testing.
- Trailing stop distance — the same RSI strategy with the trailing exit at 1×, 2× and 3× ATR, converted with zero diagnostics. Teaches: the trail multiplier is a one-line change with a $6,820 headline — and the second silent drop in the series, $43.03 short, in our testing.
- Commission & fees — the same RSI strategy with a 0.1% round-trip fee (
commission_type=strategy.commission.percent, commission_value=0.05), converted with zero diagnostics. Teaches:commission_valuepasses through verbatim and charges per fill — and the measured cost of the mechanism, where the fee itself took $359.12 but the strategy lost $1,592.79, in our testing. - RSI trailing stop — the RSI mean-reversion strategy with its 10-bar clock exit replaced by a
var-tracked trailing stop (highest close − 2×ATR), converted with zero diagnostics. Teaches:Persistentprice levels — and the measured cost of the mechanism, a median 156.60 points of give-back per trail exit, in our testing. - request.security weekly filter — a daily EMA 10/30 crossover with a weekly close-above-SMA filter, converted with zero diagnostics. Teaches: the developing weekly value is not last week's close — one line moves the backtest by $1,480.28, in our testing — and the SMA line we honestly could not verify.
- SuperTrend trend-following strategy — two ratchet lines 3 × ATR(10) off the bar midpoint, trend flips on a close through the opposite line, converted with zero diagnostics. Teaches:
varstate that survives bar to bar —PersistentvsPersistentSeries— plus the honest run: 56 trades, net +$8,578.61, PF 1.491, but a 45% max drawdown, in our testing.
Drawing objects
- Pivot lines — a horizontal line at every pivot high, no
plot()at all, converted with zero diagnostics. Teaches: the 50-object cap is semantics, not data loss — 238 lines created, 50 live — and why the run CSV is 0 bytes while the drawing journal holds everything.
Diagnostics
- input.enum has no known Pyne parameter type — one real diagnostic, reproduced verbatim, with the verified fix:
input.stringwith the same options, zero diagnostics, run confirmed on 4,089 bars.
Coming next
More conversion examples are being added in small batches, and the diagnostics explainers have started — one real error message at a time, with the fix that resolves it. Next are ta.* function reference pages. Each page carries the same rule as the rest: real converter output, real numbers, and a note wherever the translation changes meaning.
To convert your own script, use the converter on the home page. Every account gets 3 free conversions; Pro is $12/month via Paddle.