-
Notifications
You must be signed in to change notification settings - Fork 82
/
BinHV27.py
135 lines (126 loc) · 5.71 KB
/
BinHV27.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
from freqtrade.strategy.interface import IStrategy
from typing import Dict, List
from functools import reduce
from pandas import DataFrame
# --------------------------------
import talib.abstract as ta
import freqtrade.vendor.qtpylib.indicators as qtpylib
from typing import Dict, List
from functools import reduce
from pandas import DataFrame, DatetimeIndex, merge
# --------------------------------
import talib.abstract as ta
import freqtrade.vendor.qtpylib.indicators as qtpylib
import numpy # noqa
class BinHV27(IStrategy):
"""
strategy sponsored by user BinH from slack
"""
minimal_roi = {
"0": 1
}
stoploss = -0.50
timeframe = '5m'
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
dataframe['rsi'] = numpy.nan_to_num(ta.RSI(dataframe, timeperiod=5))
rsiframe = DataFrame(dataframe['rsi']).rename(columns={'rsi': 'close'})
dataframe['emarsi'] = numpy.nan_to_num(ta.EMA(rsiframe, timeperiod=5))
dataframe['adx'] = numpy.nan_to_num(ta.ADX(dataframe))
dataframe['minusdi'] = numpy.nan_to_num(ta.MINUS_DI(dataframe))
minusdiframe = DataFrame(dataframe['minusdi']).rename(columns={'minusdi': 'close'})
dataframe['minusdiema'] = numpy.nan_to_num(ta.EMA(minusdiframe, timeperiod=25))
dataframe['plusdi'] = numpy.nan_to_num(ta.PLUS_DI(dataframe))
plusdiframe = DataFrame(dataframe['plusdi']).rename(columns={'plusdi': 'close'})
dataframe['plusdiema'] = numpy.nan_to_num(ta.EMA(plusdiframe, timeperiod=5))
dataframe['lowsma'] = numpy.nan_to_num(ta.EMA(dataframe, timeperiod=60))
dataframe['highsma'] = numpy.nan_to_num(ta.EMA(dataframe, timeperiod=120))
dataframe['fastsma'] = numpy.nan_to_num(ta.SMA(dataframe, timeperiod=120))
dataframe['slowsma'] = numpy.nan_to_num(ta.SMA(dataframe, timeperiod=240))
dataframe['bigup'] = dataframe['fastsma'].gt(dataframe['slowsma']) & ((dataframe['fastsma'] - dataframe['slowsma']) > dataframe['close'] / 300)
dataframe['bigdown'] = ~dataframe['bigup']
dataframe['trend'] = dataframe['fastsma'] - dataframe['slowsma']
dataframe['preparechangetrend'] = dataframe['trend'].gt(dataframe['trend'].shift())
dataframe['preparechangetrendconfirm'] = dataframe['preparechangetrend'] & dataframe['trend'].shift().gt(dataframe['trend'].shift(2))
dataframe['continueup'] = dataframe['slowsma'].gt(dataframe['slowsma'].shift()) & dataframe['slowsma'].shift().gt(dataframe['slowsma'].shift(2))
dataframe['delta'] = dataframe['fastsma'] - dataframe['fastsma'].shift()
dataframe['slowingdown'] = dataframe['delta'].lt(dataframe['delta'].shift())
return dataframe
def populate_buy_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
dataframe.loc[
dataframe['slowsma'].gt(0) &
dataframe['close'].lt(dataframe['highsma']) &
dataframe['close'].lt(dataframe['lowsma']) &
dataframe['minusdi'].gt(dataframe['minusdiema']) &
dataframe['rsi'].ge(dataframe['rsi'].shift()) &
(
(
~dataframe['preparechangetrend'] &
~dataframe['continueup'] &
dataframe['adx'].gt(25) &
dataframe['bigdown'] &
dataframe['emarsi'].le(20)
) |
(
~dataframe['preparechangetrend'] &
dataframe['continueup'] &
dataframe['adx'].gt(30) &
dataframe['bigdown'] &
dataframe['emarsi'].le(20)
) |
(
~dataframe['continueup'] &
dataframe['adx'].gt(35) &
dataframe['bigup'] &
dataframe['emarsi'].le(20)
) |
(
dataframe['continueup'] &
dataframe['adx'].gt(30) &
dataframe['bigup'] &
dataframe['emarsi'].le(25)
)
),
'buy'] = 1
return dataframe
def populate_sell_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
dataframe.loc[
(
(
~dataframe['preparechangetrendconfirm'] &
~dataframe['continueup'] &
(dataframe['close'].gt(dataframe['lowsma']) | dataframe['close'].gt(dataframe['highsma'])) &
dataframe['highsma'].gt(0) &
dataframe['bigdown']
) |
(
~dataframe['preparechangetrendconfirm'] &
~dataframe['continueup'] &
dataframe['close'].gt(dataframe['highsma']) &
dataframe['highsma'].gt(0) &
(dataframe['emarsi'].ge(75) | dataframe['close'].gt(dataframe['slowsma'])) &
dataframe['bigdown']
) |
(
~dataframe['preparechangetrendconfirm'] &
dataframe['close'].gt(dataframe['highsma']) &
dataframe['highsma'].gt(0) &
dataframe['adx'].gt(30) &
dataframe['emarsi'].ge(80) &
dataframe['bigup']
) |
(
dataframe['preparechangetrendconfirm'] &
~dataframe['continueup'] &
dataframe['slowingdown'] &
dataframe['emarsi'].ge(75) &
dataframe['slowsma'].gt(0)
) |
(
dataframe['preparechangetrendconfirm'] &
dataframe['minusdi'].lt(dataframe['plusdi']) &
dataframe['close'].gt(dataframe['lowsma']) &
dataframe['slowsma'].gt(0)
)
),
'sell'] = 1
return dataframe