forked from LeQuangHuyUIT/RL-Bitcoin-trading-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
indicators.py
48 lines (39 loc) · 1.84 KB
/
indicators.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
#================================================================
#
# File name : indicators.py
# Author : PyLessons
# Created date: 2021-01-20
# Website : https://pylessons.com/
# GitHub : https://github.com/pythonlessons/RL-Bitcoin-trading-bot
# Description : Used to plot 5 indicators with OHCL bars
#
#================================================================
import pandas as pd
from ta.trend import SMAIndicator, macd, PSARIndicator
from ta.volatility import BollingerBands
from ta.momentum import rsi
from utils import Plot_OHCL
def AddIndicators(df):
# Add Simple Moving Average (SMA) indicators
df["sma7"] = SMAIndicator(close=df["Close"], window=7, fillna=True).sma_indicator()
df["sma25"] = SMAIndicator(close=df["Close"], window=25, fillna=True).sma_indicator()
df["sma99"] = SMAIndicator(close=df["Close"], window=99, fillna=True).sma_indicator()
# Add Bollinger Bands indicator
indicator_bb = BollingerBands(close=df["Close"], window=20, window_dev=2)
df['bb_bbm'] = indicator_bb.bollinger_mavg()
df['bb_bbh'] = indicator_bb.bollinger_hband()
df['bb_bbl'] = indicator_bb.bollinger_lband()
# Add Parabolic Stop and Reverse (Parabolic SAR) indicator
indicator_psar = PSARIndicator(high=df["High"], low=df["Low"], close=df["Close"], step=0.02, max_step=2, fillna=True)
df['psar'] = indicator_psar.psar()
# Add Moving Average Convergence Divergence (MACD) indicator
df["MACD"] = macd(close=df["Close"], window_slow=26, window_fast=12, fillna=True) # mazas
# Add Relative Strength Index (RSI) indicator
df["RSI"] = rsi(close=df["Close"], window=14, fillna=True) # mazas
return df
if __name__ == "__main__":
df = pd.read_csv('./pricedata.csv')
df = df.sort_values('Date')
df = AddIndicators(df)
test_df = df[-400:]
Plot_OHCL(df)