Data Generation

Event Injection

Backtest Control

Performance

Scroll: pan | Ctrl+Scroll: zoom | Drag: pan | Hover: details

Lifecycle Callbacks

onStrategyStart()
Called when strategy starts
onBar(bar)
Triggered on each bar close
onBarOpen(bar)
Triggered on each bar open
onStrategyStop()
Called when strategy stops

Order/Position/Stop Callbacks

onOrderFilled(order)
Triggered when order is filled
onOrderCancelled(order)
Triggered when order is cancelled
onOrderRejected(order)
Triggered when order is rejected
onPositionOpened(pos)
Triggered when position is opened
onPositionClosed(pos)
Triggered when position is closed
onPositionChanged(pos)
Triggered when position changes (add/reduce)
onStopExecuted(stop)
Called when stop is triggered
onStopCancelled(stop)
Called when stop is cancelled

Market Orders

this.buy (qty, text?)
Market buy (fills at next bar open)
this.sell (qty, text?)
Market sell (fills at next bar open)

Limit/Stop Orders

this.buyLimit (qty, price, text?)
Limit buy
this.sellLimit (qty, price, text?)
Limit sell
this.buyStop (qty, stopPrice, text?)
Stop buy
this.sellStop (qty, stopPrice, text?)
Stop sell
this.buyStopLimit (qty, price, stopPrice, text?)
Stop-limit buy
this.sellStopLimit (qty, price, stopPrice, text?)
Stop-limit sell

Low-level Order API

this.marketOrder (side, qty, text?)
Create market order object (not auto-sent)
this.limitOrder (side, qty, price, text?)
Create limit order object
this.stopOrder (side, qty, stopPrice, text?)
Create stop order object
this.stopLimitOrder (side, qty, price, stopPrice, text?)
Create stop-limit order object
this.sendOrder (order)
Send order
this.cancelOrder (order)
Cancel order

Stops

this.setStop (level, stopType?, mode?)
Set stop (StopType: FIXED/TRAILING, StopMode: ABSOLUTE/PERCENT)

Properties

this.bars
All bars up to current
this.bar
Current bar
this.position
Current position {side, qty, entryPrice} or null
this.hasPosition
Has position (boolean)
this.hasLongPosition
Has long position
this.hasShortPosition
Has short position
this.portfolio
{cash, equity, initialCash}

Logging

this.log (message)
Output log message

Enum Constants

OrderSide
BUY / SELL
StopType
FIXED / TRAILING
StopMode
ABSOLUTE / PERCENT

Bar Object Properties

bar.datetime
Timestamp (seconds), use new Date(bar.datetime * 1000)
bar.open / high / low / close
Open/High/Low/Close prices
bar.volume
Volume

Common Array Methods

this.bars.slice(-n)
Get last n bars
arr.map(b => b.close)
Extract close price array
arr.reduce((a,b) => a+b)
Sum
Math.max(...arr)
Maximum value
Math.min(...arr)
Minimum value
ID Time Side Type Status Qty Price Note
No orders
Side Entry Price Entry Date Qty Closed Exit Date PnL PnL %
No positions
No logs