-
Notifications
You must be signed in to change notification settings - Fork 1
/
bars.py
212 lines (202 loc) · 8.63 KB
/
bars.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
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
import MetaTrader5 as mt5
import pandas as pd
import time
from datetime import datetime
import pytz
high_TIMEFRAME=[mt5.TIMEFRAME_M15,mt5.TIMEFRAME_M30,mt5.TIMEFRAME_H1,mt5.TIMEFRAME_H4]
NUM_BARZ=int(200)
TIMEFRAME=mt5.TIMEFRAME_H4
START_POS=int(0)
SYMBOL="XAUUSD"
v=int(1)
counterHigh={"XAUUSD":{15:int(0),30:int(0),16385:int(0),16388:int(0)}
,"EURUSD":{15:int(0),30:int(0),16385:int(0),16388:int(0)}
,"USDCAD":{15:int(0),30:int(0),16385:int(0),16388:int(0)}
,"USDJPY":{15:int(0),30:int(0),16385:int(0),16388:int(0)}
,"AUDCAD":{15:int(0),30:int(0),16385:int(0),16388:int(0)}}
xau_DictHigh={1:{15:[],30:[],16385:[],16388:[]},
2:{15:[],30:[],16385:[],16388:[]},
3:{15:[],30:[],16385:[],16388:[]},
4:{15:[],30:[],16385:[],16388:[]},
5:{15:[],30:[],16385:[],16388:[]},
6:{15:[],30:[],16385:[],16388:[]},
7:{15:[],30:[],16385:[],16388:[]},
8:{15:[],30:[],16385:[],16388:[]},
9:{15:[],30:[],16385:[],16388:[]},
10:{15:[],30:[],16385:[],16388:[]},
11:{15:[],30:[],16385:[],16388:[]},
12:{15:[],30:[],16385:[],16388:[]}}
eur_DictHigh={1:{15:[],30:[],16385:[],16388:[]},
2:{15:[],30:[],16385:[],16388:[]},
3:{15:[],30:[],16385:[],16388:[]},
4:{15:[],30:[],16385:[],16388:[]},
5:{15:[],30:[],16385:[],16388:[]},
6:{15:[],30:[],16385:[],16388:[]},
7:{15:[],30:[],16385:[],16388:[]},
8:{15:[],30:[],16385:[],16388:[]},
9:{15:[],30:[],16385:[],16388:[]},
10:{15:[],30:[],16385:[],16388:[]},
11:{15:[],30:[],16385:[],16388:[]},
12:{15:[],30:[],16385:[],16388:[]}}
jpy_DictHigh={1:{15:[],30:[],16385:[],16388:[]},
2:{15:[],30:[],16385:[],16388:[]},
3:{15:[],30:[],16385:[],16388:[]},
4:{15:[],30:[],16385:[],16388:[]},
5:{15:[],30:[],16385:[],16388:[]},
6:{15:[],30:[],16385:[],16388:[]},
7:{15:[],30:[],16385:[],16388:[]},
8:{15:[],30:[],16385:[],16388:[]},
9:{15:[],30:[],16385:[],16388:[]},
10:{15:[],30:[],16385:[],16388:[]},
11:{15:[],30:[],16385:[],16388:[]},
12:{15:[],30:[],16385:[],16388:[]}}
cad_DictHigh={1:{15:[],30:[],16385:[],16388:[]},
2:{15:[],30:[],16385:[],16388:[]},
3:{15:[],30:[],16385:[],16388:[]},
4:{15:[],30:[],16385:[],16388:[]},
5:{15:[],30:[],16385:[],16388:[]},
6:{15:[],30:[],16385:[],16388:[]},
7:{15:[],30:[],16385:[],16388:[]},
8:{15:[],30:[],16385:[],16388:[]},
9:{15:[],30:[],16385:[],16388:[]},
10:{15:[],30:[],16385:[],16388:[]},
11:{15:[],30:[],16385:[],16388:[]},
12:{15:[],30:[],16385:[],16388:[]}}
aud_DictHigh={1:{15:[],30:[],16385:[],16388:[]},
2:{15:[],30:[],16385:[],16388:[]},
3:{15:[],30:[],16385:[],16388:[]},
4:{15:[],30:[],16385:[],16388:[]},
5:{15:[],30:[],16385:[],16388:[]},
6:{15:[],30:[],16385:[],16388:[]},
7:{15:[],30:[],16385:[],16388:[]},
8:{15:[],30:[],16385:[],16388:[]},
9:{15:[],30:[],16385:[],16388:[]},
10:{15:[],30:[],16385:[],16388:[]},
11:{15:[],30:[],16385:[],16388:[]},
12:{15:[],30:[],16385:[],16388:[]}}
# LOW PRICE DICTIONARY
# counterHigh value dictionary
counterLow={"XAUUSD":{15:int(0),30:int(0),16385:int(0),16388:int(0)}
,"EURUSD":{15:int(0),30:int(0),16385:int(0),16388:int(0)}
,"USDCAD":{15:int(0),30:int(0),16385:int(0),16388:int(0)}
,"USDJPY":{15:int(0),30:int(0),16385:int(0),16388:int(0)}
,"AUDCAD":{15:int(0),30:int(0),16385:int(0),16388:int(0)}}
xau_DictLow={1:{15:[],30:[],16385:[],16388:[]},
2:{15:[],30:[],16385:[],16388:[]},
3:{15:[],30:[],16385:[],16388:[]},
4:{15:[],30:[],16385:[],16388:[]},
5:{15:[],30:[],16385:[],16388:[]},
6:{15:[],30:[],16385:[],16388:[]},
7:{15:[],30:[],16385:[],16388:[]},
8:{15:[],30:[],16385:[],16388:[]},
9:{15:[],30:[],16385:[],16388:[]},
10:{15:[],30:[],16385:[],16388:[]},
11:{15:[],30:[],16385:[],16388:[]},
12:{15:[],30:[],16385:[],16388:[]}}
eur_DictLow={1:{15:[],30:[],16385:[],16388:[]},
2:{15:[],30:[],16385:[],16388:[]},
3:{15:[],30:[],16385:[],16388:[]},
4:{15:[],30:[],16385:[],16388:[]},
5:{15:[],30:[],16385:[],16388:[]},
6:{15:[],30:[],16385:[],16388:[]},
7:{15:[],30:[],16385:[],16388:[]},
8:{15:[],30:[],16385:[],16388:[]},
9:{15:[],30:[],16385:[],16388:[]},
10:{15:[],30:[],16385:[],16388:[]},
11:{15:[],30:[],16385:[],16388:[]},
12:{15:[],30:[],16385:[],16388:[]}}
jpy_DictLow={1:{15:[],30:[],16385:[],16388:[]},
2:{15:[],30:[],16385:[],16388:[]},
3:{15:[],30:[],16385:[],16388:[]},
4:{15:[],30:[],16385:[],16388:[]},
5:{15:[],30:[],16385:[],16388:[]},
6:{15:[],30:[],16385:[],16388:[]},
7:{15:[],30:[],16385:[],16388:[]},
8:{15:[],30:[],16385:[],16388:[]},
9:{15:[],30:[],16385:[],16388:[]},
10:{15:[],30:[],16385:[],16388:[]},
11:{15:[],30:[],16385:[],16388:[]},
12:{15:[],30:[],16385:[],16388:[]}}
cad_DictLow={1:{15:[],30:[],16385:[],16388:[]},
2:{15:[],30:[],16385:[],16388:[]},
3:{15:[],30:[],16385:[],16388:[]},
4:{15:[],30:[],16385:[],16388:[]},
5:{15:[],30:[],16385:[],16388:[]},
6:{15:[],30:[],16385:[],16388:[]},
7:{15:[],30:[],16385:[],16388:[]},
8:{15:[],30:[],16385:[],16388:[]},
9:{15:[],30:[],16385:[],16388:[]},
10:{15:[],30:[],16385:[],16388:[]},
11:{15:[],30:[],16385:[],16388:[]},
12:{15:[],30:[],16385:[],16388:[]}}
aud_DictLow={1:{15:[],30:[],16385:[],16388:[]},
2:{15:[],30:[],16385:[],16388:[]},
3:{15:[],30:[],16385:[],16388:[]},
4:{15:[],30:[],16385:[],16388:[]},
5:{15:[],30:[],16385:[],16388:[]},
6:{15:[],30:[],16385:[],16388:[]},
7:{15:[],30:[],16385:[],16388:[]},
8:{15:[],30:[],16385:[],16388:[]},
9:{15:[],30:[],16385:[],16388:[]},
10:{15:[],30:[],16385:[],16388:[]},
11:{15:[],30:[],16385:[],16388:[]},
12:{15:[],30:[],16385:[],16388:[]}}
def conn():
# intialise mt5
if not mt5.initialize():
print(f"The Initialisation error is {mt5.last_error()}")
# login credentials
account=int(810414810)
password="Marichu12"
server="EGMSecurities-Live"
# login scredentials
log=mt5.login(account,password,server)
if not log:
print(f"The login error was {mt5.last_error()}")
def startTest(from_date,to_date,Siganly):
bars=mt5.copy_rates_range(SYMBOL,Siganly,from_date,to_date)
# create a dataframe
df=pd.DataFrame(bars)[['close','open','high','low','time']]
# format the time column
df["time"]=pd.to_datetime(df["time"], unit='s')
# filter the time column
df=df[df["time"]>"2021-05-01"]
# create a high price dataframe if data frame is not empty
if df.empty != True:
highPrice=df[df["close"] == df["close"].max()]
HighPrice=highPrice.iloc[-1]["close"]
lowPrice=df[df["close"] == df["close"].min()]
# print(HighPrice)
highP_array[x][Siganly].append(HighPrice)
LowPrice=lowPrice.iloc[-1]["close"]
lowP_array[x][Siganly].append(LowPrice)
print(f"HIGH ARRAY IS {highP_array}")
print(f"LOW ARRAY {lowP_array}")
# get the highest price in an array
def main():
conn()
# startTest(from_date=datetime(2022,5,7),to_date=datetime(2022,5,9))
while True:
for s in high_TIMEFRAME:
global S
S=s
global v
global x
v=v+1
x=int(5)
if v >29:
x=x+1
v= int(1)
if x > 11:
x=int(1)
v=int(1)
from_date=datetime(2022,x,v)
to_date=datetime(2022,x,v+1)
print(f"From {from_date}")
print(f"To {to_date}")
print(f"The value of v is {v}")
print(f"The value of x is {x}")
print(f" The current timeframe is {S}")
startTest(Siganly=S,from_date=from_date,to_date=to_date)
time.sleep(1)
main()