Functions
strategy.close()
Closes the position opened by the entry named `id` with a market order. `qty` closes only part of it; `comment` labels the closing order.
Syntax
strategy.close(series string id, series float qty, series string comment) → void
Arguments
id required series string qty series float comment series string Return Type
void Example
//@lipi=2
strategy("strategy.close 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)
}
// Close after the position has been open for 10 bars
if strategy.opentrades > 0 and bar_index - strategy.opentrades_entry_bar_index(0) >= 10 {
strategy.close("Long", comment="Time exit")
}