Exit
ExitBase is the abstract base for exit conditions. Each exit is attached to an Entry and checked on every market event. When the exit condition is met, all positions are closed.
Namespace: MZpack.NT8.Algo
Inheritance: ExitBase (abstract)
Source: [INSTALL PATH]/API/Extensions/Exits/ExitBase.cs
ExitBase Properties
| Property | Type | Default | Description |
|---|---|---|---|
Calculate | Calculate | OnEachTick | When to check the exit condition: OnEachTick or OnBarClose |
ExitBase Methods
| Method | Description |
|---|---|
OnExecution(Entry entry, MarketDataEventArgs e) | Checks timing (first tick of bar or each tick), calls CheckExit, closes all positions if exit triggers |
CheckExit(MarketDataEventArgs e, Entry entry, MarketPosition marketPosition, out string reason) | Abstract — return true to trigger exit, set reason for logging |
ClosePosition(Position position, string reason, DateTime time) | Virtual — calls position.CancelClose(false, reason, time) |
BarCloseTarget
Closes the position on the first bar close after the entry bar.
Inheritance: BarCloseTarget : ExitBase
Constructor
public BarCloseTarget()
Sets Calculate = OnBarClose.
Behavior
CheckExit returns true when CurrentBar > entry.FilledBarIdx — i.e., the bar after the entry fill closes. Reason: "Bar close".
Custom Exit
To create a custom exit condition, subclass ExitBase and implement CheckExit:
public class MyExit : ExitBase
{
public override bool CheckExit(MarketDataEventArgs e, Entry entry,
MarketPosition marketPosition, out string reason)
{
reason = null;
if (/* your condition */)
{
reason = "My exit reason";
return true;
}
return false;
}
}
Attach the exit to an entry via entry.Exit = new MyExit().