-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsample.py
More file actions
151 lines (129 loc) · 4.7 KB
/
sample.py
File metadata and controls
151 lines (129 loc) · 4.7 KB
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import pandas as pd
import talib.abstract as ta
import technical.vendor.qtpylib.indicators as qtpylib
from indicators.candlestick_patterns import find_candlestick_patterns
from indicators.hawkeye_volume import hawkeye_volume
from indicators.pivot import pivot_high, pivot_low
from ploting.plotting import generate_candlestick_graph, store_plot_file
from utils.logger import logger
from utils.utils import (
dataframe_date_to_date,
load_dataframe,
)
def populate_indicators(dataframe: pd.DataFrame) -> pd.DataFrame:
# RSI
dataframe["rsi"] = ta.RSI(dataframe, timeperiod=14)
# ADX
dataframe["adx"] = ta.ADX(dataframe, timeperiod=14)
# Parabolic SAR
dataframe["sar"] = ta.SAR(dataframe, acceleration=0.02, maximum=0.2)
# Hawkeye Volume
dataframe["durchschnitt"], dataframe["v_color"] = hawkeye_volume(
dataframe=dataframe
)
# Pivot high/low
dataframe["pivot_highs"] = pivot_high(dataframe=dataframe, left=10, right=2)
dataframe["pivot_lows"] = pivot_low(dataframe=dataframe, left=10, right=2)
dataframe["pivot_lows"] = dataframe["pivot_lows"].ffill()
dataframe["pivot_highs"] = dataframe["pivot_highs"].ffill()
# Candlestick pattern
dataframe["bullish_candle"], dataframe["bearish_candle"] = (
find_candlestick_patterns(dataframe=dataframe)
)
# EMA
dataframe["ema34"] = ta.EMA(dataframe, timeperiod=34)
dataframe["ema89"] = ta.EMA(dataframe, timeperiod=89)
dataframe["ema200"] = ta.EMA(dataframe, timeperiod=200)
# Bollinger Bands
bollinger = qtpylib.bollinger_bands(
qtpylib.typical_price(dataframe), window=20, stds=2
)
dataframe["bb_lowerband"] = bollinger["lower"]
dataframe["bb_middleband"] = bollinger["mid"]
dataframe["bb_upperband"] = bollinger["upper"]
dataframe["bb_percent"] = (dataframe["close"] - dataframe["bb_lowerband"]) / (
dataframe["bb_upperband"] - dataframe["bb_lowerband"]
)
dataframe["bb_width"] = (
dataframe["bb_upperband"] - dataframe["bb_lowerband"]
) / dataframe["bb_middleband"]
dataframe.loc[
(
(dataframe["high"] > dataframe["pivot_highs"])
& (dataframe["bearish_candle"] == 1)
& (dataframe["open"] < dataframe["pivot_highs"])
& (dataframe["adx"] > 25)
& (dataframe["rsi"] > 60)
),
"enter_short",
] = 1
dataframe.loc[
(
(dataframe["low"] < dataframe["pivot_lows"])
& (dataframe["bullish_candle"] == 1)
& (dataframe["open"] > dataframe["pivot_lows"])
& (dataframe["adx"] > 25)
& (dataframe["rsi"] <= 40)
),
"enter_long",
] = 1
dataframe.loc[
(
(dataframe["high"] <= dataframe["sar"])
& (dataframe["low"].shift(1) > dataframe["sar"].shift(1))
& (dataframe["volume"] > 0)
),
["exit_long", "exit_tag"],
] = 1, "Exit Long - SAR"
dataframe.loc[
(
(dataframe["low"] >= dataframe["sar"])
& (dataframe["high"].shift(1) < dataframe["sar"].shift(1))
& (dataframe["volume"] > 0)
),
["exit_short", "exit_tag"],
] = 1, "Exit Short - SAR"
return dataframe
if __name__ == "__main__":
logger.info("Trading To The Moon!")
loaded_dataframe = load_dataframe("./data/BTC_USDT_USDT-1h-futures.feather")
dataframe = dataframe_date_to_date(
loaded_dataframe, start_date="20240801", end_date="20240901"
)
dataframe = populate_indicators(dataframe=dataframe)
plot_config = {
"main_plot": {
"sar": {
"plotly": {"mode": "markers", "marker": {"color": "DarkSlateGrey"}}
},
"pivot_highs": {
"plotly": {"mode": "markers", "marker": {"color": "#ff5733"}}
},
"pivot_lows": {
"plotly": {"mode": "markers", "marker": {"color": "#40A677"}}
},
"Bollinger Bands": {
"type": "area",
"indicator_a": "bb_upperband",
"indicator_b": "bb_lowerband",
"fill_color": "rgba(0,176,246,0.2)",
},
"bb_middleband": {"color": "#DCD743"},
},
"subplots": {
"RSI": {"rsi": {"color": "#55CE82"}},
"Hawkeye Volume": {
"volume": {"type": "bar", "colors": "v_color"},
"durchschnitt": {"color": "orange"},
},
},
}
fig = generate_candlestick_graph(
title="BTCUSDT", data=dataframe, plot_config=plot_config
)
store_plot_file(
fig=fig,
filename="BTCUSDT-1H-Candlestick-Graph.html",
directory="./plot",
auto_open=True,
)