Strategies
Any script that calls strategy.entry, exit or close is a strategy. Orders are simulated by the CodeLab backtester and fill at the next bar’s open, so there is no look-ahead. On the chart, outside a backtest, the order calls do nothing.
strategy.* API
Order calls for the backtester. Market orders fill at the next bar’s open; pass limit or stop for a limit or stop order.
strategy.entry(id, 'long' | 'short', opts?)Open or add to a position. id names the order slot. opts: qty (default 1), limit, stop, comment. Without limit or stop it is a market order.
strategy.exit(id, opts?)Close the position held under id, fully or partly (opts: qty, limit, stop, comment).
strategy.close(comment?)Close every open position at the next bar's open.
strategy.cancel(id) / cancelAll()Cancel pending orders.
strategy.positionRead-only: { isLong, isShort, isFlat, size, entryPrice, entryBar }. Also strategy.equity, netProfit, openProfit, closedTrades and winRate.