Martingale Mode & Martingale-Only Strategy
This page explains how the Martingale mode works in our aggregator-based trading bot, including the newly introduced Martingale-Only strategy. Both modes let you average down on a position when the market price falls, but Martingale-Only disables other indicators so it can open its initial position purely by price thresholds, rather than RSI/ML signals.
1. Overview
What is Martingale?
- Martingale is a strategy in which you buy additional tokens at lower prices to reduce your average cost basis.
- Each time the market price drops a certain percentage below your current average price, you buy more tokens (often at a larger size than the previous buy).
- The goal is to accelerate your position’s breakeven point so you can exit at a profit sooner — assuming the price eventually recovers.
Martingale vs. Other Indicators
- The bot processes each symbol independently in a loop.
- If martingale_mode is enabled for a particular symbol, the bot checks if the current price is below a step percent threshold from your average entry. If yes, it rebuy for that position.
- If you have an indicator (like RSI or ML) enabled and martingale_mode is
true
, the bot can open initial entries via the indicator, but subsequent rebuys can also come from the martingale logic. - Martingale-Only means the bot does not rely on RSI, ML, or any other indicator to open the first position. Instead, it automatically enters an initial buy (like a time-based or standard minimum buy) and then continues rebuys purely on the martingale criteria.
2. Configuration Fields
Below are the relevant fields in the user config (SymbolConfig
) that control martingale behavior:
- martingale_mode: A boolean; if
true
, the symbol can perform additional rebuys when the price falls below a given threshold from the average cost basis. - martingale_only: A boolean; if
true
, that symbol runs purely on Martingale logic for all entries (initial + rebuys), ignoring RSI, ML, STOCH, etc. - Internally, if you select "MARTINGALE_ONLY" from the indicator dropdown, the code sets
martingale_only=true
and also flipsmartingale_mode=true
. - martingale_step_percent (
stepPct
): The percentage drop from your average price at which the bot triggers an additional buy. - Example: If set to
5
, the bot attempts to rebuy each time the live price is at least 5% below your cost basis. - martingale_scale_factor (
scaleFactor
): Each new buy can be multiplied by this factor to accelerate your position size. - Example: If your normal buy is 1 token, and
scale_factor=2
, each subsequent buy is doubled (1, 2, 4, 8, …). - martingale_max_buys (
maxBuys
): The maximum number of times the bot will keep adding onto a losing position. - martingale_max_base_amount (
maxBaseFloat
): The maximum total base token usage for this position’s martingale. This ensures you don’t exceed a specified capital limit.
3. How It Works Step-by-Step
When the bot sees martingale_mode = true for a given symbol:
- Initial Position
- If martingale_only is NOT enabled, the first buy typically comes from time-based or from an indicator signal (like RSI, ML, etc.).
-
If martingale_only is enabled, the bot automatically opens an initial buy on that symbol (like a minimal trade size) without needing an RSI/ML signal.
-
Check Price
- In each loop, the bot compares the aggregator’s live price for your symbol with your current average buy price (the “cost basis”).
- It calculates a threshold:
costBasis * (1 - (martingale_step_percent / 100))
. -
If the live price is below or equal to that threshold, the bot tries a rebuy.
-
Scaling
- The new buy size can be scaled up by
martingale_scale_factor
. For example, if your normal buy is 1 SUI in the first buy, the second might be 2 SUI, the third 4 SUI, etc. -
This scale factor is multiplied after each rebuy, up to your chosen limit.
-
Max Buys & Max Base
- If your
martingale_max_buys
is 5, you cannot do more than 5 rebuys on this position. -
martingale_max_base_amount
ensures you never exceed a certain total base usage. If you hit that cap, no further rebuys happen. -
Profit Target
- Once you have a position, the bot uses your configured profit margin (e.g.
profit_margin_percent=5
) to set an exit price. When the aggregator feed price for that symbol is above that goal price, the bot attempts to sell.
4. Example Usage
Below is a sample snippet of a symbol config in your JSON or user interface:
{
"symbol": "SUI",
"targetSymbol": "PUMPKIN",
"min_buy_amount": "1",
"max_buy_amount": "2",
"profit_margin_percent": "10",
"buy_interval_minutes": "15",
"time_enabled": false,
"rsi_enabled": false,
"ml_enabled": false,
"stoch_enabled": false,
"mfi_rsi_enabled": false,
"indicator": "MARTINGALE_ONLY",
"martingale_only": true,
"martingale_mode": true,
"martingale_step_percent": "5",
"martingale_scale_factor": "2",
"martingale_max_buys": "5",
"martingale_max_base_amount": "10"
}