OPEN-SOURCE SCRIPT
Telah dikemas kini TT Backtest Compare

## TT Backtest Compare — Two Lorentzian Engines, One Chart, No Excuses
Every optimized strategy makes the same claim: "better than the defaults."
TT Backtest Compare is the tool that makes that claim checkable — on your
chart, your symbol, your timeframe, with both engines running live in front
of you.
It runs two complete Machine Learning: Lorentzian Classification engines
(original k-NN core by jdehorty, used under MPL-2.0) side by side in a single
indicator pane:
- ARM A — TT-Autotune: machine-evolved parameters delivered as Regime Sync
Codes, hot-swapped bar-by-bar as the market regime changes, scanning a
sliding pool of the most RECENT bars.
- ARM B — TT-Lorentzian (control): the verbatim stock jdehorty v2 defaults,
the original oldest-bars neighbor pool, the official MLExtensions and
KernelFunctions library calls. Untouched, on purpose.
Both arms see the same bars, pay the same costs, and obey the same exit
rules. The only difference is the thing being tested: where the parameters
came from.
### Why it's an indicator that runs its own backtests
A jdehorty-style "Backtest Adapter" can't do this job: adapters read another
script's plot through a Source input, and TradingView only exposes INDICATOR
plots that way — both of our production arms are strategy() scripts. So this
indicator embeds both engines and simulates the trades itself, with one shared
trade simulator so neither arm can cheat.
### Accounting you can audit
The trade loop is not a loose approximation of a backtest — it is a
transcription of the exact accounting used by TensorTrader's Python
genetic optimizer:
- Single position per arm, flip on the opposite signal.
- ATR stop-loss / take-profit bracket evaluated against the CURRENT bar's
ATR before signals (matching how the live strategy re-issues its exit
orders every bar).
- Per-trade ROI net of a round-trip cost you control (default 5 bps taker
fee + 2 bps slippage per side, 14 bps round trip).
- Trade-gated Sortino on per-trade ROI (MAR = 0, bounded, requires 2+
trades) — the same fitness statistic the optimizer breeds against.
On the server, a line-by-line Python transcription of this Pine trade loop is
continuously tested against the optimizer's canonical simulator — trades,
total ROI, compound ROI, drawdown, Sortino, and per-regime attribution must
all match or the build fails. When this chart says the evolved parameters
earned +X%, that number means the same thing as the optimizer's report.
### What you see
- Two equity curves (% return), with a green/red fill showing which arm is
ahead at every bar, plus an optional "edge" plot of the running difference.
- A stats table: compound return, total ROI, trade count, win rate, average
trade, Sortino, max drawdown, profit factor, and time in market — for each
arm, with the A−B delta in its own column.
- A per-regime table: the embedded six-state regime classifier (the same
ADX + regression-slope + ATR% classifier with hysteresis that runs in
TensorTrader's Python engine and inside TT-Autotune) buckets every trade
by the regime at its ENTRY bar, so you can see exactly where the evolved
parameters earn their edge — and where they don't. Regimes with no
deployed champion are marked honestly instead of hidden.
- A header card with the active sync source, backtest window, and the cost /
exit configuration, so screenshots are self-documenting.
Controls include a backtest start date, fee and slippage inputs, an
indicator-exits toggle (mirroring the optimizer's setting), full ATR bracket
settings, and an arms selector — each arm is a full k-NN scan per bar, so you
can drop to a single arm if a very long chart hits Pine's time limit.
### What this does NOT show
Honesty section: the comparison runs one position per arm because that is
what the optimizer's fitness function measures. The live TT-Autotune strategy
can pyramid up to 5 DCA legs, so its realized P&L scales differently — this
chart compares the SIGNAL edge, not the position ladder. All figures are
backtests net of modeled costs, not live results; past performance never
guarantees future returns.
### The TensorTrader side
Without a sync code, Arm A runs the same defaults as Arm B and the race is a
tie by construction — the indicator is fully functional but you're comparing
a thing to itself.
The evolved parameters come from TensorTrader's deterministic genetic
optimizer: populations of candidate genomes evolved over walk-forward,
out-of-sample folds, scored on net Sortino after fees and slippage, with
minimum-trade eligibility rules so no 6-trade miracle ever ships. A separate
champion is bred for each of the six market regimes and packed into one
Regime Sync Code per symbol × timeframe cell.
1. Create a free account at tensortrader.agent-swarm.net.
2. Pick an optimized symbol × timeframe cell from the catalog.
3. The TensorTrader browser extension pastes the packed Regime Sync Code into
the indicator's input for you — the same code that arms the TT-Autotune
strategy — and keeps it current when a newer champion is bred for your
cell.
Use this indicator BEFORE you trust any cell: load your market, arm A with
its code, and watch whether the edge is real on the window you care about.
That is what it was built for.
### Credits and license
Original Lorentzian Classification logic © jdehorty, used under the Mozilla
Public License 2.0 — Arm B imports his MLExtensions and KernelFunctions
libraries directly and runs his published defaults unmodified. The dual-arm
simulator, cost model, regime classifier, sync-code system, and comparison
tables by TensorTrader.
---
## Categories and tags (publication notes, not part of the description)
TradingView's publish dialog allows up to two categories plus free-form tags.
- Primary category: **Statistics** — the script's product is comparative
performance analytics (equity curves, Sortino, drawdown, profit factor),
not a trade signal.
- Secondary category: **Trend Analysis** — the underlying engines are
trend-classification (Lorentzian k-NN + kernel regression), and it's where
the jdehorty original and TT-Autotune audiences browse.
- Alternative secondary if you prefer positioning it as a research tool:
**Educational**.
Suggested tags: `machinelearning`, `lorentzian`, `knn`, `backtesting`,
`equitycurve`, `sortino`, `regime`, `abtest`, `tensortrader`.
Other notes:
- House Rules: as a derivative of an open-source script it must credit the
original and describe meaningful changes — the description does both, and
the MPL-2.0 header is already in the source.
- Publish as an INDICATOR (it is `indicator()`, not `strategy()` — the
Strategy Tester will not appear, which is expected and explained in the
description).
- The parity claim ("same numbers as the optimizer") is backed by
`test_pine_backtest_compare_accounting.py`; keep that test green before
republishing after any accounting change.
Every optimized strategy makes the same claim: "better than the defaults."
TT Backtest Compare is the tool that makes that claim checkable — on your
chart, your symbol, your timeframe, with both engines running live in front
of you.
It runs two complete Machine Learning: Lorentzian Classification engines
(original k-NN core by jdehorty, used under MPL-2.0) side by side in a single
indicator pane:
- ARM A — TT-Autotune: machine-evolved parameters delivered as Regime Sync
Codes, hot-swapped bar-by-bar as the market regime changes, scanning a
sliding pool of the most RECENT bars.
- ARM B — TT-Lorentzian (control): the verbatim stock jdehorty v2 defaults,
the original oldest-bars neighbor pool, the official MLExtensions and
KernelFunctions library calls. Untouched, on purpose.
Both arms see the same bars, pay the same costs, and obey the same exit
rules. The only difference is the thing being tested: where the parameters
came from.
### Why it's an indicator that runs its own backtests
A jdehorty-style "Backtest Adapter" can't do this job: adapters read another
script's plot through a Source input, and TradingView only exposes INDICATOR
plots that way — both of our production arms are strategy() scripts. So this
indicator embeds both engines and simulates the trades itself, with one shared
trade simulator so neither arm can cheat.
### Accounting you can audit
The trade loop is not a loose approximation of a backtest — it is a
transcription of the exact accounting used by TensorTrader's Python
genetic optimizer:
- Single position per arm, flip on the opposite signal.
- ATR stop-loss / take-profit bracket evaluated against the CURRENT bar's
ATR before signals (matching how the live strategy re-issues its exit
orders every bar).
- Per-trade ROI net of a round-trip cost you control (default 5 bps taker
fee + 2 bps slippage per side, 14 bps round trip).
- Trade-gated Sortino on per-trade ROI (MAR = 0, bounded, requires 2+
trades) — the same fitness statistic the optimizer breeds against.
On the server, a line-by-line Python transcription of this Pine trade loop is
continuously tested against the optimizer's canonical simulator — trades,
total ROI, compound ROI, drawdown, Sortino, and per-regime attribution must
all match or the build fails. When this chart says the evolved parameters
earned +X%, that number means the same thing as the optimizer's report.
### What you see
- Two equity curves (% return), with a green/red fill showing which arm is
ahead at every bar, plus an optional "edge" plot of the running difference.
- A stats table: compound return, total ROI, trade count, win rate, average
trade, Sortino, max drawdown, profit factor, and time in market — for each
arm, with the A−B delta in its own column.
- A per-regime table: the embedded six-state regime classifier (the same
ADX + regression-slope + ATR% classifier with hysteresis that runs in
TensorTrader's Python engine and inside TT-Autotune) buckets every trade
by the regime at its ENTRY bar, so you can see exactly where the evolved
parameters earn their edge — and where they don't. Regimes with no
deployed champion are marked honestly instead of hidden.
- A header card with the active sync source, backtest window, and the cost /
exit configuration, so screenshots are self-documenting.
Controls include a backtest start date, fee and slippage inputs, an
indicator-exits toggle (mirroring the optimizer's setting), full ATR bracket
settings, and an arms selector — each arm is a full k-NN scan per bar, so you
can drop to a single arm if a very long chart hits Pine's time limit.
### What this does NOT show
Honesty section: the comparison runs one position per arm because that is
what the optimizer's fitness function measures. The live TT-Autotune strategy
can pyramid up to 5 DCA legs, so its realized P&L scales differently — this
chart compares the SIGNAL edge, not the position ladder. All figures are
backtests net of modeled costs, not live results; past performance never
guarantees future returns.
### The TensorTrader side
Without a sync code, Arm A runs the same defaults as Arm B and the race is a
tie by construction — the indicator is fully functional but you're comparing
a thing to itself.
The evolved parameters come from TensorTrader's deterministic genetic
optimizer: populations of candidate genomes evolved over walk-forward,
out-of-sample folds, scored on net Sortino after fees and slippage, with
minimum-trade eligibility rules so no 6-trade miracle ever ships. A separate
champion is bred for each of the six market regimes and packed into one
Regime Sync Code per symbol × timeframe cell.
1. Create a free account at tensortrader.agent-swarm.net.
2. Pick an optimized symbol × timeframe cell from the catalog.
3. The TensorTrader browser extension pastes the packed Regime Sync Code into
the indicator's input for you — the same code that arms the TT-Autotune
strategy — and keeps it current when a newer champion is bred for your
cell.
Use this indicator BEFORE you trust any cell: load your market, arm A with
its code, and watch whether the edge is real on the window you care about.
That is what it was built for.
### Credits and license
Original Lorentzian Classification logic © jdehorty, used under the Mozilla
Public License 2.0 — Arm B imports his MLExtensions and KernelFunctions
libraries directly and runs his published defaults unmodified. The dual-arm
simulator, cost model, regime classifier, sync-code system, and comparison
tables by TensorTrader.
---
## Categories and tags (publication notes, not part of the description)
TradingView's publish dialog allows up to two categories plus free-form tags.
- Primary category: **Statistics** — the script's product is comparative
performance analytics (equity curves, Sortino, drawdown, profit factor),
not a trade signal.
- Secondary category: **Trend Analysis** — the underlying engines are
trend-classification (Lorentzian k-NN + kernel regression), and it's where
the jdehorty original and TT-Autotune audiences browse.
- Alternative secondary if you prefer positioning it as a research tool:
**Educational**.
Suggested tags: `machinelearning`, `lorentzian`, `knn`, `backtesting`,
`equitycurve`, `sortino`, `regime`, `abtest`, `tensortrader`.
Other notes:
- House Rules: as a derivative of an open-source script it must credit the
original and describe meaningful changes — the description does both, and
the MPL-2.0 header is already in the source.
- Publish as an INDICATOR (it is `indicator()`, not `strategy()` — the
Strategy Tester will not appear, which is expected and explained in the
description).
- The parity claim ("same numbers as the optimizer") is backed by
`test_pine_backtest_compare_accounting.py`; keep that test green before
republishing after any accounting change.
Nota Keluaran
This Is Used To Compare The Backtest Of TT-Autotune Vs Default ML:LC ScriptSkrip sumber terbuka
Dalam semangat TradingView sebenar, pencipta skrip ini telah menjadikannya sumber terbuka, jadi pedagang boleh menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupuan anda boleh menggunakan secara percuma, ingat bahawa penerbitan semula kod ini tertakluk kepada Peraturan Dalaman.
Penafian
Maklumat dan penerbitan adalah tidak bertujuan, dan tidak membentuk, nasihat atau cadangan kewangan, pelaburan, dagangan atau jenis lain yang diberikan atau disahkan oleh TradingView. Baca lebih dalam Terma Penggunaan.
Skrip sumber terbuka
Dalam semangat TradingView sebenar, pencipta skrip ini telah menjadikannya sumber terbuka, jadi pedagang boleh menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupuan anda boleh menggunakan secara percuma, ingat bahawa penerbitan semula kod ini tertakluk kepada Peraturan Dalaman.
Penafian
Maklumat dan penerbitan adalah tidak bertujuan, dan tidak membentuk, nasihat atau cadangan kewangan, pelaburan, dagangan atau jenis lain yang diberikan atau disahkan oleh TradingView. Baca lebih dalam Terma Penggunaan.