-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodul_oo.mqh
199 lines (175 loc) · 5.16 KB
/
modul_oo.mqh
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
//+------------------------------------------------------------------+
//| module_oo.mqh |
//| Copyright 2019, MetaQuotes Software Corp. |
//| [email protected] |
//+------------------------------------------------------------------+
#property copyright "Copyright 2019, MetaQuotes Software Corp."
#property link "[email protected]"
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
class Order
{
private:
MqlTradeRequest o_request;
MqlTradeResult o_result;
int OrderSL;
int OrderTP;
double order_SL;
double order_TP;
public:
Order()
{
ZeroMemory(o_request);
o_request.action = TRADE_ACTION_DEAL;
o_request.magic = 0;
o_request.symbol = Symbol();
o_request.volume = 0;
o_request.sl = 0;
o_request.deviation = 5;
o_request.type_filling = ORDER_FILLING_FOK;
o_request.type_time = ORDER_TIME_DAY;
o_request.expiration = 0;
OrderSL = 0;
OrderTP = 0;
order_SL= 0;
order_TP= 0;
}
double GetSL(bool CheckBuyOrder)
{
if (OrderSL > 0)
{
if (CheckBuyOrder)
{
return SymbolInfoDouble(o_request.symbol, SYMBOL_ASK) - OrderSL * _Point;
}
else
{
return SymbolInfoDouble(o_request.symbol, SYMBOL_BID) + OrderSL * _Point;
}
}
else return(order_SL);
}
double GetTP(bool CheckBuyOrder)
{
if (OrderTP > 0)
{
if (CheckBuyOrder)
{
return SymbolInfoDouble(o_request.symbol, SYMBOL_ASK) + OrderTP * _Point;
}
else
{
return SymbolInfoDouble(o_request.symbol, SYMBOL_BID) - OrderTP * _Point;
}
}
else return(order_TP);
}
bool Execute()
{
bool err=OrderSend(o_request,o_result);
if(!err)
{
Print("Greska prilikom izvrsenja naloga!");
}
return(err);
}
bool Buy()
{
o_request.symbol = Symbol();
o_request.type = ORDER_TYPE_BUY;
o_request.price = SymbolInfoDouble(o_request.symbol, SYMBOL_ASK);
o_request.sl = GetSL(true);
o_request.tp = GetTP(true);
return(Execute());
}
bool Sell()
{
o_request.symbol = Symbol();
o_request.type = ORDER_TYPE_SELL;
o_request.price = SymbolInfoDouble(o_request.symbol, SYMBOL_BID);
o_request.sl = GetSL(false);
o_request.tp = GetTP(false);
return(Execute());
}
bool Close()
{
bool ret;
if(PositionSelect(o_request.symbol))
{
if(ENUM_POSITION_TYPE(PositionGetInteger(POSITION_TYPE))==POSITION_TYPE_BUY)
{
o_request.type = ORDER_TYPE_BUY;
o_request.price = SymbolInfoDouble(o_request.symbol, SYMBOL_ASK);
}
else if(ENUM_POSITION_TYPE(PositionGetInteger(POSITION_TYPE))==POSITION_TYPE_SELL)
{
o_request.type = ORDER_TYPE_SELL;
o_request.price = SymbolInfoDouble(o_request.symbol, SYMBOL_BID);
}
double vol = o_request.volume;
o_request.sl = 0;
o_request.tp = 0;
o_request.volume = PositionGetDouble(POSITION_VOLUME);
ret=Execute();
o_request.volume=vol;
}
else
{
Print("ZATVORI: Ne mozete odabrati poziciju! ");
ret=false;
}
return(ret);
}
void SetMagic(int magic)
{
o_request.magic=magic;
}
void SetComment(string comment)
{
o_request.comment=comment;
}
void SetLots(double lots)
{
o_request.volume=lots;
}
void SetSL(int sl)
{
order_SL = 0;
OrderSL = sl;
}
void SetTP(int tp)
{
order_TP = 0;
OrderTP = tp;
}
void Signal()
{
ulong N = 500;
ulong m_number = 191817;
MqlRates rates[];
ArraySetAsSeries(rates,true);
int copied=CopyRates(NULL,0,0,100,rates);
if(copied<=0) {
Print("Error copying price data ",GetLastError());
}
else{
Print("Copied ",ArraySize(rates)," bars");
}
if ( rates[0].high - rates[0].low > rates[1].high - rates[1].low &&
rates[0].high < rates[1].high &&
rates[0].open < rates[1].close &&
rates[0].close < rates[1].open &&
rates[0].low < rates[1].low ){
Sell();
}
else if ( rates[0].high - rates[0].low < rates[1].high - rates[1].low &&
rates[0].high > rates[1].high &&
rates[0].close > rates[1].open &&
rates[0].open > rates[1].close &&
rates[0].low > rates[1].low ){
Buy();
}
}
};
//+------------------------------------------------------------------+