Docs   »   Studio   »   How to use a bot sizer
published-date Published: June 5, 2025
update-date Last Update: September 11, 2025

How to use a bot sizer

This guide explains how to use predefined sizers or create your own in Backtrader.

What is a sizer?

Sizer is a useful tool to standardize the lot_size logic across your entire strategy.

  • There is no need to define lot_size in each self.buyor self.sell action.
  • Choose one of the default sizers or define your own at the beginning of your strategy.
  • Backtrader will do the rest.

There are multiple bot sizers you can use:

  • FixedLotSizer
  • FixedCashSizer
  • AssignedMarginPercentSizer
  • CustomSizer

You can activate a sizer by specifying the sizer and the sizer_specific_value in the params section of your Backtrader strategy.

1. FixedLotSizer

Defines a fixed lot size.

The following strategy will set sizer_lots to 0.27.The same size will be used for every trade if not otherwise specified.

Example:

import backtrader as bt
class SimpleStrategy(bt.Strategy):
      params = {
             “sizer”: “FixedLotSizer”,
             “sizer_lots”: 0.27,
      }
      def next(self):
             self.buy()

2. FixedCashSizer

Uses a fixed cash amount (in account currency) per trade.

  • Example: If your account is in USD, the following strategy will calculate how much lot_size is equal to $100. This calculation is repeated for each trade action.

  • If your account is in BTC, each lot_size is equal to the value of BTC 100.

Example:

import backtrader as bt
class SimpleStrategy(bt.Strategy):
      params = {
             “sizer”: “FixedCashSizer”,
             “sizer_cash”: 100,
      }
      def next(self):
             self.buy()

3. AssignedMarginPercentSizer

Calculates lot size as a percentage of the margin assigned to the bot.

  • The following strategy will calculate lot_size as 2% of the margin assigned to the bot.

  • The calculation is done only once at the first trade action.

  • All the later actions will use the lot_size calculation from the first action.

Example:

import backtrader as bt
class SimpleBot(bt.Strategy):
      params = {
             “sizer”: “AssignedMarginPercentSizer”,
             “sizer_assigned_margin_percent”: 2,
      }
      def next(self):
             self.buy()

4. CustomSizer

Create your own sizer with custom logic.

The following strategy will open a position with a lot size of 0.2 on each self.buy or self.sell action, because we used sizer_value 0.1 , and multiplier of 2 in the custom sizer.

Example:

import backtrader as bt
class CustomSizer(bt.Sizer):
      def _getsizing(self, comminfo, cash, data, isbuy):
           return self.strategy.p.sizer_value * 2
class SimpleStrategy(bt.Strategy):
      params = {
“sizer”: “CustomSizer”,
“sizer_value”: 0.1,
      }
      def next(self):
             self.buy()

Note: Supported on TradeLocker Desktop version ≥ 2.36.

You can download the TradeLocker Desktop app here and experiment with different sizers to match your strategy needs.

Bold moves. Bend reality.

Author
Kristina Zovak

Social and Content Manager