-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmt5_lib.py
More file actions
35 lines (28 loc) · 1021 Bytes
/
Copy pathmt5_lib.py
File metadata and controls
35 lines (28 loc) · 1021 Bytes
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
import MetaTrader5 as mt5
import pandas as pd
import pandas_ta as ta
from utils import set_period
def run_server(username, password, server, path):
first_connection = mt5.initialize(
path=path,
login=username,
password=password,
server=server
)
second_connection = mt5.login(
login=username,
password=password,
server=server
)
return first_connection, second_connection
def retreive_data(symbol="GBPUSD", timeframe="M5"):
time_frame = set_period(timeframe)
candles = mt5.copy_rates_from_pos(symbol, time_frame, 1, 1000)[["time", "open", "high", "low", "close"]]
df = pd.DataFrame(candles)
df['time'] = pd.to_datetime(df['time'], unit='s')
ichimoku = ta.ichimoku(df['high'], df['low'], df['close'])
df = pd.concat([df, ichimoku[0]], axis=1)
df['ema_21'] = ta.ema(df['close'], length=21)
df['ema_50'] = ta.ema(df['close'], length=50)
df['ema_100'] = ta.ema(df['close'], length=100)
return df