-
Notifications
You must be signed in to change notification settings - Fork 0
/
SEMA.py
92 lines (71 loc) · 3.37 KB
/
SEMA.py
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
from pandas import DataFrame
from functools import reduce
import talib.abstract as ta
from freqtrade.strategy import (BooleanParameter, CategoricalParameter, DecimalParameter,
IStrategy, IntParameter)
import freqtrade.vendor.qtpylib.indicators as qtpylib
class SEMA_Opted(IStrategy):
timeframe = '5m'
# ROI table:
minimal_roi = {
"0": 0.067,
"8": 0.034,
"20": 0.015,
"43": 0
}
# Stoploss:
stoploss = -0.346
# Trailing stop:
trailing_stop = True
trailing_stop_positive = 0.045
trailing_stop_positive_offset = 0.113
trailing_only_offset_is_reached = True
# Number of candles the strategy requires before producing valid signals
startup_candle_count: int = 30
# Buy parameter spaces
buy_ema_short = IntParameter(3, 50, default=10)
buy_ema_long = IntParameter(15, 200, default=175)
buy_sma_short = IntParameter(3, 75, default=50)
buy_sma_long = IntParameter(50, 200, default=200)
sell_ema_short = IntParameter(3, 50, default=10)
sell_ema_long = IntParameter(15, 200, default=175)
sell_sma_short = IntParameter(3, 75, default=50)
sell_sma_long = IntParameter(50, 200, default=200)
use_sell_signal = False
sell_profit_only = False
ignore_roi_if_buy_signal = False
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
"""Generate all indicators used by the strategy"""
# Calculate all ema_short values
for val in self.buy_ema_short.range:
dataframe[f'ema_short_{val}'] = ta.EMA(dataframe, timeperiod=val)
for val in self.buy_sma_short.range:
dataframe[f'sma_short_{val}'] = ta.SMA(dataframe, timeperiod=val)
# Calculate all ema_long values
for val in self.buy_ema_long.range:
dataframe[f'ema_long_{val}'] = ta.EMA(dataframe, timeperiod=val)
for val in self.buy_sma_long.range:
dataframe[f'sma_long_{val}'] = ta.SMA(dataframe, timeperiod=val)
return dataframe
def populate_buy_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
conditions = []
conditions.append(dataframe[f'ema_long_{self.buy_ema_long.value}']> dataframe['close'])
conditions.append(dataframe[f'ema_short_{self.buy_ema_short.value}'] > dataframe[f'sma_short_{self.buy_sma_short.value}'])
conditions.append(dataframe[f'sma_short_{self.buy_sma_short.value}'] > dataframe[f'sma_long_{self.buy_sma_long.value}'])
conditions.append(dataframe['volume'] > 0)
if conditions:
dataframe.loc[
reduce(lambda x, y: x & y, conditions),
'buy'] = 1
return dataframe
def populate_sell_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
conditions = []
conditions.append(dataframe[f'ema_long_{self.buy_ema_long.value}'] < dataframe['close'])
conditions.append(dataframe[f'ema_short_{self.buy_ema_short.value}'] < dataframe[f'sma_short_{self.buy_sma_short.value}'])
conditions.append(dataframe[f'sma_short_{self.buy_sma_short.value}'] < dataframe[f'sma_long_{self.buy_sma_long.value}'])
conditions.append(dataframe['volume'] > 0)
if conditions:
dataframe.loc[
reduce(lambda x, y: x & y, conditions),
'sell'] = 1
return dataframe