import pandas as pd
import datetime
import ta
import plotly.graph_objects as go
from plotly.subplots import make_subplots
data = pd.read_csv('EURUSD_Data.csv')
new_datetime = []
for i in data['time'] :
one_date = i.split()[0]
one_time = i.split()[1]
one_date_split = one_date.split('/')
one_time_split = one_time.split(':')
new_datetime.append(datetime.datetime(year=int('20'+one_date_split[2]), month=int(one_date_split[0]), day=int(one_date_split[1]),
hour=int(one_time_split[0]), minute=int(one_time_split[1])))
data['DateTime'] = new_datetime
data = data.drop('time', axis=1).set_index('DateTime')
data['bb_h'] = ta.volatility.BollingerBands(close=data['close'], window=30, window_dev=2).bollinger_hband()
data['bb_l'] = ta.volatility.BollingerBands(close=data['close'], window=30, window_dev=2).bollinger_lband()
data['bb_m'] = ta.volatility.BollingerBands(close=data['close'], window=30, window_dev=2).bollinger_mavg()
data['rsi'] = ta.momentum.RSIIndicator(close=data['close'], window=13).rsi()
fig = make_subplots(rows=2, cols=1, shared_xaxes=True, vertical_spacing=0.07, subplot_titles=('Chart', 'RSI'), row_width=[0.2, 0.7])
fig.add_trace(go.Candlestick(x=data.index.strftime("%d-%m-%Y %H:%M"), open=data["open"], high=data["high"],low=data["low"],
close=data["close"], name='OHLC'), row=1, col=1)
fig.add_trace(go.Scatter(x=data.index.strftime("%d-%m-%Y %H:%M"), y=data['bb_h'], line=dict(color='black', width=0.4), name='BB_High'), row=1, col=1)
fig.add_trace(go.Scatter(x=data.index.strftime("%d-%m-%Y %H:%M"), y=data['bb_l'], line=dict(color='black', width=0.4), name='BB_Low'), row=1, col=1)
fig.add_trace(go.Scatter(x=data.index.strftime("%d-%m-%Y %H:%M"), y=data['bb_m'], line=dict(color='blue', width=0.6), name='BB_Moving'), row=1, col=1)
fig.add_trace(go.Scatter(x=data.index.strftime("%d-%m-%Y %H:%M"), y=data['rsi'], line=dict(color='royalblue', width=1), name='RSI'), row=2, col=1)
fig.add_hline(y=25, row=2, col=1, line=dict(color='firebrick', width=0.8))
fig.add_hline(y=75, row=2, col=1, line=dict(color='firebrick', width=0.8))
fig.update(layout_xaxis_rangeslider_visible=False)
fig.show()