Bot Basics
This page covers the fundamental concepts of how Freqtrade works and operates.
Core Terminology
Trading Concepts
- Strategy: Your trading logic that tells the bot when to buy and sell
- Trade: An open position in the market
- Pair: A tradable cryptocurrency pair (e.g.,
BTC/USDT
,ETH/BTC
) - Timeframe: The candle duration for analysis (e.g.,
5m
,1h
,1d
) - Indicators: Technical analysis tools (RSI, SMA, MACD, etc.)
Order Types
- Limit Order: Executes at a specific price or better
- Market Order: Executes immediately at current market price
- Stop Loss: Automatic exit order to limit losses
- Take Profit: Automatic exit order to secure profits
Profit Calculations
- Current Profit: Unrealized profit/loss for open trades
- Realized Profit: Actual profit/loss from closed trades
- Total Profit: Combined realized and unrealized profit
Pair Naming Conventions
Freqtrade follows the CCXT naming convention:
Spot Trading
- Format:
BASE/QUOTE
- Examples:
BTC/USDT
,ETH/BTC
,ADA/USD
Futures Trading
- Format:
BASE/QUOTE:SETTLE
- Examples:
BTC/USDT:USDT
,ETH/USD:USD
Using incorrect pair naming will result in errors like "pair not available". Always verify the correct format for your exchange and trading mode.
Bot Execution Logic
Live Trading Loop
When running freqtrade trade
, the bot performs these actions every few seconds:
-
Data Collection
- Fetch open trades from database
- Calculate current tradable pairs
- Download OHLCV data for all pairs
- Update informative pairs data
-
Strategy Analysis
- Call
populate_indicators()
for each pair - Call
populate_entry_trend()
to identify buy signals - Call
populate_exit_trend()
to identify sell signals
- Call
-
Order Management
- Update open order status from exchange
- Check for filled orders and call
order_filled()
callback - Handle order timeouts and cancellations
- Adjust order prices if needed
-
Exit Logic
- Check stop loss conditions
- Evaluate ROI (Return on Investment) targets
- Process exit signals from strategy
- Execute custom exit logic
- Place exit orders when conditions are met
-
Entry Logic
- Check for available trading slots
- Evaluate entry signals from strategy
- Calculate position size and leverage
- Confirm trade entry with callbacks
- Place entry orders when conditions are met
-
Position Adjustments
- Check for position adjustment opportunities
- Add to existing positions if enabled
- Manage partial exits
Callback Sequence
The bot calls strategy methods in this order:
# Once per bot start
bot_start()
# Every iteration
bot_loop_start()
# For each pair
populate_indicators(dataframe)
populate_entry_trend(dataframe)
populate_exit_trend(dataframe)
# For order management
check_entry_timeout()
check_exit_timeout()
adjust_order_price()
# For trade confirmation
confirm_trade_entry()
confirm_trade_exit()
# For custom logic
custom_entry_price()
custom_exit_price()
custom_stake_amount()
custom_stoploss()
custom_exit()
Backtesting Logic
Backtesting simulates trading with historical data:
-
Data Preparation
- Load historical OHLCV data
- Calculate all indicators once
- Generate entry/exit signals
-
Simulation Loop
- Process each candle chronologically
- Check for entry signals and simulate trades
- Apply stop losses and take profits
- Handle order timeouts and adjustments
- Calculate profits and statistics
-
Key Differences from Live Trading
- All orders assumed to fill (no slippage simulation)
- Perfect timing (no network delays)
- Historical data only (no real-time updates)
- Simplified fee calculations
Backtesting results may not match live trading due to:
- Order fill assumptions
- Timing differences
- Market impact
- Slippage and fees
- Data quality issues
Fee Handling
Freqtrade includes trading fees in all profit calculations:
- Backtesting/Dry Run: Uses exchange default fees (lowest tier)
- Live Trading: Uses actual fees charged by exchange
- Fee Rebates: Includes exchange-specific rebates (e.g., BNB discounts)
Trading Modes
Dry Run (Paper Trading)
- Simulates trading with fake money
- Uses real-time market data
- No actual orders placed on exchange
- Perfect for testing strategies safely
{
"dry_run": true,
"dry_run_wallet": 1000
}
Live Trading
- Uses real money and places actual orders
- Requires exchange API keys
- All profits and losses are real
- Requires careful risk management
{
"dry_run": false,
"exchange": {
"key": "your_api_key",
"secret": "your_api_secret"
}
}
Risk Management
Position Sizing
Control how much to invest per trade:
{
"stake_amount": 100, // Fixed amount per trade
"max_open_trades": 3, // Maximum concurrent trades
"tradable_balance_ratio": 0.99 // Percentage of balance to use
}
Stop Loss Protection
Limit losses with automatic exits:
{
"stoploss": -0.10, // 10% stop loss
"trailing_stop": true, // Follow price up
"trailing_stop_positive": 0.01 // Start trailing at 1% profit
}
Profit Targets
Secure profits automatically:
{
"minimal_roi": {
"60": 0.01, // 1% profit after 60 minutes
"30": 0.02, // 2% profit after 30 minutes
"0": 0.04 // 4% profit immediately
}
}
Data Management
Timeframes
Choose appropriate candle sizes:
- 1m, 5m: Scalping strategies (high frequency)
- 15m, 30m: Short-term trading
- 1h, 4h: Medium-term strategies
- 1d: Long-term position trading
Indicators
Common technical indicators:
# Trend indicators
dataframe['sma_20'] = ta.SMA(dataframe, timeperiod=20)
dataframe['ema_12'] = ta.EMA(dataframe, timeperiod=12)
# Momentum indicators
dataframe['rsi'] = ta.RSI(dataframe, timeperiod=14)
dataframe['macd'] = ta.MACD(dataframe)['macd']
# Volatility indicators
bollinger = ta.BBANDS(dataframe, timeperiod=20)
dataframe['bb_upper'] = bollinger['upperband']
dataframe['bb_lower'] = bollinger['lowerband']
Performance Optimization
Processing Efficiency
- process_only_new_candles: Only analyze new data
- Pair filtering: Limit number of trading pairs
- Timeframe selection: Balance detail vs. speed
Resource Management
{
"internals": {
"process_throttle_secs": 5, // Loop frequency
"heartbeat_interval": 60 // Status update frequency
}
}
Monitoring and Control
Logging
Freqtrade provides detailed logs:
# View logs in real-time
tail -f user_data/logs/freqtrade.log
# Search for specific events
grep "ENTRY" user_data/logs/freqtrade.log
Control Interfaces
- FreqUI: Web-based interface
- Telegram: Mobile notifications and control
- REST API: Programmatic access
- Command Line: Direct bot commands
Common Patterns
Conservative Trading
{
"max_open_trades": 3,
"stake_amount": 50,
"stoploss": -0.05,
"minimal_roi": {"0": 0.02},
"timeframe": "1h"
}
Aggressive Trading
{
"max_open_trades": 10,
"stake_amount": 100,
"stoploss": -0.15,
"minimal_roi": {"0": 0.10},
"timeframe": "5m"
}
Scalping Setup
{
"max_open_trades": 20,
"stake_amount": 25,
"stoploss": -0.02,
"minimal_roi": {"0": 0.01},
"timeframe": "1m"
}
Best Practices
Strategy Development
- Start Simple: Begin with basic indicators
- Test Thoroughly: Use backtesting and dry runs
- Risk Management: Always include stop losses
- Gradual Scaling: Start small, increase gradually
- Continuous Monitoring: Watch performance closely
Operational Security
- API Permissions: Use trading-only API keys
- IP Restrictions: Whitelist your server IP
- Regular Backups: Save configuration and data
- Update Regularly: Keep Freqtrade updated
- Monitor Logs: Watch for errors and warnings
Next Steps
Now that you understand the basics:
- Configuration - Set up your bot
- Strategy Development - Create trading strategies
- Backtesting - Test your strategies
- Bot Usage - Learn operational commands
Resources
- Discord Community - Get help and share ideas
- GitHub Repository - Source code and issues
- Strategy Examples - Community strategies
- Documentation - Complete documentation