Before we create a strategy, it’s important to know the basic template of a strategy, especially the important parts. Below is a template of a basic strategy
from freqtrade.strategy import IStrategy
from pandas import DataFrame
import talib.abstract as ta
class strat_template (IStrategy):
def version(self) -> str:
return "template-v1"
INTERFACE_VERSION = 3
minimal_roi = {
"0": 0.05
}
stoploss = -0.05
timeframe = '15m'
process_only_new_candles = True
startup_candle_count = 999
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
return dataframe
def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
dataframe['enter_long'] = 0
return dataframe
def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
return dataframe
Short explanations for each lines
- Line 1-3 : lines to import libraries, modules, or classes needed to be used in the strategy
- Line 6-7 : place where you can specify version string of current strategy class. It’s optional.
- Line 11-13 : minimal roi to be used by the strategy. Read here for better explanation
- Line 15 : hard stoploss to be set. Read here for better explanation
- Line 16 : timeframe used by the strategy. Read here for better explanation
- Line 18 : number of past candles needed to calculate indicators. Read here for better explanation
- Line 20 : where you calculate indicators. Read here for more info
- Line 23 : where you check for entry signal. Read here for more info
- Line 27 : where you check for exit signal. Read here for more info
[…] Basic Template of a Strategy […]
[…] Previous – Basic Template of a Strategy […]