πProfit Machine! Three Steps to Master Freqtrade Core Buy/Sell Signals β A Step-by-Step Guide to Writ
This article was produced by the Quantitative Trading Lab at https://www.itrade.icu. Visit for more benefits. In the Freqtrade strategy framework,
populate_indicators,populate_entry_trend, andpopulate_exit_trendare the three most basic and commonly used functions. They are responsible for:
βοΈ Calculating technical indicators (e.g., RSI, MACD, moving averages)
π Determining buy signals
π Determining sell signals
This article will explain the purpose, usage, code examples, and tips for these three functions, helping you build your own quantitative trading strategy from scratch.
1οΈβ£ populate_indicators: Core Function for Calculating Technical Indicators
populate_indicators: Core Function for Calculating Technical Indicatorsβ
Purpose
This function calculates and fills technical indicators in the DataFrame, which are used for subsequent buy/sell signal decisions.
It takes historical OHLCV data as input and returns a DataFrame with additional indicator columns, such as RSI, MACD, SMA, EMA, etc.
π§ Backtesting vs Live Trading
Backtesting:
populate_indicatorsis called once for the entire historical dataset.Live Trading: Called every time a new candle is generated (e.g., every minute or hour).
In live trading, you can add real-time processing here; in backtesting, you may iterate over rows with for row in dataframe.iterrows().
π‘ Example Code
2οΈβ£ populate_entry_trend: Buy Signal Logic
populate_entry_trend: Buy Signal Logicβ
Purpose
populate_entry_trend defines when to enter a trade. It generates a buy column in the DataFrame:
buy = 1means this candle is a buy signalbuy = 0(default) means no action
Freqtrade will execute a trade with a market or limit order when the condition is met.
π Usage
You can use .loc to filter the DataFrame and set buy signals:
π‘ Example Code
π Tips
Combine multiple conditions using
(cond1) & (cond2).Incorporate Bollinger Bands, moving averages, or other indicators to refine entries.
3οΈβ£ populate_exit_trend: Sell Signal Logic
populate_exit_trend: Sell Signal Logicβ
Purpose
populate_exit_trend defines when to exit a trade. It works similarly to populate_entry_trend, but sets the sell column:
sell = 1triggers a sellsell = 0means no action
Freqtrade will sell when sell=1.
π‘ Example Code
π§ Tips
Add volume or price pattern logic to improve exit accuracy.
Combine with ROI or trailing stop to create a complete exit mechanism.
π§© Example Strategy: Minimal RSI Strategy
A complete strategy class combining the three functions. Logic:
Buy when RSI < 30 (oversold)
Sell when RSI > 70 (overbought)
π§Ύ Summary
populate_indicators
Calculate indicators
DataFrame with new indicators
populate_entry_trend
Set buy signals
DataFrame with buy=1
populate_exit_trend
Set sell signals
DataFrame with sell=1
These three functions are the core βtrioβ of a strategy. You can further optimize and combine them to build your own trading system.
Next article will cover custom_exit vs custom_exit_price and how to use them together. Stay tuned!
Last updated