FRENESDE

Placing orders: buy() / sell()

self.buy() sends a buy order to the broker, self.sell() a sell order. By default these are market orders, executed at the open of the next bar.
self.close() sends the opposite order to the open position, with the same size: it is the safest way to exit a position.
A sell() with no position opens a short sale: you gain if the price falls and lose if it rises, with no theoretical limit.
These methods return the order they create: self.order = self.buy() lets you know an order is pending and avoid sending a second one.

Examples

Key terms

buy()
Sends a buy order
sell()
Sends a sell order
close()
Closes the open position
Short sale
Selling an asset you do not own to profit from a fall
Take the mission on Doji Academy

← Back to the index