🧿 @backtest-kit/sidekick

The fastest way to start a backtest-kit trading bot β€” but the full-control one. Scaffolds a complete multi-timeframe crypto strategy where every wire (exchange, frames, risk, actions, runner) is editable source in your project: a 4H trend filter + 15m signal generator in Pine Script, partial profit taking, breakeven trailing stops, and risk validation.

screenshot

Ask DeepWiki npm License

πŸ“š Docs Β· 🌟 Reference implementation Β· πŸ™ GitHub

npx -y @backtest-kit/sidekick my-trading-bot
cd my-trading-bot && npm start

@backtest-kit/cli --init keeps the boilerplate inside the CLI; your repo holds only strategy files. Sidekick is the "eject": it writes the entire wiring β€” exchange adapter, frames, risk rules, actions, bootstrap, runner β€” as plain, editable source in your project, with no CLI in the loop and nothing hidden. Choose Sidekick when you want to read and own every line, not just the strategy.

What you get out of the box: a working multi-timeframe Pine Script strategy (4H trend + 15m signals), SL/TP distance risk validation, partial profit taking + breakeven trailing stops, cache utilities and debug scripts, a CLAUDE.md for AI-assisted iteration, and environment config.

  • πŸš€ Zero config β€” one command, no setup.
  • πŸ“Š Multi-timeframe β€” 4H trend filter (RSI+MACD+ADX) + 15m entries (EMA crossover + volume spike + momentum).
  • πŸ“œ Pine Script v5 β€” strategies run locally via @backtest-kit/pinets, no TradingView.
  • πŸ›‘οΈ Risk management β€” SL/TP distance validation, 33/33/34 partial profit, breakeven trailing.
  • πŸ”„ Full lifecycle β€” scheduled/opened/closed/cancelled event logging.
  • πŸ”Œ Binance via CCXT β€” OHLCV, order-book depth, tick-precise formatting.
  • πŸ• Historical frames β€” bull, sharp-drop, and sideways periods predefined.
  • 🎨 Web dashboard β€” @backtest-kit/ui charting.
  • πŸ’Ύ Crash-safe storage β€” atomic persistence for backtest and live.

4H trend filter (timeframe_4h.pine)

Classifies the market regime from three indicators:

Regime Condition
AllowLong ADX > 25, MACD histogram > 0, DI+ > DIβˆ’, RSI > 50
AllowShort ADX > 25, MACD histogram < 0, DIβˆ’ > DI+, RSI < 50
AllowBoth Strong trend, no clear bull/bear regime
NoTrades ADX ≀ 25 (weak trend)
15m signal generator (timeframe_15m.pine)

EMA crossover confirmed by volume and momentum:

  • Long β€” EMA(5) crosses above EMA(13), RSI 40–65, price above EMA(50), volume spike (>1.5Γ— MA), positive momentum.
  • Short β€” EMA(5) crosses below EMA(13), RSI 35–60, price below EMA(50), volume spike, negative momentum.
  • SL/TP β€” static 2% / 3% from entry. Signal expiry β€” 5 bars.
Risk filters & position management

Risk filters: reject signals with SL distance < 0.2% or TP distance < 0.2% (slippage protection); enforce trend alignment (longs rejected in a bear regime, shorts in a bull regime).

Position management: partial profit taking scales out at three levels β€” 33% at TP3, 33% at TP2, 34% at TP1; when breakeven is reached, the trailing stop is lowered by 3 points.

Backtest frames
Frame Period Market note
February2024 Feb 1–29, 2024 Bull run
October2025 Oct 1–31, 2025 Sharp drop Oct 9–11
November2025 Nov 1–30, 2025 Sideways with downtrend
December2025 Dec 1–31, 2025 Sideways, no clear direction

Everything below lands as editable source in your project β€” this is the package's deliverable.

Full tree
my-trading-bot/
β”œβ”€β”€ src/
β”‚ β”œβ”€β”€ index.mjs # Entry point β€” loads config, logic, bootstrap
β”‚ β”œβ”€β”€ main/bootstrap.mjs # Mode dispatcher (backtest / paper / live)
β”‚ β”œβ”€β”€ config/
β”‚ β”‚ β”œβ”€β”€ setup.mjs # Logger, storage, notifications, UI server
β”‚ β”‚ β”œβ”€β”€ validate.mjs # Schema validation for all enums
β”‚ β”‚ β”œβ”€β”€ params.mjs # Environment variables (Ollama API key)
β”‚ β”‚ └── ccxt.mjs # Binance exchange singleton via CCXT
β”‚ β”œβ”€β”€ logic/
β”‚ β”‚ β”œβ”€β”€ strategy/main.strategy.mjs # Main strategy β€” multi-TF signal logic
β”‚ β”‚ β”œβ”€β”€ exchange/binance.exchange.mjs # Exchange schema β€” candles, order book, formatting
β”‚ β”‚ β”œβ”€β”€ frame/*.frame.mjs # Backtest time frames (Feb 2024, Oct–Dec 2025)
β”‚ β”‚ β”œβ”€β”€ risk/sl_distance.risk.mjs # Stop-loss distance validation (β‰₯0.2%)
β”‚ β”‚ β”œβ”€β”€ risk/tp_distance.risk.mjs # Take-profit distance validation (β‰₯0.2%)
β”‚ β”‚ └── action/
β”‚ β”‚ β”œβ”€β”€ backtest_partial_profit_taking.action.mjs
β”‚ β”‚ β”œβ”€β”€ backtest_lower_stop_on_breakeven.action.mjs
β”‚ β”‚ └── backtest_position_monitor.action.mjs
β”‚ β”œβ”€β”€ classes/
β”‚ β”‚ β”œβ”€β”€ BacktestPartialProfitTakingAction.mjs # Scale out at 3 TP levels
β”‚ β”‚ β”œβ”€β”€ BacktestLowerStopOnBreakevenAction.mjs # Trailing stop on breakeven
β”‚ β”‚ └── BacktestPositionMonitorAction.mjs # Position event logger
β”‚ β”œβ”€β”€ math/
β”‚ β”‚ β”œβ”€β”€ timeframe_4h.math.mjs # 4H trend data β€” RSI, MACD, ADX, DI+/DIβˆ’
β”‚ β”‚ └── timeframe_15m.math.mjs # 15m signal data β€” EMA, ATR, volume, momentum
β”‚ β”œβ”€β”€ enum/ # String constants for type-safe schema refs
β”‚ └── utils/getArgs.mjs # CLI argument parser with defaults
β”œβ”€β”€ config/source/
β”‚ β”œβ”€β”€ timeframe_4h.pine # Pine Script v5 β€” Daily Trend Filter (RSI/MACD/ADX)
β”‚ └── timeframe_15m.pine # Pine Script v5 β€” Signal Strategy (EMA/ATR/Volume)
β”œβ”€β”€ scripts/
β”‚ β”œβ”€β”€ run_timeframe_15m.mjs # Standalone 15m Pine Script runner
β”‚ β”œβ”€β”€ run_timeframe_4h.mjs # Standalone 4H Pine Script runner
β”‚ └── cache/
β”‚ β”œβ”€β”€ cache_candles.mjs # Pre-download OHLCV candles (1m/15m/4h)
β”‚ β”œβ”€β”€ validate_candles.mjs # Verify cached candle data integrity
β”‚ └── cache_model.mjs # Pull Ollama LLM model with progress bar
β”œβ”€β”€ docker/ollama/
β”‚ β”œβ”€β”€ docker-compose.yaml # Ollama GPU container setup
β”‚ └── watch.sh # nvidia-smi monitor
β”œβ”€β”€ CLAUDE.md # AI strategy development guide
β”œβ”€β”€ .env # Environment variables
└── package.json

npx -y @backtest-kit/sidekick my-bot   # named project
npx -y @backtest-kit/sidekick . # current directory (must be empty)
Dependencies installed
Package Purpose
backtest-kit Core backtesting / trading framework
@backtest-kit/pinets Pine Script v5 runtime for Node.js
@backtest-kit/ui Interactive charting dashboard
@backtest-kit/ollama LLM inference integration
ccxt Binance exchange connectivity
functools-kit singleshot, randomString utilities
pinolog File-based structured logging
openai OpenAI API client
ollama Ollama local LLM client

Documentation Β· GitHub Β· Reference implementation

Found a bug or want a feature? Open an issue or submit a PR.

MIT Β© tripolskypetr