💬 Forum

PrivateMACross

🏆 League #123 / 1939

PacktPublishing/Zero-to-Hero-in-Cryptocurrency-Trading/Chapter_08/PrivateMACross.py · ★65 · ⑂23 · first seen 2026-07-16 · repo updated 2023-10-05

Basics mode: spot timeframe: 1d interface version: 3
Settings stoploss: -1.0 has minimal roi process only new candles: false
Indicators SMA talib
9 related strategies ( identical code, similar name)

Each tile is a different kind of check — from an instant code lint to full sandboxed backtests and forward tests on recent data. Not sure what a check actually proves? See the FAQ →

Source

Download Raw
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# --- Do not remove these libs --- 
import numpy as np  # noqa 
import pandas as pd  # noqa 
from pandas import DataFrame 
  
from freqtrade.strategy import (BooleanParameter, CategoricalParameter, DecimalParameter, 
                                IStrategy, IntParameter) 
  
# -------------------------------- 
# Add your lib to import here 
import talib.abstract as ta 
import freqtrade.vendor.qtpylib.indicators as qtpylib 
from functools import reduce 
  
  
class PrivateMACross(IStrategy): 
    INTERFACE_VERSION = 3 
  
    timeframe = '1d' 
    ma_short = 9 
    ma_long = 21 
  
    startup_candle_count: int = ma_long 
    can_short: bool = False 
  
    minimal_roi = { 
        "0": 10.5 
    } 
  
    stoploss = -1.0 
    trailing_stop = False 
  
    process_only_new_candles = False 
  
    use_exit_signal = True 
    exit_profit_only = False 
    ignore_roi_if_entry_signal = False 
  
    order_types = { 
        'entry': 'market', 
        'exit': 'market', 
        'stoploss': 'market', 
        'stoploss_on_exchange': False 
    } 
  
    order_time_in_force = { 
        'entry': 'gtc', 
        'exit': 'gtc' 
    } 
  
    plot_config = { 
        'main_plot': { 
            f'sma_short_9': {'color': 'red'}, 
            f'sma_long_21': {'color': 'yellow'} 
        } 
    } 
  
    def informative_pairs(self): 
        return [] 
  
    def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame: 
        dataframe['sma_short_9'] = ta.SMA(dataframe, timeperiod=self.ma_short) 
        dataframe['sma_long_21'] = ta.SMA(dataframe, timeperiod=self.ma_long) 
        return dataframe 
  
    def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame: 
        conditions_long = [] 
        conditions_long.append(qtpylib.crossed_above( 
            dataframe[f'sma_short_9'].shift(1), 
            dataframe[f'sma_long_21'].shift(1) 
            )) 
  
        if conditions_long: 
            dataframe.loc[ 
                    reduce(lambda x, y: x & y, conditions_long), 
                    'enter_long'] = 1 
  
        return dataframe 
  
    def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame: 
        conditions_exit_long = [] 
        conditions_exit_long.append(qtpylib.crossed_above( 
            dataframe[f'sma_long_21'], 
            dataframe[f'sma_short_9'] 
            )) 
  
        if conditions_exit_long: 
            dataframe.loc[ 
                    reduce(lambda x, y: x & y, conditions_exit_long), 
                    'exit_long'] = 1 
  
        return dataframe