Functions
strategy.exit()
Places exit orders for an open position: a take-profit, a stop-loss, or both. `from_entry` names the entry to exit; leave it out to exit all entries. Prices can be given as levels (`limit` for the take-profit, `stop` for the stop-loss) or as distances in ticks from the entry price (`profit` and `loss`). When both kinds are given for the same side, the one that would fill first is used.
Syntax
strategy.exit(series string id, series string from_entry, series float qty, series float profit, series float limit, series float loss, series float stop, series string oca_name, series string comment) → void
Arguments
id required series string from_entry series string qty series float profit series float limit series float loss series float stop series float oca_name series string comment series string Return Type
void Example
//@lipi=2
strategy("strategy.exit Example", overlay=true, initial_capital=10000, default_qty_type=strategy.fixed, default_qty_value=1)
if talib.crossover(close, talib.sma(close, 20)) {
strategy.entry("Long", strategy.long)
}
// Take profit 2% above and stop 1% below the average entry price
if strategy.position_size > 0 {
strategy.exit("Exit Long", from_entry="Long", limit=strategy.position_avg_price * 1.02, stop=strategy.position_avg_price * 0.99)
}