FSD – Basic Template of a Strategy

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

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:
        return dataframe

    def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
        return dataframe

Short explanations for each lines

  • Line 1-2 : 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 17 : timeframe used by the strategy. Read here for better explanation
  • Line 20 : number of past candles needed to calculate indicators. Read here for better explanation
  • Line 22 : where you calculate indicators. Read here for more info
  • Line 25 : where you check for entry signal. Read here for more info
  • Line 28 : where you check for exit signal. Read here for more info

2 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *