on_increased_position(self, order)

The size of the position has been increased with the execution of an order.

This event is fired if your strategy is entering positions in more than one point. For Example:

def go_long(self): = [
        (1, 100), 
        (1, 90), 

Or if you're updating the inside the update_position method to increase the size of the position after it is already open.

def update_position(self):
    # increase position size if the long
    # position is in more than 2% profit
    if self.is_long and self.position.pnl_percentage > 2: = self.position.qty, self.price

on_open_position(self, order)

This function is called right after an open-position order is executed. You may use self.position to access the current position's object.

see also: position

on_reduced_position(self, order)

The position has been reduced (but not closed) with the execution of either a stop-loss or a take-profit order.

Example usage of this would be to move the stop-loss to break even after part of the position has been exited:

def go_long(self): = 2, 100
    # take-profit in two points
    self.take_profit = [
        (1, 120), 
        (1, 140)

def on_reduced_position(self, order):
    self.stop_loss = 1, 100

on_close_position(self, order)

The position has been closed with the execution of either a stop-loss or a take-profit order.

To see if the position was closed because of a take-profit or a stop-loss, you can use the order.is_take_profit or order.is_stop_loss properties:

def on_close_position(self, order):
    if order.is_take_profit:
        self.log("Take-profit closed the position")
    elif order.is_stop_loss:
        self.log("Stop-loss closed the position")


You do not need to worry about canceling the remaining active orders. Jesse takes care of it for you.


This function is called after all active orders have been canceled. An example of usage would be if you are using a custom value that needs to be cleared after each completed trade.