-
Notifications
You must be signed in to change notification settings - Fork 2
/
ZNO12.mq4
279 lines (273 loc) · 14.1 KB
/
ZNO12.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
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
//+--------------------------------------------------------------------------------------------------+
//| NO12.mq4 |
//| Strategiya muallifi: Nematillo Ochilov |
//| Dasturchi: Nematillo Ochilov |
//+--------------------------------------------------------------------------------------------------+
#property copyright "Nematillo Ochilov MQL4"// |
#property link "https://t.me/MQLUZ"// |
//+--------------------------------------------------------------------------------------------------+
//| Tashqi sozlamalar |
//+--------------------------------------------------------------------------------------------------+
extern int TakeProfit=30;// Daromadni belgilash |
extern int StopLoss=300;// Zararni cheklash |
extern int Slippage=10;// Oraliq farq (spreed) o'zgarishi |
extern int MA=1200;// Moving Average Period |
extern int RSI=8;// RSI Period |
extern int Step=30;// Savdolar orqasidagi qadamlar |
//+--------------------------------------------------------------------------------------------------+
//| Ochiq savdo miqdorlarini aniqlash funksiyalari |
//+--------------------------------------------------------------------------------------------------+
int Count_Buy()
{
int count_buy_orders = 0;
for(int i = 0; i < OrdersTotal(); i++)
{
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES) == false)
break;
if (OrderType() == OP_BUY || OrderType() == OP_BUYLIMIT)
count_buy_orders++;
}
return(count_buy_orders);
}
int Count_Sell()
{
int count_sell_orders = 0;
for (int i = 0; i < OrdersTotal(); i++)
{
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES) == false)
break;
if (OrderType() == OP_SELL || OrderType() == OP_SELLLIMIT)
count_sell_orders++;
}
return (count_sell_orders);
}
double Lot(double Lots)
{
/*if (Lots == 0.01)
Lots = 0.02;
if (OrdersTotal() > 1)
Lots = 2 * OrderLots();
if (Lots > 10)
Lots = 10;*/
return (0.01);
}
void satr(string text, uint x, uint y, color rang)
{
long chart_ID=0;//ChartID();
string obj_name="Text: "+IntegerToString(y);
if (ObjectsTotal() < 1)
{
if (ObjectCreate(obj_name,OBJ_LABEL,0,0,0))
{
ObjectSetInteger(chart_ID,obj_name,OBJPROP_COLOR,rang);
ObjectSetString(chart_ID,obj_name,OBJPROP_TEXT,text);
ObjectSet(chart_ID,OBJPROP_XDISTANCE,x);
ObjectSet(chart_ID,OBJPROP_YDISTANCE,y);
ChartRedraw(chart_ID);
}
else
{
Print("Error: can't create label! code #",GetLastError());
}
}
else
{
if(!ObjectSetString(chart_ID,obj_name,OBJPROP_TEXT,text))
{
Print(__FUNCTION__, ": failed to change the text! Error code = ",GetLastError());
}
}
}
//+------------------------------------------------------------------------------------------------------+
int start()// |
{// |
//+--------------------------------------------------------------------------------------------------+
//| Ichki sozlamalar |
//+--------------------------------------------------------------------------------------------------+
//+--------------------------------------------------------------------------------------------------+
//| Texnik ko'rsatgichlar sozlamasi |
//+--------------------------------------------------------------------------------------------------+
double RSI0=iRSI(NULL,0,RSI,PRICE_CLOSE,0);// |
double RSI1=iRSI(NULL,0,RSI,PRICE_OPEN,1);// |
double RSI2=iRSI(NULL,0,RSI,PRICE_OPEN,2);// |
bool RSI_BUY_CLOSE = RSI1 > 79;//RSI2 < RSI1 && RSI1 > RSI0 &&
bool RSI_SELL_CLOSE = RSI1 < 21;//RSI2 > RSI1 && RSI1 < RSI0 &&
double SMA=iMA(NULL,0,MA,0,0,0,0); // |
double AC=iAC(NULL,0,0);
double BandsU=iBands(NULL,0,20,2,0,PRICE_OPEN,MODE_UPPER,0);
double BandsL=iBands(NULL,0,20,2,0,PRICE_OPEN,MODE_LOWER,0);
//Print("BandsU ", BandsU);
//Print("BandsL ", BandsL);
bool Bands = BandsU - BandsL < 0.0025;
//+--------------------------------------------------------------------------------------------------+
//| |
//+--------------------------------------------------------------------------------------------------+
double Lots = 0.01;// Savdo hajmi
double TP = TakeProfit * Point;// Foydani cheklash |
double SL = StopLoss * Point;// Zararni cheklash |
double price=MarketInfo(Symbol(),MODE_BID); // Hozirgi narx
bool OpenBuy = false, OpenSell = false;
int CB = Count_Buy();
int CS = Count_Sell();
//+--------------------------------------------------------------------------------------------------+
//| Sotib olingan tovar haqida ma'lumotlarni saqlash |
//+--------------------------------------------------------------------------------------------------+
double BuyHistory[11][8];
ArrayResize(BuyHistory,CB + 1);
ArrayInitialize(BuyHistory, 0.0);
int NumberBuy = 0;
for(int BH = 0; BH < OrdersTotal(); BH++)
{
if (OrderSelect(BH, SELECT_BY_POS, MODE_TRADES) == false)
break;
if (OrderSymbol() == Symbol())
{
NumberBuy++;
if (OrderType() == OP_BUYLIMIT)
{
BuyHistory[NumberBuy][0] = OrderTicket();
BuyHistory[NumberBuy][3] = OrderType();
}
if (OrderType() == OP_BUY)
{
BuyHistory[NumberBuy][0] = OrderTicket();
BuyHistory[NumberBuy][1] = OrderOpenPrice();
BuyHistory[NumberBuy][2] = OrderLots();
BuyHistory[NumberBuy][3] = OrderType();
BuyHistory[NumberBuy][4] = OrderMagicNumber();
BuyHistory[NumberBuy][5] = OrderStopLoss();
BuyHistory[NumberBuy][6] = OrderTakeProfit();
BuyHistory[NumberBuy][7] = OrderProfit();
}
}
}
//+--------------------------------------------------------------------------------------------------+
//| Sotilgan tovar haqida ma'lumotlarni saqlash |
//+--------------------------------------------------------------------------------------------------+
double SellHistory[11][8];
ArrayResize(SellHistory, CS + 1);
ArrayInitialize(SellHistory, 0.0);
int NumberSell = 0;
for(int SH = 0; SH < OrdersTotal(); SH++)
{
if (OrderSelect(SH, SELECT_BY_POS, MODE_TRADES) == false)
break;
if (OrderSymbol() == Symbol())
{
NumberSell++;
if (OrderType() == OP_SELLLIMIT)
{
SellHistory[NumberSell][0] = OrderTicket();
SellHistory[NumberSell][3] = OrderType();
}
if (OrderType() == OP_SELL)
{
SellHistory[NumberSell][0] = OrderTicket();
SellHistory[NumberSell][1] = OrderOpenPrice();
SellHistory[NumberSell][2] = OrderLots();
SellHistory[NumberSell][3] = OrderType();
SellHistory[NumberSell][4] = OrderMagicNumber();
SellHistory[NumberSell][5] = OrderStopLoss();
SellHistory[NumberSell][6] = OrderTakeProfit();
SellHistory[NumberSell][7] = OrderProfit()
}
}
}
//+--------------------------------------------------------------------------------------------------+
//| Sotish yoki sotib olishni aniqlash qismi |
//+--------------------------------------------------------------------------------------------------+
/*satr(
"Ticket: " + IntegerToString(BuyHistory[CB][0]) +
" OpenPrice: " + DoubleToString(BuyHistory[CB][1]) +
" Lots: " + DoubleToString(BuyHistory[CB][2]) +
//" OrderType: " + IntegerToString(BuyHistory[CB][3]) +
//" OrderMagicNumber: " + IntegerToString(BuyHistory[CB][4]) +
//" OrderStopLoss: " + IntegerToString(BuyHistory[CB][5]) +
//" OrderTakeProfit: " + IntegerToString(BuyHistory[CB][6]) +
" Profit: " + DoubleToString(BuyHistory[CB][7]),
250,
1,
clrWhite);*/
if (OrdersTotal() < 1)
{
OpenBuy = (RSI1 > 79) && (RSI0 < 79) && SMA < price && AC < 0.0005;
OpenSell = (RSI1 < 21) && (RSI0 > 21) && SMA > price && AC > -0.0005;
}
if (CB > 0)
{
//OpenBuy = BuyHistory[CB][1] - Step * Point > Ask && AccountFreeMargin() > AccountBalance() * 0.5;
//&& Bands && SMA < price && -0.0002 < AC && AC < 0.0002;
if (RSI_BUY_CLOSE)//BuyHistory[CB][7] / (BuyHistory[CB][2]*10) > Step / 5 &&
{
for (int OCB = 0; OCB < CB; OCB++)
{Print("tttttttttttt", OrderType());Print("bbbbbbbbbbb", SellHistory[OCB][0]);
if (OrderType() == OP_BUYLIMIT)
{
if (!OrderDelete(BuyHistory[OCB][0]))
Print("OrderDelete BUYLIMITda muammo: ",GetLastError());
}
else
{
if (!OrderClose(BuyHistory[OCB][0],BuyHistory[OCB][2],Bid,Slippage,Aqua))
Print("OrderClose BUYda muammo: ",GetLastError());
}
}
}
}
if (CS > 0)
{
//OpenSell = SellHistory[CS][1] + Step * Point < Bid && AccountFreeMargin() > AccountBalance() * 0.5;
//&& Bands && SMA > price && -0.0002 < AC && AC < 0.0002;
if (RSI_SELL_CLOSE)//SellHistory[CS][7] / (SellHistory[CS][2]*10) > Step / 5 &&
{
for (int OCS = 0; OCS < CS; OCS++)
{Print("tttttttttttt", OrderType());Print("ssssssssss", SellHistory[OCS][0]);
if (OrderType() == OP_SELLLIMIT)
{
if (!OrderDelete(SellHistory[OCS][0]))
Print("OrderDelete SELLLIMITda muammo: ",GetLastError());
}
else
{
if (!OrderClose(SellHistory[OCS][0],SellHistory[OCS][2],Ask,Slippage,Red))
Print("OrderClose SELLda muammo: ",GetLastError());
}
}
}
}
//+--------------------------------------------------------------------------------------------------+
//| Sotish yoki sotib olish |
//+--------------------------------------------------------------------------------------------------+
if (OpenBuy)
{
if (!OrderSend(Symbol(), OP_BUY, Lot(Lots), Ask, Slippage, Ask - SL, Ask + TP, "NO savdo ", 0, 0, Blue))
Print("OrderSend BUYda muammo: ", GetLastError());//
}
if (OrdersTotal() == 1)
{
for (int OSBL = 30; OSBL < 300; OSBL += 30)
{Lots *= 2;
if (!OrderSend(Symbol(), OP_BUYLIMIT, Lots, Ask - OSBL * Point, Slippage,
Ask - (StopLoss + OSBL) * Point, Ask - (OSBL - TakeProfit) * Point, "NO savdo ", 0, 0, Blue))
Print("OrderSend BUYLIMITda muammo: ", GetLastError());//
}
}
if (OpenSell)
{
if (!OrderSend(Symbol(), OP_SELL, Lot(Lots), Bid, Slippage, Bid + SL, Bid - TP,"NO savdo ", 0, 0, Red))
Print("OrderSend SELLda muammo: ", GetLastError());//
}
if (OrdersTotal() == 1)
{
for (int OSSL = 30; OSSL < 300; OSSL += 30)
{Lots *= 2;
if (!OrderSend(Symbol(), OP_SELLLIMIT, Lots, Bid + OSSL * Point, Slippage,
Bid + (StopLoss + OSSL) * Point, Bid + (OSSL - TakeProfit) * Point, "NO savdo ", 0, 0, Red))
Print("OrderSend SELLLIMITda muammo: ", GetLastError());//
}
}
return(0);// |
}// |
//+--------------------------------------------------------------------------------------------------+
//| Tugadi |
//+--------------------------------------------------------------------------------------------------+