/
PatternsJava.mq4
157 lines (138 loc) · 9.34 KB
/
PatternsJava.mq4
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
//+------------------------------------------------------------------+
//| frog.mq4 |
//| Copyright 2022, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2022, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
extern bool patternActivity = false;
extern bool patternPassivity = false;
extern bool patternMulti = false;
extern int checkCountTick = 10;
string URL="http://localhost/api/v1/ea/signal";
int countTick, res;
char post[];
char result[];
string headers;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- create timer
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//--- destroy timer
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
if (countTick >= checkCountTick) {
if(patternActivity) postPrice("activity");
if(patternPassivity) postPrice("passivity");
if(patternMulti) postPrice("multi");
} else {
countTick++;
}
}
//+------------------------------------------------------------------+
void createCross(color colors){
string nameLine = TimeToString(TimeCurrent(), TIME_DATE | TIME_MINUTES | TIME_SECONDS);
nameLine += " ";
nameLine += colors;
ObjectCreate(nameLine, OBJ_ARROW, 0, TimeCurrent(), Bid);
ObjectSetInteger(0,nameLine,OBJPROP_ARROWCODE,251);// установим код стрелки
ObjectSetInteger(0, nameLine, OBJPROP_COLOR, colors);
}
//+------------------------------------------------------------------+
void createCircle(color colors){
string nameLine = TimeToString(TimeCurrent(), TIME_DATE | TIME_MINUTES | TIME_SECONDS);
nameLine += " ";
nameLine += colors;
ObjectCreate(nameLine, OBJ_ARROW, 0, TimeCurrent(), Bid);
ObjectSetInteger(0,nameLine,OBJPROP_ARROWCODE,161);// установим код круга
ObjectSetInteger(0, nameLine, OBJPROP_COLOR, colors);
}
//+------------------------------------------------------------------+
void createLine(color colors){
string nameLine = TimeToString(TimeCurrent(), TIME_DATE | TIME_MINUTES);
ObjectCreate(nameLine, OBJ_HLINE, 0, 0, Bid);
ObjectSetInteger(0, nameLine, OBJPROP_COLOR, colors);
}
//+------------------------------------------------------------------+
void designateActivity(int responseCode) {
if(responseCode == 200){//если прошла дельта по аску
createCross(clrRed);
return;
}
if(responseCode == 201){//если прошла дельта по бид
createCross(clrBlue);
return;
}
if(responseCode == 202){//если прошли обе дельты цен
createCross(clrGold);
return;
}
}
void designatePassivity(int responseCode) {
if (responseCode == 300) {
createCircle(clrWhite);
}
}
void designateMulty(int responseCode) {
if(responseCode == 200){// low level
createCross(clrGold);
return;
}
if(responseCode == 201){// middle level
createCross(clrBlue);
return;
}
if(responseCode == 202){// high level
createCross(clrRed);
return;
}
}
//+------------------------------------------------------------------+
void postPrice(string pattern){
string url = URL
+ "?priceAsk=" + DoubleToString(Ask)
+ "&priceBid=" + DoubleToString(Bid)
+ "&pattern=" + pattern;
res = WebRequest("POST",url,NULL,NULL,500,post,0,result,headers);
if(res == -1) {
Print("Ошибка в WebRequest. Код ошибки = ",GetLastError());
return;
}
if(res == 500){
Print("Ошибка сервера");
return;
}
if(res == 400){
Print("Выборка слишком мала");
return;
}
if (patternActivity) {
designateActivity(res);
return;
}
if (patternPassivity) {
designatePassivity(res);
return;
}
if (patternMulti) {
designateMulty(res);
return;
}
}
//+------------------------------------------------------------------+