Multi-timeframe technical analysis for AI trading on backtest-kit. Computes 50+ indicators across four timeframes plus order-book depth, and emits LLM-ready markdown reports β drop the whole market context into an LLM prompt in one call.

π Docs Β· π Reference implementation Β· π GitHub
npm install @backtest-kit/signals backtest-kit
An LLM trading strategy is only as good as the market context you hand it. Computing 50+ indicators across four timeframes, formatting order-book depth, and laying it all out as clean markdown β by hand, every tick β is the unglamorous 200 lines that decides signal quality. This package is that work, pre-computed, cached, and synchronized with backtest-kit's timeline: one commitHistorySetup(symbol, messages) appends order book + candle history + indicators for 1m/15m/30m/1h to your LLM message array.
import { commitHistorySetup } from '@backtest-kit/signals';
const messages = [];
await commitHistorySetup('BTCUSDT', messages);
// messages now hold: order book + 1m/15m/30m/1h candle history
// + indicators for all 4 timeframes + system context (symbol, price, timestamp)
const signal = await llm(messages);
import { v4 as uuid } from 'uuid';
import { addStrategy, dumpSignal } from 'backtest-kit';
import { commitHistorySetup } from '@backtest-kit/signals';
import { json } from './utils/json.mjs'; // your LLM wrapper
addStrategy({
strategyName: 'llm-strategy', interval: '5m', riskName: 'demo',
getSignal: async (symbol) => {
const messages = [{ role: 'system', content: 'You are a trading bot. Analyze the indicators and generate a signal.' }];
await commitHistorySetup(symbol, messages);
messages.push({ role: 'user', content: [
'Based on the technical analysis above, generate a trading signal.',
'Use position: "wait" if signals are unclear or contradictory.',
'Return JSON: { position: "long"|"short"|"wait", priceTakeProfit: number, priceStopLoss: number }',
].join('\n') });
const resultId = uuid();
const signal = await json(messages);
await dumpSignal(resultId, messages, signal); // archive for debugging
return { ...signal, id: resultId };
},
});
Prefer to choose exactly what goes into the prompt? Call the individual report functions β each appends one markdown section to messages.
import {
commitBookDataReport, // order book: bids/asks, spread, imbalance
commitOneMinuteHistory, commitFifteenMinuteHistory, // candle histories (last 15 / 8 β¦)
commitThirtyMinuteHistory, commitHourHistory,
commitMicroTermMath, commitShortTermMath, // indicator tables per timeframe
commitSwingTermMath, commitLongTermMath,
} from '@backtest-kit/signals';
const messages = [];
await commitBookDataReport('BTCUSDT', messages);
await commitOneMinuteHistory('BTCUSDT', messages);
await commitMicroTermMath('BTCUSDT', messages);
// β¦add only the sections you want, then call your LLM
commitHistorySetup is simply the orchestrator that runs all of these in the right order.
| Timeframe | Candles | Indicators | Use case |
|---|---|---|---|
| MicroTerm (1m) | 60 | RSI(9,14), MACD(8,21,5), Stochastic, ADX(9), Bollinger(8,2), ATR, CCI, Volume, Squeeze | Scalping, ultra-short entries |
| ShortTerm (15m) | 144 | RSI(9), MACD(8,21,5), Stochastic(5,3,3), ADX(14), Bollinger(10,2), Fibonacci | Day trading |
| SwingTerm (30m) | 96 | RSI(14), MACD(12,26,9), Stochastic(14,3,3), Bollinger(20,2), Support/Resistance | Swing trading |
| LongTerm (1h) | 100 | RSI(14), MACD(12,26,9), ADX(14), Bollinger(20,2), SMA(50), DEMA, WMA, Volume Trend | Trend analysis |
Order book β symbol, best bid/ask, mid price, spread, depth imbalance ((bid_vol β ask_vol)/(bid_vol + ask_vol), + = buy pressure), and top-20 bid/ask levels with % of total.
Candle history β per-candle table: timestamp, OHLC, volume, volatility, body size.
Indicators β a wide per-bar table; e.g. MicroTerm columns: Price, RSI(9), RSI(14), MACD, Signal, Histogram, Stoch %K/%D, ADX, +DI, βDI, BB Upper/Middle/Lower, ATR(5/9), CCI(9), Volume, Vol Trend, Momentum, ROC, Support, Resistance, Squeeze, Pressure β followed by a Data Sources note listing every period used.
Cache TTL (cleared on error): 1m data β 1 min Β· 15m β 5 min Β· 30m β 15 min Β· 1h β 30 min Β· order book β 5 min.
(bid β ask)/(bid + ask), positive = buy pressure.import { setLogger } from '@backtest-kit/signals';
setLogger({ log: console.log, debug: console.debug, info: console.info, warn: console.warn });
// β Manual β 40+ indicators, formatting, caching, all by hand
const candles = await getCandles('BTCUSDT', '1m', 60);
const rsi = calculateRSI(candles, 14);
const macd = calculateMACD(candles, 12, 26, 9);
const bb = calculateBollingerBands(candles, 20, 2);
// β¦and the markdown formatting, and the cache
messages.push({ role: 'user', content: formatToMarkdown(rsi, macd, bb /* β¦ */) });
// β
With signals
await commitHistorySetup('BTCUSDT', messages);
Pre-computed, cached, optimized Β· 50+ indicators Γ 4 timeframes Β· LLM-ready markdown Β· synchronized with the backtest timeline Β· validation & error handling built in.
| Export | Description |
|---|---|
commitHistorySetup(symbol, messages) |
Orchestrator β appends order book + all candle histories + all indicators + context |
commitBookDataReport(symbol, messages) |
Order-book depth & imbalance section |
commitOneMinuteHistory / commitFifteenMinuteHistory / commitThirtyMinuteHistory / commitHourHistory |
Candle-history sections per timeframe |
commitMicroTermMath / commitShortTermMath / commitSwingTermMath / commitLongTermMath |
Indicator-table sections (1m / 15m / 30m / 1h) |
setLogger(logger) |
Replace the default no-op logger |
lib |
Internal IoC service container (advanced use) |
function/history.function.ts β the four commit*History functions. function/math.function.ts β the four commit*Math functions. function/other.function.ts β commitBookDataReport + commitHistorySetup.tools/setup.tool.ts β setLogger. contract/{History,ReportFn}.contract.ts β report-function contracts. interfaces/Logger.interface.ts.lib/ IoC: core/{di,provide,types}, services/common/LoggerService, services/history/{One,Fifteen,Thirty}MinuteCandleHistoryService + HourCandleHistoryService, services/math/{MicroTerm,ShortTerm,SwingTerm,LongTerm}MathService + BookDataMathService (the math services are the package's bulk β 32β45 KB each). Every export maps to one of these; nothing in src/ is undocumented.Fork / PR on GitHub.
MIT Β© tripolskypetr