forked from PeetCrypto/freqtrade-stuff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CofiBitStrategy.py
70 lines (57 loc) · 2.39 KB
/
CofiBitStrategy.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
# --- Do not remove these libs ---
import freqtrade.vendor.qtpylib.indicators as qtpylib
import talib.abstract as ta
from freqtrade.strategy.interface import IStrategy
from pandas import DataFrame
# --------------------------------
class CofiBitStrategy(IStrategy):
"""
taken from slack by user CofiBit
"""
# Minimal ROI designed for the strategy.
# This attribute will be overridden if the config file contains "minimal_roi"
minimal_roi = {"40": 0.05, "30": 0.06, "20": 0.07, "0": 0.10}
# Optimal stoploss designed for the strategy
# This attribute will be overridden if the config file contains "stoploss"
stoploss = -0.25
# Optimal timeframe for the strategy
timeframe = "5m"
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
stoch_fast = ta.STOCHF(dataframe, 5, 3, 0, 3, 0)
dataframe["fastd"] = stoch_fast["fastd"]
dataframe["fastk"] = stoch_fast["fastk"]
dataframe["ema_high"] = ta.EMA(dataframe, timeperiod=5, price="high")
dataframe["ema_close"] = ta.EMA(dataframe, timeperiod=5, price="close")
dataframe["ema_low"] = ta.EMA(dataframe, timeperiod=5, price="low")
dataframe["adx"] = ta.ADX(dataframe)
return dataframe
def populate_buy_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
"""
Based on TA indicators, populates the buy signal for the given dataframe
:param dataframe: DataFrame
:return: DataFrame with buy column
"""
dataframe.loc[
(
(dataframe["open"] < dataframe["ema_low"])
& (qtpylib.crossed_above(dataframe["fastk"], dataframe["fastd"]))
& (dataframe["fastk"] < 30)
& (dataframe["fastd"] < 30)
& (dataframe["adx"] > 30)
),
"buy",
] = 1
return dataframe
def populate_sell_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
"""
Based on TA indicators, populates the sell signal for the given dataframe
:param dataframe: DataFrame
:return: DataFrame with buy column
"""
dataframe.loc[
((dataframe["open"] >= dataframe["ema_high"]))
| (dataframe["fastk"] > 70)
| (qtpylib.crossed_above(dataframe["fastd"], 70)),
"sell",
] = 1
return dataframe