Validating Freqtrade Backtests with a Moving Average Strategy
Summary
This document provides a simple Freqtrade strategy intended to compare backtest behavior across platforms. It calculates 14-period and 28-period simple moving averages on hourly data, marks a long entry whenever the fast average is above the slow average, and signals an exit whenever it is below. The strategy also sets a high stop-loss and staged minimal return-on-investment thresholds, making those execution settings part of the comparison setup.
The script’s stated purpose is validation against a corresponding strategy on another platform using the same asset, period, and resolution. However, the document contains no paired results, comparison procedure, or evidence that the platforms agree. Because entry and exit conditions use the relative averages rather than only crossover events, the conditions may remain active across multiple candles. The code is therefore a reproducible starting point for a cross-platform backtest check, not proof of equivalence or profitability.
Key ideas
- The strategy uses 14-period and 28-period simple moving averages on hourly candles.
- It enters long while the fast average is above the slow average and exits when it is below.
- The script is intended for comparison with a counterpart on another trading platform.
- The document includes no comparison results or evidence of platform equivalence.
- Persistent above/below conditions differ from signals that trigger only at the crossover.
Tags
Full text
# Freqtrade_backtest_validation_freqtrade1
# Freqtrade_backtest_validation_freqtrade1
## Source (GPL-3.0)
```python
# Freqtrade_backtest_validation_freqtrade1.py
# This script is 1 of a pair the other being freqtrade_backtest_validation_tradingview1
# These should be executed on their respective platforms for the same coin/period/resolution
# The purpose is to test Freqtrade backtest provides like results to a known industry platform.
#
# --- Do not remove these libs ---
from freqtrade.strategy import IStrategy
from pandas import DataFrame
# --------------------------------
# Add your lib to import here
import talib.abstract as ta
import freqtrade.vendor.qtpylib.indicators as qtpylib
class Freqtrade_backtest_validation_freqtrade1(IStrategy):
INTERFACE_VERSION: int = 3
# Minimal ROI designed for the strategy.
minimal_roi = {
"40": 2.0,
"30": 2.01,
"20": 2.02,
"0": 2.04
}
stoploss = -0.90
timeframe = '1h'
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
# SMA - Simple Moving Average
dataframe['fastMA'] = ta.SMA(dataframe, timeperiod=14)
dataframe['slowMA'] = ta.SMA(dataframe, timeperiod=28)
return dataframe
def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
dataframe.loc[
(
(dataframe['fastMA'] > dataframe['slowMA'])
),
'enter_long'] = 1
return dataframe
def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
dataframe.loc[
(
(dataframe['fastMA'] < dataframe['slowMA'])
),
'exit_long'] = 1
return dataframe
```Shown in full with attribution under the source's licence. Licence: GPL-3.0
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.