A script that declares strategy(…) places orders — entries, exits, stops, targets — and runs on Bentrix's strategy engine, on a workbench whose account decides the money.
A script that begins with strategy(…) instead of indicator(…) is a strategy: on each closed candle it may place orders, and Bentrix's strategy engine runs it like any strategy — on a laboratory workbench to test it, then loaded onto a paper or real workbench.
//@version=6
strategy("Two averages", overlay = true)
fast = ta.ema(close, input.int(9, "Fast"))
slow = ta.sma(close, input.int(21, "Slow"))
atr = ta.atr(14)
if ta.crossover(fast, slow)
strategy.entry("Long", strategy.long, qty = 0.1)
if ta.crossunder(fast, slow)
strategy.close("Long")
strategy.exit("Long exit", "Long", stop = close - 2 * atr, limit = close + 3 * atr)
01Saving and running
In the IDE, Save as a strategy (in the Laboratory) puts it among your strategies; the Strategies panel lists it, and Run… loads it onto a workbench. On a real workbench, its orders follow the workbench's Automations setting and the start card asks first.
02The orders
strategy.entry opens a position at the candle's close — at market, or as a limit, stop or stop-limit order; an entry against an open position closes it first. strategy.order places an order with no reversal. strategy.exit sets the position's stop and target on the venue (a partial close for less than all of it; a trailing stop run by Bentrix). strategy.close and strategy.close_all close; strategy.cancel and strategy.cancel_all cancel pending orders. What the run holds is read back before each closed candle: strategy.position_size (in lots, short negative), strategy.equity, strategy.netprofit and the rest.
03What the workbench decides
A strategy's money is the workbench's, never the script's. The declaration's initial_capital, currency, commission_*, slippage and margin_* are named on the Run sheet and not read: the account's own balance and currency, the feed's own costs and the venue's own fills are used — so a test in the laboratory is priced as the workbench would price it. Its inputs are the strategy's figures, so a batch can vary them.
04What is refused
A strategy is read at each candle's close, so calc_on_every_tick and calc_on_order_fills are refused by name, and pyramiding above one entry a side is not run. strategy.risk.* is not built yet: the run's own limits stand for it. See strategy and What a strategy is.