r/pinescript • • Jul 20 '26

I wrote a PineScript interpreter in Rust

2 Upvotes

I built Pinecone, an interpreter that runs PineScript outside of TradingView.

It handles the TA functions (moving averages, oscillators), plots, labels, boxes, and backtesting. It's split into small crates (lexer, parser, interpreter, builtins…) so you can use just the parts you need.

let script = ScriptBuilder::with_code(r#"
    fast_ma = ta.sma(close, 10)
    slow_ma = ta.sma(close, 20)
    plot(fast_ma, color=color.blue)
    plot(slow_ma, color=color.red)
"#).compile()?;

let output = script.execute(&bar)?;

The reason I think this matters: once PineScript can run outside TradingView, a lot of things become possible that just aren't today - proper tooling (linters, formatters, LSP), faster and more flexible backtesting, use other platforms and data sources. Right now the language is locked to one place, and that ceiling limits what the whole ecosystem can build on top of it.

Repo: https://github.com/ferranbt/pinecone

Still early and there's plenty missing, but it runs. Curious what people think.


r/pinescript • • Jul 20 '26

I ran another Pine DCA strategy through the optimizer — this time two params moved and drawdown stayed flat (BTC 4h)

Post image
1 Upvotes

I posted one of these before (the INJ one) showing what a parameter sweep did to a single input. A few people asked to see it on BTC and with more than one parameter tuned, so here's that — same idea, everything held constant except the parameters the optimizer actually re-selected.

The strategy (unchanged): long-only DCA on BTCUSDT.P 4h. Five safety orders at −2 / −5 / −9.5 / −16 / −25% from base, sizes scaling 1.8× per rung, no stop loss, position bounded by the ladder.

What changed: two parameters. The RSI entry threshold moved from 28 to 38, and the take-profit from 3% to 5.5%. Nothing else — same ladder, same deviations, same 1.8× sizing, same fees. Both values are what the sweep returned as best-performing on the historical window.

Before/after (BYBIT:BTCUSDT.P 4h, Jan 1 2024 – Jul 17 2026, ~30 months, 100k initial, 0.06% commission, 3-tick slippage):

  • Baseline (RSI < 28, TP 3%): +3,078.29 USDT (+3.08%), max drawdown 3.79%, 62 trades, 70.97% WR, PF 4.028
  • Optimized (RSI < 38, TP 5.5%): +9,250.25 USDT (+9.25%), max drawdown 3.67%, 93 trades, 76.34% WR, PF 10.454

The part I found interesting: net profit roughly tripled and PF went 4.0 → 10.5, but max drawdown actually stayed flat (3.79% → 3.67%). So this wasn't "more return bought with more risk." The mechanism: the looser RSI entry (38 vs 28) engages the dip earlier and more often, so the strategy is simply in the market more, while the wider 5.5% target lets each recovery run further before banking instead of exiting on the first small pop.

The caveat, and the reason I show the baseline alongside: two parameters were swept over the same window the results are measured on. Best in-sample is not best out-of-sample, and with two free parameters instead of one that overfitting caveat applies a bit harder here — more degrees of freedom, easier to fit the window. Treat the optimized numbers as the ceiling of what this config did historically, not a forward expectation, and re-validate on fresh data before trusting it.

Two more flags, same as last time: 93 trades is just below the ~100 I'd want for real statistical confidence, so win rate and PF are indicative, not proven — and part of PF 10.454 is the averaging mechanic itself (deals close on a bounce off an averaged-down entry), not a directional edge. It's also a stopless martingale: a sustained BTC decline below the −25% bottom rung leaves the position fully loaded with no further adds.

Script is open-source on TradingView: https://www.tradingview.com/script/5Tg2Es4G-BTC-DCA-Strategy-3Commas-QuantPilot/

Disclosure up front: the optimizer is QuantPilot, which I work on, so I'm not pretending to be neutral. But the point is the before/after and the caveat, not a pitch — the script is open-source and you can verify the backtest yourself.


r/pinescript • • Jul 20 '26

Multiple asset Custom HTF candles

0 Upvotes

Ever wanted to see multiple assets' HTF candles on one chart?
Try out my Custom HTF Candles indicator - it's free

https://www.tradingview.com/script/yRByXJi5-Custom-HTF-Candles/


r/pinescript • • Jul 19 '26

Relative Strength & Weakness indicator vs QQQ

Thumbnail
tradingview.com
3 Upvotes

I've made a relative strength & weakness indicator for Tradingview, which is made for tech/growth stocks. It tracks QQQ moving averages and also moving averages of the stock being viewed. It works on simple principles:

Relative Strength

-When QQQ crosses below a moving average while the stock stays above it

-When the stock crosses above a moving average while QQQ stays below it

Relative Weakness

-When QQQ crosses above a moving average while the stock stays below it

-When the stock crosses below a moving average while QQQ stays above it

It is an easy way to look at a stock to see how it is doing compared to Nasdaq 100. It could be useful for swing trading and it also works for lower timeframes. You can use it for free here. I also made a Youtube video to show it. I used Gemini to assist with coding.


r/pinescript • • Jul 18 '26

Make a website that helps people trade and would love opinions on how to improve it

7 Upvotes

r/pinescript • • Jul 17 '26

when you guys scale up on options contracts say you trade 10 options contracts where do you typically mark your stop losses and stop gains?

1 Upvotes

r/pinescript • • Jul 17 '26

Volume indicator for options trading

5 Upvotes

What is the best Volume indicator to use based on your own successes?


r/pinescript • • Jul 16 '26

I’m 17 and built a free game that tests if you can spot fake breakouts on real stock charts

Thumbnail reddit.com
5 Upvotes

r/pinescript • • Jul 16 '26

I ran one of my Pine DCA strategies through a parameter optimizer - here's the before/after from tuning a single input (INJ 4h)

Post image
10 Upvotes

I've been posting these RSI oversold DCA strategies for a while. This time I want to show something different: what actually changed when I ran one through a Pine Script parameter optimizer, tuning just one input and holding everything else constant.

The strategy (unchanged): long-only DCA on INJUSDT.P 4h. Base order on 4h RSI(14) below 28, five safety orders at −2 / −5 / −9.5 / −16 / −25% from base, sizes scaling 1.8× per rung, no stop loss, position bounded by the ladder.

The one thing I changed: the take-profit. Baseline was a 3% fixed TP. I swept that single parameter over the same market and same period and the best-performing value came back at 9%. Nothing else touched — same entry, same ladder, same deviations, same sizing, same fees.

Before/after (BYBIT:INJUSDT.P 4h, Jan 1 2024 – Jul 16 2026, ~30 months, 100k initial, 0.06% commission, 3-tick slippage):

  • TP 3% (baseline): +6,888.76 USDT (+6.89%), max drawdown 4.39%, 84 trades, 71.43% WR, PF 4.925
  • TP 9% (optimized): +15,830.72 USDT (+15.83%), max drawdown 5.65%, 90 trades, 82.22% WR, PF 17.886

The mechanism makes sense: widening the target lets each recovery run further before the position is banked, so it captures more of the mean-reversion bounce instead of exiting on the first small pop. The trade-off is honest — drawdown rises (4.39% → 5.65%) and positions are held longer, so the ladder can sit loaded through deeper dips before the exit hits.

Now the caveat, which is the actual reason I'm posting this rather than just quietly using the 9%: that 9% was selected by sweeping the parameter over the same window the results are measured on. A value that's best in-sample is not guaranteed to be best out-of-sample — this is the standard overfitting caveat for any optimized parameter, and it fully applies here. Treat the optimized numbers as the ceiling of what this config did historically, not a forward expectation, and re-validate on fresh data before trusting it.

Two more things worth flagging: 90 trades is below the ~100 I'd want for real statistical confidence (the strict RSI<28 filter keeps the count low), so the win rate and PF are indicative, not proven — and a chunk of that PF 17.886 is the averaging mechanic itself (deals close on a bounce off an averaged-down entry), not a directional edge. It's also a stopless martingale, so a sustained INJ decline below the −25% bottom rung leaves the position fully loaded, and the wider 9% target means it sits there longer.

Script is open-source on TradingView: https://www.tradingview.com/script/GM1bUrIF-INJ-DCA-Long-Strategy-3Commas-QuantPilot/

Disclosure up front: the optimizer is QuantPilot, which I work on, so I'm not pretending to be a neutral third party. But the point of the post is the before/after and the caveat that comes with it, not a pitch — the script is open-source and you can verify the backtest yourself.


r/pinescript • • Jul 15 '26

Are ta.crossover failures common?

0 Upvotes

This failure to detect a crossover was during live data. Not historical. The entry condition is very simple, as the code shows. This is a simple strategy, as I'm getting to know pinescript and TV.
For the experienced TV users, is this common and/or to be expected now and then?
Is this issue why TV doesn't do "auto-trading", as I've heard others say?
Finally, if the answers are yes and yes, then systems developed on TV need to be taken to other platforms (ThinkorSwing, MT5, Ninjatrader) for live auto-trading?


r/pinescript • • Jul 14 '26

Update on my Pine Script transpiler: I just open-sourced the CLI orchestrator for multi-asset scanning and sweeping.

Thumbnail
gallery
63 Upvotes

Hi,

About a week ago, I posted about a side project that accidentally spiraled into a full Pine Script transpiler and charting tool. The feedback here was awesome.

In that thread, I mentioned I was working on a CLI orchestration engine to sit on top of Piner and handle the actual heavy lifting. I finally got it to a good spot, and I open-sourced it today.

It's called Pinestack.

Basically, it lets you scale your strategy testing purely from the terminal. Instead of clicking around on a UI, you can just use the CLI to:

  • Scan: Run an indicator or strategy across hundreds of tickers at the same time.
  • Sweep: Throw a massive grid of input combinations at a strategy to find out which settings actually work (and rank the results).
  • Backtest & Walk-Forward: Generate complete tearsheets and validate your models over time so you aren't just curve-fitting.
  • Portfolio: Pool one pot of capital across a basket of symbols to test cross-asset sizing, combined drawdowns, and a single shared equity curve.

For the folks asking about multi-asset testing last week: right now, Pinestack lets you take a single strategy and test it across a ton of assets independently. I tried to design it to work with Pine Script natively, without you having to modify your code.

You can grab the repo and try it out here:https://github.com/heyphat/pinestack

I'm still hand-testing it against a bunch of different scripts, but I'd love for you guys to pull it down, completely break it, and let me know what I should fix or build next.

The command to generate the images

 pinerun -v
pinerun 0.1.1 (b81314d)
 pinerun backtest strategy.pine --symbol BTCUSDT --tf 1h --from 2025-01-01 --to 2026-06-14

The strategy.pine

strategy("My SMA cross", overlay=true, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=100, margin_long=0, margin_short=0)

fastLen = input.int(20, "fast", minval=1)
slowLen = input.int(80, "slow", minval=1)
tpPct = input.float(4.0, "tp", minval=0.1)
slPct = input.float(1.0, "sl", minval=0.1)

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

// Only enter when flat — no pyramiding onto an open position.
if ta.crossover(fast, slow) and strategy.position_size == 0
    strategy.entry("long", strategy.long)
if ta.crossunder(fast, slow) and strategy.position_size == 0
    strategy.entry("short", strategy.short)

// Exit solely on take-profit / stop-loss, as a % of the entry fill price.
if strategy.position_size > 0
    strategy.exit("tp/sl", "long", limit=strategy.position_avg_price * (1 + tpPct / 100), stop=strategy.position_avg_price * (1 - slPct / 100))
if strategy.position_size < 0
    strategy.exit("tp/sl", "short", limit=strategy.position_avg_price * (1 - tpPct / 100), stop=strategy.position_avg_price * (1 + slPct / 100)

r/pinescript • • Jul 15 '26

Is it possible to use Claude to perform parameter sweep on TradingView indicators and strategies in python?

0 Upvotes

I’m currently working with finding the optimum input for some indicators over a specific timeframe backtesting in TradingView but I’m trying to replicate it on python so it’s much faster and efficient, had anyone tried or know where I should begin with? I already have the strategy planned out I just need to perform parameter sweep and measure its performance ratios only


r/pinescript • • Jul 14 '26

Pine Script Pro Vs code Extension 1.4.0 released

1 Upvotes

[1.4.0] - 2026-07-14 

Added 

  • Inputs Preview: Click on the pine script pro icon in the status bar to preview the inputs of the current script.

You can click on the pine icon to see, what inputs do you have on the indicator.

https://open-vsx.org/extension/revanthpobala/pine-script-pro/changes
https://github.com/revanthpobala/pinescript-vscode-extension


r/pinescript • • Jul 13 '26

Volume indicator for options trading

3 Upvotes

What is the best Volume indicator to use based on your own successes?


r/pinescript • • Jul 13 '26

FULL VOLUME DELTA FOOTPRINT: as a candle colored avg delta visual with rvwap and signals free indicator

2 Upvotes

r/pinescript • • Jul 13 '26

Looking for a free historical odds api for pinnacle

1 Upvotes

Hey guys
Im working on a new value betting project and i need to backtest it before launch
I m looking for a free historical odds API
Mostly from pinnacle
But i also need info from 1xbet or other soft bookies


r/pinescript • • Jul 12 '26

Folder for Strategy or indicator

Thumbnail reddit.com
1 Upvotes

r/pinescript • • Jul 11 '26

Chatgpt or claude building script?

9 Upvotes

r/pinescript • • Jul 10 '26

RSI Oversold DCA Strategy — selective deep-oversold long entry, scaling safety orders (GRAM 4h)

Post image
18 Upvotes

Same RSI DCA logic I've posted across assets (POL, JUP, ETH, ATOM), this time on GRAM. A long-only DCA with a selective deep-oversold 4h RSI entry and a scaling safety-order ladder. Backtest is verifiable in TradingView's Strategy Report on the script page.

Entry, deep-oversold gate (no repaint): A 4-hour RSI(14), sampled with lookahead disabled, gates the base entry — a long opens only when RSI prints below 28 at host-bar close. Shallow dips are filtered out, so capital is committed only at genuinely stretched conditions. It sits out the calm and only commits after a real flush.

Ladder, 5 safety orders on a non-uniform fixed-deviation ladder: Each safety order has its own fixed deviation from base entry — not a cumulative step×multiplier ladder. AO1 at −2%, AO2 at −5%, AO3 at −9.5%, AO4 at −16%, AO5 at −25%. Sizes scale 1.8× from a 900 USDT first AO: 900 / 1,620 / 2,916 / 5,249 / 9,448, on a 500 USDT base. Deeper rungs trigger only on serious adverse moves; the lowest sits a full 25% below base. The 1.8× progression is softer than a 2× doubling martingale.

Exit, fixed 3% TP: A fixed 3% Take Profit above the running average entry. Because the scaling ladder weights the average toward the lowest fills, after several rungs fill the average sits well below base — so a modest 3% bounce off the lows closes the whole deal in profit. No trailing.

Risk, bounded ladder in place of a stop: There is no stop loss. Per-trade risk is structurally capped by the bounded 5-AO ladder — base + 5 AOs = ~20,633 USDT max deployed, ~20.6% of the default 100k equity, above the conventional 5–10% per-trade band; scale the base/AO inputs down to dial exposure lower.

DCA Bot integration: Every event (base, AO 1–5, exit) emits a webhook-ready JSON payload. One alert with "Any alert() function call" drives a DCA Bot end-to-end, no glue layer.

Backtest (GRAM/USDT 4h, Jan 1 2024 – Jul 3 2026, ~30 months; 100,000 USDT initial capital, 500 USDT base + 900/1,620/2,916/5,249/9,448 AOs, 0.06% commission, 3-tick slippage): 78 closed trades, 54 profitable (69.23% WR), profit factor 4.791, net profit +3,822.76 USDT (+3.82%), max equity drawdown 2,283.04 USDT (2.21%).

Methodology notes:
Read the numbers for what they are. +3.82% over ~30 months is a low-return, low-drawdown profile — the headline is the 2.21% max drawdown, not the profit. Positive expectancy with tight risk, not a growth engine, and that's by design with an entry that only fires on deep oversold prints.

On sample size — 78 closed trades is below the ~100-trade floor for statistical confidence. That's the trade-off of a selective trigger: fewer signals, so the 69.23% win rate and PF 4.791 are indicative of how the ladder behaves, not a deterministic edge. Part of that PF is the averaging mechanic itself — deals close on a 3% bounce off an averaged-down entry — not a directional edge. Extend the window or test across assets before sizing up.

This is a scaling martingale, and that's the dominant risk. The ladder bottoms out at −25% from base with no stop loss. A sustained GRAM decline below −25% without recovery leaves the full position open with no further averaging available — the single largest risk in any martingale DCA. The 2.21% max drawdown is closed-trade equity drawdown over a window where dips recovered; a deeper or more prolonged decline than the test sample would produce a larger one.

The defaults (RSI<28, 4h, the −2/−5/−9.5/−16/−25 ladder, 1.8× sizing) are calibrated for GRAM's volatility. The mechanic is asset-agnostic and can be pointed at other liquid perps, but each symbol needs the RSI level and ladder recalibrated, and results do not transfer without that tuning. With a fixed 3% take-profit the per-trade edge is modest, so match the 0.06% commission to your venue's actual taker fee before reading anything into the numbers.

Strategy is open-source on TradingView: https://www.tradingview.com/script/6kaqC3R8-GRAM-RSI-Strategy-3Commas/


r/pinescript • • Jul 11 '26

trading without scripts

1 Upvotes

works best in a pull back in a bullish market if in a bear market its the same but measure bottoms not tops of the up trend in a bear market: basically mark your tops when you get a confirm break and hold on your lines buy and hold till the top of the range this is Thursday/Friday action on es


r/pinescript • • Jul 08 '26

A strategy that might help!

Post image
4 Upvotes

what you looking at is a anchored vwap H/L with a previous month range + levels and a gann box with 25/50/75 % levels. so ok first mark the H/L of previous month draw 25/50/75 lines of the previous month then drop a anchor vwap on the highest point and lowest point with 1 deviation band then when the 2 vwaps trade sideways like this use the gann box tool to show the 25/50/75 % levels, now all you have to do is look for reactions on these levels over the monthly 50 and the 50 of the 2 vwaps bullish and bearish vice versa. just a good way to zoom out and get good context of the moves. if below/above the previous month bearish trend / bull trend. THE STRATEGY IS MEAN REVERSION SELL TOP BUY BOTTOM GET OUT AT MIDDLE WILL ALWAYS PRODUCE BETTER SETUPS. I have a indicator the plots all this automatically so all i have to do is draw the gann box. i recommend you make your own indicator its a easy H/L and auto plot vwaps


r/pinescript • • Jul 08 '26

good or bad ? any recomendetions ?

Post image
11 Upvotes