Why a breakout needs a time exit
A breakout strategy can remain exposed long after its initial momentum fades. A bar-count exit limits the duration of a trade independently of price. In MultiCharts .NET, implement this as a separate exit condition in a C# SignalObject, not as an indicator that merely paints the chart.
Trading rules
On a completed bar, enter long next bar at market if the close exceeds the highest high of the preceding 20 completed bars and the strategy is flat. Record the bar containing the actual strategy entry fill as age zero. At the close of the bar whose index is five greater than the entry bar, request a next-bar market exit if still long. Keep a separate protective stop, for example two ATR(14) below the entry, with ATR sampled at the signal close. Do not move this stop farther away.

Hypothetical closing prices: 100, 102, 101, 103, 102, 101, 100, 99. Entry bar is age zero; the red vertical line marks the exit decision at age five. The next open is the intended execution opportunity, not the plotted closing price.
Implementation in C#
Create entry and exit order objects in the signal's Create method using the platform order factory, and evaluate the conditions in CalcBar with intrabar order generation disabled for this example. Use the platform's strategy position and fill information to maintain entryBar; do not set it when the entry signal is merely submitted. The helper below is ordinary C# decision logic, not a standalone compiled SignalObject.
// C# decision helper, called once per completed bar
bool TimeExit(int currentBar, int entryBar, int maxAge,
bool isLong, bool exitPending)
{
return isLong && !exitPending && entryBar >= 0
&& maxAge > 0 && currentBar - entryBar >= maxAge;
}
When true, submit the configured long-exit market-next-bar order. Coordinate the protective stop and time exit so that competing orders cannot unintentionally reverse the position. Track pending exit state and reconcile it with order status; reset the entry index only after the position closes. If an order is rejected or cancelled, allow a controlled retry after checking the actual position. On restart, reconstruct entry age from reliable strategy execution history or suspend new decisions until reconciled.
Testing
Compare maximum ages of 3, 5 and 10 bars against a baseline with the same stop and entry rules. Include commissions, slippage and realistic session gaps. Examine holding time, adverse excursion, net return and drawdown on out-of-sample data. Test a stop hit on the same bar as the time exit, a rejected exit and a session-ending signal. A five-bar limit is not a five-minute limit unless the chart uses one-minute bars. Next-bar fills can differ from live fills, especially across gaps. The example has not been compiled or backtested. Trading involves risk of substantial loss.
For custom exit coordination and broker-specific execution handling, see Custom MultiCharts .NET strategy Development Services.