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 eachself.buy
orself.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:
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 ofBTC 100
.
Example:
3. AssignedMarginPercentSizer
Calculates lot size as a percentage of the margin assigned to the bot.
-
The following strategy will calculate
lot_size
as2%
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:
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:
Note: Supported on TradeLocker Desktop version ≥ 2.36.