🧿 @backtest-kit/sidekick

The easiest way to create a new Backtest Kit trading bot project. Scaffolds a multi-timeframe crypto trading strategy with Pine Script indicators via PineTS runtime, 4H trend filter + 15m signal generator, partial profit taking, breakeven trailing stops, and risk validation.

screenshot

Ask DeepWiki npm License

πŸ“š Backtest Kit Docs | 🌟 GitHub

  • πŸš€ Zero Config: Get started with one command - no setup required
  • πŸ“Š Multi-timeframe analysis β€” 4H daily trend filter (RSI + MACD + ADX) combined with 15m entry signals (EMA crossover + volume spike + momentum)
  • πŸ“œ Pine Script indicators β€” strategies written in TradingView Pine Script v5, executed locally via @backtest-kit/pinets
  • πŸ›‘οΈ Risk management β€” SL/TP distance validation, Kelly-optimized partial profit taking (33/33/34%), breakeven trailing stop
  • πŸ”„ Position lifecycle β€” full monitoring with scheduled/opened/closed/cancelled event logging
  • πŸ”Œ Binance integration β€” OHLCV candles, order book depth, tick-precise price/quantity formatting via CCXT
  • πŸ• Historical frames β€” predefined backtest periods covering bull runs, sharp drops, and sideways markets
  • 🎨 Web UI dashboard β€” interactive charting via @backtest-kit/ui
  • πŸ’Ύ Persistent storage β€” crash-safe state with atomic persistence for both backtest and live modes
npx -y @backtest-kit/sidekick my-trading-bot
cd my-trading-bot
npm start

That's it! You now have a working trading bot with:

  • Multi-timeframe Pine Script strategy (4H trend + 15m signals)
  • Risk management validation (SL/TP distance checks)
  • Partial profit taking and breakeven trailing stops
  • Cache utilities and debug scripts
  • CLAUDE.md for AI-assisted strategy iteration
  • Environment configuration
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 # Dependencies

Determines the market regime using 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 but no clear bull/bear regime
NoTrades ADX ≀ 25 (weak trend)

Generates entry signals with EMA crossover confirmed by volume and momentum:

  • Long: EMA(5) crosses above EMA(13), RSI 40–65, price above EMA(50), volume spike (>1.5x 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 price
  • Signal expiry: 5 bars
  • Reject signals where SL distance < 0.2% (slippage protection)
  • Reject signals where TP distance < 0.2% (slippage protection)
  • Trend alignment: long signals rejected in bear regime, short signals rejected in bull regime
  • Partial profit taking: Scale out at 3 levels β€” 33% at TP3, 33% at TP2, 34% at TP1
  • Breakeven trailing stop: When breakeven is reached, lower trailing stop by 3 points
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
# Create project with custom name
npx -y @backtest-kit/sidekick my-bot

# Create in current directory (must be empty)
npx -y @backtest-kit/sidekick .
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

Found a bug or want to add a feature? Open an issue or submit a PR!

MIT Β© tripolskypetr