Managed orders

Strategies

Managed orders

Position-aware intent: say "be long 5" or "go flat" and let the framework figure out the reversal arithmetic and guard against double entries.

Managed orders (position-aware intent)

Managed orders are the simplest and safest way to trade, and the right default for most strategies. Instead of computing how many contracts to buy or sell, you express the position you want and the framework works out the order. EnterLong and EnterShort handle reversals automatically: from a short position, an EnterLong covers the short and opens the long in a single intent. ExitLong and ExitShort bring you back to flat and are no-ops when you are not on that side.

C#EnterLong(5);    // flat → buy 5; short 3 → buy 8 (cover + open long 5); already long → no-op
EnterShort(5);   // mirror of EnterLong
ExitLong();      // long → sell to flat; otherwise no-op
ExitShort();     // short → buy to flat; otherwise no-op

if (!HasPendingManagedOrder && signal) EnterLong(qty);   // guard avoids stacking while one is in flight
Call Behaviour by starting position
EnterLong(qty) Flat → enters long; short → reverses to long; already long → no-op.
EnterShort(qty) Mirror of EnterLong.
ExitLong() Closes a long via a market order; no-op when flat / short.
ExitShort() Closes a short via a market order; no-op when flat / long.

The pending-order guard

Each managed call routes through a single in-flight order. While that order is live — submitted but not yet terminal — HasPendingManagedOrder is true and every managed call is a no-op. This prevents a strategy that fires on each bar from stacking duplicate entries before the first one fills. The framework clears the flag the instant the managed order goes terminal (it feeds order updates into the controller before your OnOrderUpdate hook runs), so you can read the flag to decide whether to wait.

C#protected override void OnBar()
{
    if (HasPendingManagedOrder) return;          // let the prior intent settle first
    if (crossUp && IsFlat)  EnterLong(_qty.Value);
    if (crossDown && IsLong) ExitLong();
}
Market orders only. The managed helpers move to / from a position via market orders. For resting limits, custom OCO, or absolute-price brackets, drop down to raw orders; for multi-target scale-outs with auto-breakeven and trailing, layer an ATM plan on top — ATM is orthogonal to managed intent, so you can use EnterLong for the intent and let the ATM protect the resulting position.

Behind the surface

The helpers delegate to an IManagedOrderController the base class creates lazily on first use (via IStrategyContext.CreateManagedOrderController). You rarely touch it directly; the interface exposes exactly the four intent calls plus HasPendingOrder. A host that wants different intent→order semantics (alternate correlation tagging, throttling, simulated paper-fills) plugs in its own implementation through the context factory — the strategy code is unchanged.

Start here. Reach for raw orders or ATM only when managed intent cannot express what you need. For directional strategies these four calls are usually the whole trading surface.