exitLong(string algo, var price, int lots)
exitShort(string algo, var price, int lots)
Exits all long resp. all short trades with the current asset that match the given algo identifier, at market or at a given price limit, until the given number of lots is closed.
exitTrade(TRADE*, var price, int lots): int
Exits the given number of lots of a particular trade at market or at a given price limit. Returns 0 when the order failed, otherwise nonzero.
Cancels an open trade with a particular identifier without sending a close order to the broker and without adding to the statistics. Useful for removing an externally closed position that was not transmitted to Zorro (f.i. on an NFA account).
|| 0 for closing all trades with the current algo/asset combination. Alternatively, an algorithm identifier, or the asset name when no algo is used in the script, or "*" for closing all trades with the current asset.
|| A pointer to the trade to be closed, or 0 for closing the current trade in a trade enumeration loop.
||Optional price or price distance for selling the position, or 0 for selling at market. A positive price or price distance constitutes an exit stop, a negative price is an exit limit (similar to Entry). An exit stop closes the position when the asset price is at or worse than the given price, like a stop loss; an exit limit closes the position when the asset price is at or better than the given price, like a profit target.
||Optional number of lots to be closed, or 0 for closing all open lots. Partially closing trades is not available with all brokers, for instance not with NFA compliant accounts.
||Identifier of the trade to be cancelled. Either the full number as assigned by the broker, or the last 4 digits as displayed in the Zorro window.
- Before closing a trade, check the business hours of the broker. Not all assets can be traded 24 hours per day. Trading is automatically disabled during weekends, during the LookBack period, or in the inactive period of SKIP or DataSplit.
- Optional parameters can be omitted. F.i. exitLong() exits all long positions with the current asset and algorithm identifier at market.
- If an exit stop or exit limit is given, the position is closed as soon as the target price is reached, no matter how long it takes. An exit stop overrides a more distant stop loss, an exit limit overrides a previous profit target. The exitLong/Short function can thus be used to tighten the stop loss or to change the profit target of open trades.
- If an exit order fails in live trading, Zorro will repeat it in increasing time intervals until it is executed (except for options or when OrderLimit is used). If the position can not be closed after 2 working days, Zorro will assume an issue with the broker server and remove the trade from its internal list. If the market is not open due to holidays or weekend, a message "Can't exit at weekends" is printed and the position is closed as soon as the market opens again.
- When no price was given, pending positions - positions either immediately entered before, or positions with an entry stop or limit - are also closed.
- The price at which the trade is closed in the backtest can be affected with the Fill variable.
- If a order function is defined in the script, it is called with 2 for the first argument and the TRADE* pointer for the second argument at the moment when the sell order is sent to the broker. This function can f.i. open a message box for manually exiting the trade, or control another broker's user interface.
exitShort(0,1.234); // exits all short trades with the current Algo/Asset as soon as the price is at or above 1.234 (exit stop).
enterLong/Short, numLong/Short, Entry, Hedge,