Skip to main content
An order call queues an order; the broker emulator fills it on a later price. The account holds one net position (strategy.position_size: positive long, negative short) made of open entries, which close oldest first.

When orders fill

On historical bars the emulator steps through each bar’s prices (open, then high and low, then close; high first when the open is nearer the high), filling queued orders at each step. The script runs once, at the close, so an order placed on bar N is first tested on bar N+1:
  • A market order fills at the open of bar N+1. With process_orders_on_close=true, an order placed on a confirmed bar also fills at that bar’s close.
  • A limit order fills at the first step at the limit or better (long: at or below). A stop order fills at the first step at the stop or worse (long: at or above). A stop-limit order arms at the stop, then fills by the limit rule.
  • The fill price is that step’s price, not the limit or stop level: a long limit at 99 on a bar that opens at 98 fills at 98.

The order calls

qty defaults to default_qty_value. For entry and order, a qty of zero or less counts as not given; for close it means the entry’s whole open quantity; for exit it stops the script with Invalid order quantity, as does a default size that cannot be worked out.
  • Reversal: strategy.entry against the open position closes it and opens the other side in one fill.
  • Pyramiding: an entry is ignored, without an error, when pyramiding entries are already open in its direction.
  • Same id: entry or order with an id still queued replaces that order; flipping its direction stops the script (Entry order direction cannot be changed...).
  • Exit: ignored when the position is flat at the call, or when no limit, stop, profit or loss is given, so call it on bars where you are already in the trade, not on the entry bar. It queues two orders and a fill removes the other; a new call with the same id replaces both. qty defaults to the whole open quantity.
  • OCA: oca_name works only with oca_type: strategy.oca_cancel removes the group’s other orders on a fill, strategy.oca_reduce reduces their quantity.
  • Direction is a plain string: "buy" compiles, then stops the script: invalid strategy direction "buy".
GoCharting is a charting and analytics tool. This is not investment advice. Trading and investing carry a high risk of loss and are not suitable for everyone. You can lose some or all of your money.