Order Type Matrix
Order-type matrix aligned to the unified execution core — MARKET, LIMIT, STOP_MARKET, STOP_LIMIT, BRACKET, and TRAILING_STOP_MARKET.
Order-Type Matrix Aligned to the Unified Execution Core#
| PyneScript trade-frame contract | Required fields | Execution-core meaning | Alignment note |
|---|---|---|---|
MARKET | entry_order_type, entry_price | Immediate market-style intent. | Maps directly to market-style core execution and is the safest cross-mode default. |
LIMIT | entry_order_type, entry_limit_price | Price-capped passive or resting intent. | The canonical passive-price field is entry_limit_price. |
STOP_MARKET | entry_order_type, entry_trigger_price | Trigger first, then market execution. | Stable across replay, backtest, and live adapters. |
STOP_LIMIT | entry_order_type, entry_trigger_price, entry_limit_price | Trigger first, then submit a limit order. | The current core keeps the distinction in replay/backtest and venue-capable live paths. |
BRACKET entry | Do not emit as a trade-frame entry type. | Use a normal entry type plus sl and tp. | This stays closer to the normalized execution contract. |
TRAILING_STOP_MARKET entry | Do not teach it as the primary entry type in the strategy layer. | Use a normal entry plus trail_offset. | Trailing is modeled through dedicated protective fields. |
Portability: if you want portability across PyneScript strategy backtest, replay, and live signal execution,
treat MARKET, LIMIT, STOP_MARKET, and STOP_LIMIT as the stable entry-type subset. Use dedicated
trade-frame risk fields for bracket and trailing behavior.
Entry Fields: Direction, Price, and Sizing Base#
| Field | Purpose | Practical rule |
|---|---|---|
entry_side | Trade direction intent. | Emit only on rows where a new entry actually exists. Empty string is safer than implicit carry-forward behavior. |
entry_price | Price basis for the order. | Choose the series that matches your timing assumption: open, close, trigger, or limit basis. |
quantity | Absolute size. | Use for unit-based sizing. Keep size_pct neutral when quantity is the primary sizing model. |
size_pct | Relative size. | Use when the strategy sizes by percent of capital or policy budget. Avoid mixing active quantity and active percent sizing in the same simple example. |
Order-Type Examples You Can Adapt Directly#
MARKET entry#
frame["entry_side"] = np.where(frame["buy_signal"], "BUY", np.where(frame["sell_signal"], "SELL", ""))
frame["entry_order_type"] = "MARKET"
frame["entry_price"] = frame["open"]
frame["quantity"] = 1.0LIMIT entry#
frame["entry_side"] = np.where(frame["buy_signal"], "BUY", "")
frame["entry_order_type"] = "LIMIT"
frame["entry_price"] = frame["close"]
frame["entry_limit_price"] = frame["close"] * 0.998
frame["quantity"] = 1.0STOP_MARKET entry#
frame["entry_side"] = np.where(frame["breakout_signal"], "BUY", "")
frame["entry_order_type"] = "STOP_MARKET"
frame["entry_price"] = frame["close"]
frame["entry_trigger_price"] = frame["high"].rolling(5).max()
frame["quantity"] = 1.0STOP_LIMIT entry#
frame["entry_side"] = np.where(frame["breakout_signal"], "BUY", "")
frame["entry_order_type"] = "STOP_LIMIT"
frame["entry_price"] = frame["close"]
frame["entry_trigger_price"] = frame["high"].rolling(5).max()
frame["entry_limit_price"] = frame["entry_trigger_price"] * 1.001
frame["quantity"] = 1.0