Place a new short order and return it. For explanation of parameters, see `Order` and its properties. .. caution:: Keep in mind that `self.sell(size=.1)` doesn't close existing `self.buy(size=.1)` trade unless: * the backtest was run wit
(self, *,
size: float = _FULL_EQUITY,
limit: Optional[float] = None,
stop: Optional[float] = None,
sl: Optional[float] = None,
tp: Optional[float] = None,
tag: object = None)
| 237 | return self._broker.new_order(size, limit, stop, sl, tp, tag) |
| 238 | |
| 239 | def sell(self, *, |
| 240 | size: float = _FULL_EQUITY, |
| 241 | limit: Optional[float] = None, |
| 242 | stop: Optional[float] = None, |
| 243 | sl: Optional[float] = None, |
| 244 | tp: Optional[float] = None, |
| 245 | tag: object = None) -> 'Order': |
| 246 | """ |
| 247 | Place a new short order and return it. For explanation of parameters, see `Order` |
| 248 | and its properties. |
| 249 | |
| 250 | .. caution:: |
| 251 | Keep in mind that `self.sell(size=.1)` doesn't close existing `self.buy(size=.1)` |
| 252 | trade unless: |
| 253 | |
| 254 | * the backtest was run with `exclusive_orders=True`, |
| 255 | * the underlying asset price is equal in both cases and |
| 256 | the backtest was run with `spread = commission = 0`. |
| 257 | |
| 258 | Use `Trade.close()` or `Position.close()` to explicitly exit trades. |
| 259 | |
| 260 | See also `Strategy.buy()`. |
| 261 | |
| 262 | .. note:: |
| 263 | If you merely want to close an existing long position, |
| 264 | use `Position.close()` or `Trade.close()`. |
| 265 | """ |
| 266 | assert 0 < size < 1 or round(size) == size >= 1, \ |
| 267 | "size must be a positive fraction of equity, or a positive whole number of units" |
| 268 | return self._broker.new_order(-size, limit, stop, sl, tp, tag) |
| 269 | |
| 270 | @property |
| 271 | def equity(self) -> float: |