PineScript backtests offline चलाएँ, अपने data पर
PineForge PineScript v6 को native C++ में transpile करता है और Docker के via आपकी local machine पर चलाता है। Local-first, byte-reproducible, हर जगह जहाँ Docker चलता है वहाँ चलता है। अपना OHLCV CSV लाइए।
Offline क्यों?
Browser-based backtesting chart-side iteration के लिए बढ़िया है। Offline backtesting वो है जो तब चाहिए जब अगला step strategy के पीछे पैसा लगाना हो: जब audit trail चाहिए, जब CI को हर commit gate करना हो, जब दो महीने पुराने result को आज bit-for-bit reproduce करना हो।
Offline backtests चलाने से वो चीज़ें मिलती हैं जो browser-based testers नहीं दे सकते: results होते हैं byte-reproducible — same input, same output, हर बार। आप engine version pin करते हैं, results repository में check-in करते हैं, commits के बीच trade lists diff करते हैं, और पूरी चीज़ अपनी CI pipeline में headlessly चलाते हैं। जो CSV आप feed करते हैं वो आपका है; जो binary चलता है वो local है; जो report वापस मिलती है वो auditable है।
Practical list क्या unlock होता है: version-pinned engines ताकि दो महीने पुराना commit आज वही trade list produce करे; custom data ingestion ताकि अपने exchange के tick reconstructions, अपने data vendor के point-in-time equity prices, या किसी भी alt-data feed पर test हो जिसे OHLCV में serialize किया जा सके; CI integration ताकि regressions production तक पहुँचने से पहले build fail कर दें; और multi-broker portability क्योंकि strategy की logic platform से locked नहीं — वो एक file है।
अगर कभी आपको colleague के साथ backtest result share करना पड़ा हो और एहसास हुआ हो कि उसे ‘share’ करने का इकलौता तरीक़ा chart का screenshot है — वही चीज़ offline running आपको देती है।
कैसे काम करता है
तीन steps। Pine source से JSON trade report तक का full workflow पहली बार दो minutes से कम लगता है और हर बाद के run में तीस seconds से कम।
Step 1 — Free codegen API key लें। नीचे early-access form पर sign up करें। Key तुरंत email हो जाती है और उसकी free tier generous है — किसी भी individual quant के development workflow के लिए काफ़ी।
Step 2 — Codegen API पर अपनी Pine source POST करें। API PineScript v6 को C++ में transpile करती है और एक compiled shared object return करती है। Runtime पर कोई Pine interpreter नहीं चलता — output native machine code है।
curl -s https://api.pineforge.io/v1/codegen \
-H "Authorization: Bearer $PINEFORGE_API_KEY" \
-H "Content-Type: application/json" \
-d '{"source": "'"$(cat my_strategy.pine | jq -Rs .)"'"}' \
| jq -r '.artifact_url' \
| xargs curl -sL -o strategy.soStep 3 — docker run. PineForge runtime image pull करें और अपनी OHLCV CSV को compiled artifact के साथ mount करें। Engine data file पढ़ता है, strategy को bar-by-bar execute करता है, और stdout पर JSON report लिखता है।
docker run --rm \ -v "$(pwd)/strategy.so":/strategy.so \ -v "$(pwd)/ohlcv.csv":/data.csv \ ghcr.io/pineforge/runtime:latest \ run /strategy.so --data /data.csv --output json
JSON output में entry/exit prices, bar indices, position sizes के साथ full trade list, और net PnL, max drawdown, total trades, profit factor, Sharpe ratio का summary block होता है। Same major version के patch releases पर सारे fields stable हैं — scripts में parse करना safe है।
बस यही पूरा workflow है। न GUI, न account re-authentication, न chart loading। अगर Docker चला सकते हैं, तो PineForge offline backtests चला सकते हैं।
क्या-क्या backtest कर सकते हैं
छोटा जवाब: कुछ भी जिसे OHLCV में serialize कर सकते हैं। PineForge किसी market data provider से connected नहीं। आप data लाते हैं; engine strategy चलाता है।
अपने exchange से crypto. Binance, Bybit, Kraken, या किसी भी REST/WebSocket API वाले exchange से raw trade data pull करें। जो भी timeframe आपकी strategy use करती है उस पर aggregate करें। CSV directly feed करें। ठीक उसी pair-and-venue पर test करें जिस पर trade करेंगे।
अपने data vendor से equities. Polygon, Norgate, BarChart, Tiingo — अपना source चुनिए, point-in-time adjusted prices export कीजिए, अपने actual fills और survivorship-bias-free universe पर backtest चलाइए।
Tick reconstructions. अगर Level 2 data है और ticks से reconstruct किए synthetic 1-second bars पर test करना चाहते हैं, तो कर सकते हैं। Tick data से OHLCV generate कीजिए और pass कर दीजिए। Engine को नहीं पता और न परवाह कि bars कहाँ से आए।
Alt-data. Sentiment scores, on-chain metrics, funding rates, options skew — अगर इसे bar index से aligned time series की तरह express कर सकते हैं, तो Pine में custom data columns के via incorporate कर सकते हैं और offline test कर सकते हैं।
Gallery में 167-strategy reference suite को TradingView CSV exports (parity validation के लिए) और custom CSV datasets (regression testing के लिए) पर backtest किया गया। 167 में से 165 canonical strict-excellent tier पर hit करती हैं (PnL drift ≤ 0.5% comparison window पर); बाक़ी दो strong tier पर full trade-by-trade matches हैं (drift 0.5% और 1% के बीच, production sizing के लिए reproducibility tolerance के अंदर)। एक additional probe — 1× equity-margin stress test — headline sweep से बाहर है; वो TV-side broker emulator non-determinism expose करता है जिसे हम public Pine state से model नहीं कर सकते।