strategy.exit
Stop and / or target for the position of entry from_entry ("" = every entry): stop and limit are prices, loss and profit distances in ticks from the entry fill. A trailing stop: trail_offset ticks behind the best price, starting once trail_price or trail_points (ticks in profit) is reached (at once with neither); it starts working from the bar after it starts. qty or qty_percent close part of the position. The first reached closes it and cancels the other. Given while the entry is still waiting, they start the moment it fills (in that bar a stop may fill, a target only when the entry filled at the open of that bar). qty limits how much it closes. Call it again to move the prices.
strategy.exit(id: string, from_entry: string = "", qty: float = na, profit: float = na, limit: float = na, loss: float = na, stop: float = na, comment: string = na, qty_percent: float = na, trail_price: float = na, trail_points: float = na, trail_offset: float = na)
Parameters
idstring: the order name; trades and the chart show itfrom_entrystring: The id of the entry whose contracts it protects; "" (default) covers every entry.qtyfloat: Contracts it closes (default: all from that entry).profitfloat: target distance from the entry fill in tickslimitfloat: target pricelossfloat: stop distance from the entry fill in ticksstopfloat: stop pricecommentstring: Text kept with the order; the trade it closes keeps the closing order's comment (default none).qty_percentfloat: percent of the contracts held to close (with no qty)trail_pricefloat: trailing stop: the price that starts ittrail_pointsfloat: trailing stop: starts this many ticks in profit from the entrytrail_offsetfloat: trailing stop: trails the best price by this many ticks
Example
strategy.exit("Exit", "Long", profit=40, loss=20)
strategy.exit("Trail", "Long", loss=20, trail_points=40, trail_offset=10)