PINE LIBRARY
Deeptest

Library "Deeptest"
Comprehensive quantitative backtesting library with 50+ metrics:
Sharpe/Sortino ratios, R-Expectancy, SQN, drawdown analysis, Monte Carlo
simulation, Walk-Forward Analysis, VaR/CVaR, benchmark comparison, and
interactive table rendering for TradingView strategies.
version 15 (20.06.2026)
license MIT — opensource.org/licenses/MIT
IMPORTS:
fikira/Text/1 as FN — Font styling for table cells (Sans Bold / Sans-Serif Bold)
PUBLIC API:
runDeeptest(...) — Complete backtest analysis orchestrator (only export)
type Stats — 50+ metric container returned by runDeeptest
type ThresholdConfig — Metric threshold + color configuration
type RollingStats — Rolling window analysis results
══════════════════════════════════════════════════════════════════════════════════════
runDeeptest(tableBg, headerBg, borderColor, bullColor, bearColor, textSize, showComplementaryRow, showStressTestTable, showDrawdownRecoveryCards, showTradeCards, showRExpectancy, enableLogging)
runDeeptest — Complete backtest analysis orchestrator (PUBLIC API)
Calls calculateFromStrategy() for 50+ metrics, then renders:
├ Main backtest table (23 columns × 3 rows + complementary row + footer)
├ Stress test matrix (IS | Monte Carlo | OOS — if showStressTestTable)
├ Drawdown/recovery cards (if showDrawdownRecoveryCards)
└ Top/worst trade cards (if showTradeCards)
Execution model: heavy computation runs once on last confirmed bar, table
rendering on last bar. Benchmark returns accumulate per-bar from SPY daily.
Parameters:
tableBg (color): Table background color
headerBg (color): Header background color
borderColor (color): Border color
bullColor (color): Color for positive metric values
bearColor (color): Color for negative metric values
textSize (string): Cell font size
showComplementaryRow (bool): Toggle 2nd data row
showStressTestTable (bool): Toggle MC/WFA stress test table
showDrawdownRecoveryCards (bool): Toggle drawdown/recovery card tables
showTradeCards (bool): Toggle top/worst trade card tables
showRExpectancy (bool): R-multiple display mode for expectancy
enableLogging (bool): Output all metrics to Data Window via log.info()
Returns: Stats object with all computed metrics
═══════════════════════════════════════════════════════════════════════════
Stats
Stats — Comprehensive backtest statistics container (50+ fields)
Fields:
totalTrades (series int)
winTrades (series int)
lossTrades (series int)
evenTrades (series int)
winRate (series float)
lossRate (series float)
avgWinPct (series float)
avgLossPct (series float)
avgTradePct (series float)
profitFactor (series float)
payoffRatio (series float)
expectancy (series float)
rExpectancy (series float)
grossProfit (series float)
grossLoss (series float)
netProfit (series float)
netProfitPct (series float)
compEffect (series float)
sharpe (series float)
sortino (series float)
calmar (series float)
martin (series float)
maxDrawdownPct (series float)
currentDrawdownPct (series float)
maxEquity (series float)
minEquity (series float)
cagr (series float)
monthlyReturn (series float)
maxConsecWins (series int)
maxConsecLosses (series int)
avgTradeDuration (series float)
avgWinDuration (series float)
avgLossDuration (series float)
timeInMarketPct (series float)
tradesPerMonth (series float)
tradesPerYear (series float)
skewness (series float)
kurtosis (series float)
var95 (series float)
cvar95 (series float)
ulcerIndex (series float)
riskOfRuin (series float)
pValue (series float)
alpha (series float)
beta (series float)
buyHoldReturn (series float)
equityRSquared (series float)
firstTradeTime (series int)
lastTradeTime (series int)
tradingPeriodDays (series float)
sqn (series float)
Comprehensive quantitative backtesting library with 50+ metrics:
Sharpe/Sortino ratios, R-Expectancy, SQN, drawdown analysis, Monte Carlo
simulation, Walk-Forward Analysis, VaR/CVaR, benchmark comparison, and
interactive table rendering for TradingView strategies.
version 15 (20.06.2026)
license MIT — opensource.org/licenses/MIT
IMPORTS:
fikira/Text/1 as FN — Font styling for table cells (Sans Bold / Sans-Serif Bold)
PUBLIC API:
runDeeptest(...) — Complete backtest analysis orchestrator (only export)
type Stats — 50+ metric container returned by runDeeptest
type ThresholdConfig — Metric threshold + color configuration
type RollingStats — Rolling window analysis results
══════════════════════════════════════════════════════════════════════════════════════
runDeeptest(tableBg, headerBg, borderColor, bullColor, bearColor, textSize, showComplementaryRow, showStressTestTable, showDrawdownRecoveryCards, showTradeCards, showRExpectancy, enableLogging)
runDeeptest — Complete backtest analysis orchestrator (PUBLIC API)
Calls calculateFromStrategy() for 50+ metrics, then renders:
├ Main backtest table (23 columns × 3 rows + complementary row + footer)
├ Stress test matrix (IS | Monte Carlo | OOS — if showStressTestTable)
├ Drawdown/recovery cards (if showDrawdownRecoveryCards)
└ Top/worst trade cards (if showTradeCards)
Execution model: heavy computation runs once on last confirmed bar, table
rendering on last bar. Benchmark returns accumulate per-bar from SPY daily.
Parameters:
tableBg (color): Table background color
headerBg (color): Header background color
borderColor (color): Border color
bullColor (color): Color for positive metric values
bearColor (color): Color for negative metric values
textSize (string): Cell font size
showComplementaryRow (bool): Toggle 2nd data row
showStressTestTable (bool): Toggle MC/WFA stress test table
showDrawdownRecoveryCards (bool): Toggle drawdown/recovery card tables
showTradeCards (bool): Toggle top/worst trade card tables
showRExpectancy (bool): R-multiple display mode for expectancy
enableLogging (bool): Output all metrics to Data Window via log.info()
Returns: Stats object with all computed metrics
═══════════════════════════════════════════════════════════════════════════
Stats
Stats — Comprehensive backtest statistics container (50+ fields)
Fields:
totalTrades (series int)
winTrades (series int)
lossTrades (series int)
evenTrades (series int)
winRate (series float)
lossRate (series float)
avgWinPct (series float)
avgLossPct (series float)
avgTradePct (series float)
profitFactor (series float)
payoffRatio (series float)
expectancy (series float)
rExpectancy (series float)
grossProfit (series float)
grossLoss (series float)
netProfit (series float)
netProfitPct (series float)
compEffect (series float)
sharpe (series float)
sortino (series float)
calmar (series float)
martin (series float)
maxDrawdownPct (series float)
currentDrawdownPct (series float)
maxEquity (series float)
minEquity (series float)
cagr (series float)
monthlyReturn (series float)
maxConsecWins (series int)
maxConsecLosses (series int)
avgTradeDuration (series float)
avgWinDuration (series float)
avgLossDuration (series float)
timeInMarketPct (series float)
tradesPerMonth (series float)
tradesPerYear (series float)
skewness (series float)
kurtosis (series float)
var95 (series float)
cvar95 (series float)
ulcerIndex (series float)
riskOfRuin (series float)
pValue (series float)
alpha (series float)
beta (series float)
buyHoldReturn (series float)
equityRSquared (series float)
firstTradeTime (series int)
lastTradeTime (series int)
tradingPeriodDays (series float)
sqn (series float)
Thư viện Pine
Theo đúng tinh thần TradingView, tác giả đã công bố mã Pine này như một thư viện mã nguồn mở để các lập trình viên Pine khác trong cộng đồng có thể tái sử dụng. Chúc mừng tác giả! Bạn có thể sử dụng thư viện này cho mục đích cá nhân hoặc trong các ấn phẩm mã nguồn mở khác, nhưng việc tái sử dụng mã này trong các ấn phẩm phải tuân theo Nội Quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.
Thư viện Pine
Theo đúng tinh thần TradingView, tác giả đã công bố mã Pine này như một thư viện mã nguồn mở để các lập trình viên Pine khác trong cộng đồng có thể tái sử dụng. Chúc mừng tác giả! Bạn có thể sử dụng thư viện này cho mục đích cá nhân hoặc trong các ấn phẩm mã nguồn mở khác, nhưng việc tái sử dụng mã này trong các ấn phẩm phải tuân theo Nội Quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.