Commit functions are the primary mechanism for dynamically managing an open position during its lifetime. Each function is context-aware: in backtest mode it applies mutations against the virtual timeline, while in live mode it routes through the registeredDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/theonetrade/backtest-kit/llms.txt
Use this file to discover all available pages before exploring further.
Broker adapter before mutating internal state. If the adapter throws — for example because the exchange rejected an order — the state mutation is skipped and the framework retries automatically on the next tick. All commit functions return false gracefully when no open position exists, making them safe to call without pre-checking signal state.
commitAverageBuy
Add a new Dollar Cost Averaging (DCA) entry to the current open position.Trading pair symbol (e.g.,
"BTCUSDT").Dollar amount for this DCA entry. Defaults to
CC_POSITION_ENTRY_COST (default $100).false when the current price is not below the lowest previous entry price (anti-record not broken). Set CC_ENABLE_DCA_EVERYWHERE: true via setConfig to allow averaging at any price below priceOpen. The effective entry price is the cost-weighted harmonic mean of all accepted DCA entries.
commitPartialProfit
Close a percentage of the position while price moves toward take-profit.Trading pair symbol.
Absolute percentage of position to close, 0–100.
false if the price is not currently in the profit direction or if closing percentToClose would exceed 100% total closed.
commitPartialLoss
Close a percentage of the position while price moves toward stop-loss.Trading pair symbol.
Absolute percentage of position to close, 0–100.
false if the price is not currently in the loss direction or would over-close the position.
commitPartialProfitCost
Close a dollar amount of the position at profit. Convenience wrapper that converts a dollar value to a percent and callscommitPartialProfit.
Trading pair symbol.
Dollar value of position to close (e.g.,
150 closes $150 worth).getAveragePrice and invested cost via getPositionInvestedCost.
commitPartialLossCost
Close a dollar amount of the position at loss. Convenience wrapper that converts a dollar value to a percent and callscommitPartialLoss.
Trading pair symbol.
Dollar value of position to close.
commitTrailingStop
Shift the stop-loss by a percentage of the original SL distance.Trading pair symbol.
Percentage adjustment to the original SL distance. Negative values tighten (move SL closer to entry); positive values loosen. Range:
-100 to 100, excluding 0.Current market price used for price-intrusion validation. The new SL is rejected if
currentPrice has already crossed it.commitTrailingTake
Shift the take-profit by a percentage of the original TP distance.Trading pair symbol.
Percentage adjustment to the original TP distance. Negative values bring TP closer to entry (more conservative); positive values push it further.
Current market price used for price-intrusion validation.
commitTrailingStopCost
Set the stop-loss to an absolute price level. Convenience wrapper that convertsnewStopLossPrice to a percentShift and calls commitTrailingStop.
Trading pair symbol.
Desired absolute stop-loss price.
commitTrailingTakeCost
Set the take-profit to an absolute price level. Convenience wrapper that convertsnewTakeProfitPrice to a percentShift and calls commitTrailingTake.
Trading pair symbol.
Desired absolute take-profit price.
commitBreakeven
Move the stop-loss to the effective entry price (breakeven), locking in a zero-loss exit.Trading pair symbol.
(CC_PERCENT_SLIPPAGE + CC_PERCENT_FEE) * 2 + CC_BREAKEVEN_THRESHOLD. Idempotent: safe to call repeatedly; the SL is moved only once per signal. Fetches the current price automatically via getAveragePrice.
commitClosePending
Force-close the current active pending signal at the current market price.Trading pair symbol.
Optional commit payload.
id — correlation identifier for the close operation; note — human-readable reason string.getSignal on the next tick and can open a new position.
commitCancelScheduled
Cancel a pending scheduled signal without waiting for price to reachpriceOpen.
Trading pair symbol.
Optional commit payload with
id and note fields.commitActivateScheduled
Activate a scheduled signal early without waiting for price to reachpriceOpen.
Trading pair symbol.
Optional commit payload with
id and note fields.commitSignalNotify
Broadcast a user-defined informational note for the current active pending signal without affecting position state.Trading pair symbol.
Optional notification payload.
notificationNote — human-readable message (falls back to signal.note if omitted); notificationId — optional correlation ID for external systems.SignalInfoContract via signalNotifySubject. Useful for annotating strategy decisions, triggering external alerts, or logging mid-position events such as indicator crossings. Throws if called outside an execution context or when no pending signal exists.
stopStrategy
Stop a live strategy from generating new signals. The currently open position (if any) continues to monitor TP/SL until natural closure — the strategy is not force-closed.Trading pair symbol to stop signal generation for.
getSignal from being called on subsequent ticks. The strategy can be stopped gracefully in a SIGINT handler without abandoning open positions.
shutdown
Emit a framework-wide shutdown signal to all components listening toshutdownEmitter. Use in SIGINT / SIGTERM handlers for a clean process exit.
All commit functions return
false (or resolve without error) when no open position exists for the given symbol, making them safe graceful no-ops in edge cases. They never throw for missing signals — only for invalid argument values.