TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/theonetrade/backtest-ollama-crontab/llms.txt
Use this file to discover all available pages before exploring further.
RiskOutline is the central decision-making unit in the pipeline. It receives a Telegram channel signal — symbol, direction, targets, and stop-loss — and asks a local Ollama LLM whether to follow or skip it. The decision is based on two hard empirical rules derived from 24-hour pre-computed metrics, not on the LLM’s intuition. Candle data from two timeframe advisors is injected purely for the LLM’s audit fields (sure_level and confidence), which feed the post-analysis dump but never influence the action field.
Registration
The outline is registered viaaddOutline<RiskOutlineContract> from agent-swarm-kit:
outlineName
OutlineName.RiskOutline = "risk_outline"completion
CompletionName.OllamaOutlineToolCompletionformat
zodResponseFormat(RiskOutlineFormat, "risk_assessment")Zod Response Format (RiskOutlineFormat)
The zod schema defined in src/contract/RiskOutline.ts is passed directly to zodResponseFormat to generate an OpenAI-compatible JSON schema. It is the source of truth for both the LLM’s output shape and the five runtime validations.
The trading decision.
"follow" opens a position in the signal’s direction; "skip" discards the signal entirely. Determined exclusively by the two metric rules — never by sure_level or confidence.Audit-only field. The LLM’s assessment of accumulation / manipulation evidence in the candle data.
Audit-only field. Data reliability rating.
"reliable" when ≥ 60 one-minute candles are available and metrics are unambiguous; "not_reliable" otherwise.A 2–3 sentence verdict for the trader, naming the triggered rule and the exact metric values. Minimum 30 characters enforced at runtime.
A flat string of step-by-step reasoning, steps separated by
\n. Must not be a JSON object or array. Minimum 80 characters enforced at runtime.Constants
PRE_CANDLES_LIMIT
1440 — 24 hours of 1-minute candles fetched to compute
avgRangePct and momentum24hPct.SHORT_MIN_AVG_RANGE_PCT
0.07 % — SHORT signals on assets below this average range are skipped (sleeping-coin stop-hunt rule).
LONG_MIN_MOMENTUM_24H_PCT
−1 % — LONG signals on assets whose 24 h momentum is below this threshold are skipped (knife-catching rule).
getOutlineHistory — Message Construction
The getOutlineHistory function receives { history } (the mutable IOutlineHistory object) plus four positional arguments: symbol, direction, targets, and stoploss. It builds the conversation context in a strict order before the LLM is invoked.
System prompt
Pushes the
RISK_PROMPT string as a system role message. The prompt explains the two decision rules, the five audit levels, the expected output format, and strict instructions not to use intuition or re-compute pre-computed metrics.1-minute candle history (commitOneMinuteHistory)
Calls Throws
ask(symbol, AdvisorName.StockData1mAdvisor) which invokes StockData1mAdvisor and returns a markdown table of the last 240 1m candles (4 hours). Pushes a user/assistant exchange:"StockData1mAdvisor failed" if the advisor returns a falsy value.15-minute candle history (commitFifteenMinuteHistory)
Calls Throws
ask(symbol, AdvisorName.StockData15mAdvisor) which returns a markdown table of the last 32 15m candles (8 hours). Follows the same push pattern:"StockData15mAdvisor failed" if the advisor returns a falsy value.Pre-computed metrics (commitMetricsHistory)
Fetches These are pushed as a user/assistant pair so the LLM reads them as pre-computed facts:
PRE_CANDLES_LIMIT (1440) 1m candles via getCandles(symbol, "1m", 1440) and computes two aggregate metrics:The LLM is explicitly instructed not to re-derive these numbers. Rule evaluation is always performed against the values reported in this message.
Draft signal (commitDraftSignal)
Pushes the raw Telegram signal as a user/assistant pair so the LLM can read the direction and levels it must evaluate:
The Two Decision Rules
The LLM prompt encodes three rules. Rules 1 and 2 can each fire a"skip". Rule 3 is the default.
Rule 1 — Sleeping-Coin SHORT
Condition:
direction = SHORT AND avgRangePct < 0.07 %Action: "skip"A low-volatility asset (“sleeping coin”) is a stop-hunt target. A single large candle from a market-maker will sweep short stops upward.Rule 2 — Knife-Catching LONG
Condition:
direction = LONG AND momentum24hPct < -1 %Action: "skip"A LONG signal on a market in downward momentum means buyers enter on the way down; the stop is almost certain to be hit.Rule 3 — Default Follow
Condition: Neither Rule 1 nor Rule 2 fired.Action:
"follow"Validations
All five validations run against the parsed LLM response beforeonValidDocument is called. Any failure causes the outline to retry.
- Validation 1 — action
- Validation 2 — sure_level
- Validation 3 — confidence
- Validation 4 — description length
- Validation 5 — reasoning length
Field:
actionRule: Must be exactly "skip" or "follow".Error: action "X" вне допустимого набора skip, followonValidDocument Callback
After all validations pass, onValidDocument writes the result to disk using dumpOutlineResult from agent-swarm-kit:
./dump/outline/risk accumulates one JSON file per validated call, enabling offline backtesting and performance analysis without a live exchange connection.
runRiskOutline Global
src/func/risk.function.ts exposes runRiskOutline on globalThis so the outline can be invoked interactively (e.g. from a Node.js REPL or a one-off script) outside the live 15-minute crontab pipeline.
Trading pair symbol, e.g.
"BTCUSDT".Original publication timestamp of the Telegram signal. Passed to
alignToInterval(publishedAt, "1m") to snap it to the nearest 1-minute boundary before the mock context is constructed.Exchange identifier used to resolve candle data in the mock context, e.g.
"binance".Signal direction from the Telegram channel.
Array of take-profit price levels in USD.
Hard stop-loss price level in USD.