-
Notifications
You must be signed in to change notification settings - Fork 2
/
Trading flat.mq4
223 lines (211 loc) · 22.6 KB
/
Trading flat.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
//+--------------------------------------------------------------------------------------------------+
//| NO27.mq4 |
//| Strategiya muallifi: Nematillo Ochilov |
//| Dasturchi: Nematillo Ochilov |
//+--------------------------------------------------------------------------------------------------+
#property copyright "Nematillo Ochilov MQL4"// |
#property link "https://t.me/MQLUZ"// |
#property version "1.00"
//#property strict
//+--------------------------------------------------------------------------------------------------+
//| Tashqi sozlamalar |
//+--------------------------------------------------------------------------------------------------+
extern double Lots = 5000;// Savdo hajmi
extern double ATR_min = 0.003;
extern double ATR_max = 0.009;
extern int soat = 40;// Savdo hajmi
extern int Slippage=10;// Oraliq farq (spreed) o'zgarishi |
//+--------------------------------------------------------------------------------------------------+
//| Ochiq savdo miqdorlarini aniqlash funksiyalari |
//+--------------------------------------------------------------------------------------------------+
string _Profit(){
double BuyProfit = 0, SellProfit = 0;
for(int i=0; i<OrdersTotal(); i++){
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)){
if (OrderSymbol() == Symbol()){
if (OrderType() == OP_BUY){
BuyProfit = +OrderProfit();
}
if (OrderType() == OP_SELL){
SellProfit += OrderProfit();
}
}
}
}
string None = "Savdo mavjud emas";
string matn = " Buy foyda: " + DoubleToString(BuyProfit) + " Sell foyda: " + DoubleToString(SellProfit) +
" Jami: " + DoubleToString(BuyProfit + SellProfit);
if (BuyProfit != 0 || 0 != SellProfit){
return (matn);
}
else{
return (None);
}
}
void satr(string _name, string text, uint x, uint y, color rang){
long chart_ID = ChartID();
//string _name = IntegerToString(chart_ID);
ObjectCreate(chart_ID,_name,OBJ_LABEL,0,0,0);
ObjectSetInteger(chart_ID,_name,OBJPROP_COLOR,rang);
ObjectSetString(chart_ID,_name,OBJPROP_TEXT,text);
ObjectSet(chart_ID,OBJPROP_XDISTANCE,x);
ObjectSet(chart_ID,OBJPROP_YDISTANCE,y);
ChartRedraw(chart_ID);
//Sleep(600);
}
int ocb(int _Magic) {int _m;
for (int cb = OrdersTotal(); cb >= 0; cb--) {
if (OrderSelect(cb, SELECT_BY_POS, MODE_TRADES) == true) {
if (OrderType() == OP_BUY && OrderMagicNumber() == _Magic) {_m=0;
if (!OrderClose(OrderTicket(),OrderLots(),Bid,10,Blue))
Print("OrderClose OP_BUYda muammo: ", GetLastError());
}
else _m=7;
}
}
return(_m);
}
int ocs(int _Magic) {int _m;
for (int cb = OrdersTotal(); cb >= 0; cb--) {
if (OrderSelect(cb, SELECT_BY_POS, MODE_TRADES) == true) {
if (OrderType() == OP_SELL && OrderMagicNumber() == _Magic) {_m=0;
if (!OrderClose(OrderTicket(),OrderLots(),Ask,10,Red))
Print("OrderClose OP_SELLda muammo: ", GetLastError());
}
else _m=7;
}
}
return(_m);
}
void omb(double _PlusSL, int _Magic) {
for (int cb = OrdersTotal(); cb >= 0; cb--) {
if (OrderSelect(cb, SELECT_BY_POS, MODE_TRADES) == true) {
if (OrderType() == OP_BUY && OrderMagicNumber() == _Magic) {
if (!OrderModify(OrderTicket(), OrderOpenPrice(), _PlusSL, OrderTakeProfit(), 0, Aqua))
Print("OrderModify OP_BUY " + IntegerToString(_Magic) + "-da muammo: ", GetLastError());
}
}
}
}
void oms(double _PlusSL, int _Magic) {
for (int cb = OrdersTotal(); cb >= 0; cb--) {
if (OrderSelect(cb, SELECT_BY_POS, MODE_TRADES) == true) {
if (OrderType() == OP_SELL && OrderMagicNumber() == _Magic) {
if (!OrderModify(OrderTicket(), OrderOpenPrice(), _PlusSL, OrderTakeProfit(), 0, Orange))
Print("OrderModify OP_SELL " + IntegerToString(_Magic) + "-da muammo: ", GetLastError());
}
}
}
}
double ATRS() {
double _TOTAL;
double _ATR = iATR(NULL,PERIOD_H4,14,0);
double _ATR5 = iATR(NULL,PERIOD_H4,14,5);
if (_ATR > _ATR5) _TOTAL = _ATR - _ATR5;
if (_ATR5 > _ATR) _TOTAL = _ATR5 - _ATR;
return (_TOTAL);
}
int modify = 0;
datetime M = TimeCurrent(), P = TimeCurrent();
int p = 0, m = 0;
//+------------------------------------------------------------------------------------------------------+
void start()// |
{// |
//+--------------------------------------------------------------------------------------------------+
//| Ichki sozlamalar |
//+--------------------------------------------------------------------------------------------------+
//| Texnik ko'rsatgichlar sozlamasi |
//+--------------------------------------------------------------------------------------------------+
double ADX =iADX(NULL,0,10,PRICE_CLOSE,MODE_MAIN,0);
double ADX0 =iADX(NULL,PERIOD_H4,10,PRICE_CLOSE,MODE_MAIN,0);
double ADX1 =iADX(NULL,PERIOD_H4,10,PRICE_CLOSE,MODE_MAIN,1);
double ADX2 =iADX(NULL,PERIOD_H4,10,PRICE_CLOSE,MODE_MAIN,2);
double ADX3 =iADX(NULL,PERIOD_H4,10,PRICE_CLOSE,MODE_MAIN,3);
double ADX4 =iADX(NULL,PERIOD_H4,10,PRICE_CLOSE,MODE_MAIN,4);
//satr("0","ADX0 " + DoubleToString(ADX0) + " ADX1 " + DoubleToString(ADX1) +" ADX2 " + DoubleToString(ADX2) +
//" ADX3 " + DoubleToString(ADX3) +" ADX4 " + DoubleToString(ADX4), 250, 50, clrWhite);
double ATR =iATR(NULL,PERIOD_H4,14,0);
double Bands =iBands(NULL,0,900,1.3,0,PRICE_CLOSE,MODE_MAIN,0);
double BandsP =iBands(NULL,0,900,1.3,0,PRICE_CLOSE,MODE_PLUSDI,0);
double BandsM =iBands(NULL,0,900,1.3,0,PRICE_CLOSE,MODE_MINUSDI,0);
double BandsP100 =iBands(NULL,0,900,1.3,0,PRICE_CLOSE,MODE_PLUSDI,100);
double BandsM100 =iBands(NULL,0,900,1.3,0,PRICE_CLOSE,MODE_MINUSDI,100);
bool b100_2 = (BandsP100 - BandsM100) * 2 < BandsP - BandsM;
bool b100 = (BandsP100 - BandsM100) > BandsP - BandsM;
double hml = iHigh(Symbol(),0,iHighest(NULL,0,MODE_HIGH,100,0)) - iLow(Symbol(),0,iLowest(NULL,0,MODE_LOW,100,0));
double Price=MarketInfo(Symbol(),MODE_BID); //iMA(NULL,0,1,0,0,0,0);
int HP = TimeCurrent() - P;
int HM = TimeCurrent() - M;
string tex = "HP: " + IntegerToString(HP/3600) + " : HM: " + IntegerToString(HM/3600);
double Lot = AccountBalance() / Lots;
int SOAT = soat * 3600;
int oraliq = (TimeCurrent() - OrderOpenTime()) / 3600;
//satr("0", IntegerToString(oraliq), 250, 50, clrWhite);
//satr("0", tex, 250, 50, clrWhite);
//+--------------------------------------------------------------------------------------------------+
//| Sotish yoki sotib olishni aniqlash qismi |
//+--------------------------------------------------------------------------------------------------+
//Print(_Profit());
//satr("0", DoubleToString(ATRS()), 250, 50, clrWhite);
if (BandsP < Price) {P = TimeCurrent(); p = 1;}
if (BandsM > Price) {M = TimeCurrent(); m = 1;}
if (0 < OrdersTotal()) {
for(int i=0; i<OrdersTotal(); i++) {
int b = 0, s = 0;
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES) == true) {
if (OrderType() == OP_BUY) {
if (p == 1) {b = 1;}
else if (OrderOpenPrice() > Price) {
if (b100_2 || oraliq > 40) {
if (iHighest(NULL,0,MODE_HIGH,70,0) == 0) {b = 1;}}
else if (iHighest(NULL,0,MODE_HIGH,300,0) == 0) {b = 1;}
}
else if (modify == 0) {
if (Bands > Price && Bands - 50 * Point < Price) {
omb(BandsM + 100 * Point, 1); modify = 1;
}
}
}
else if (OrderType() == OP_SELL) {
if (m == 1) {s = 1;}
else if (OrderOpenPrice() < Price) {//satr("0", IntegerToString(oraliq), 250, 50, clrWhite);
if (b100_2 || oraliq > 40) {//satr("0", "aaaaaaaaaaaa", 250, 50, clrWhite);
if (iLowest(NULL,0,MODE_LOW,70,0) == 0) {s = 1;}}
if (iLowest(NULL,0,MODE_LOW,300,0) == 0) {s = 1;}
}
else if (modify == 0) {
if (Bands + 100 * Point > Price && Bands < Price) {
oms(BandsP - 50 * Point, 2); modify = 1;
}
}
}
}
if (b == 1) ocb(1);
else if (s == 1) ocs(2);
}
}
//+--------------------------------------------------------------------------------------------------+
//| Sotish yoki sotib olish |
//+--------------------------------------------------------------------------------------------------+
//satr("0", IntegerToString(HM), 250, 50, clrWhite);
if (1 > OrdersTotal()) {modify = 0;//ADX0 < ADX1
if (ATR > ATR_min && ATR < ATR_max) {
//if (ATRS() > 0) {
if (hml < 0.007 && b100) {//satr("0", DoubleToString(hml), 250, 50, clrWhite);
if (BandsM > Price && HP < SOAT) {//satr("0", IntegerToString(HP), 250, 50, clrWhite);
int buy = OrderSend(Symbol(), OP_BUY, Lot, Ask, 10, 0, 0, "NO savdo ", 1, 0, Aqua);
if (buy<0) {Print("OrderSend BUYda muammo: ",GetLastError());}
}
else if (BandsP < Price && HM < SOAT) {
int sell = OrderSend(Symbol(), OP_SELL, Lot, Bid, 10, 0, 0, "NO savdo ", 2, 0, Red);
if (sell<0) {Print("OrderSend BUYda muammo: ",GetLastError());}
}
}
}
}
p = 0;
m = 0;
}
//+--------------------------------------------------------------------------------------------------+
//| Tugadi |
//+--------------------------------------------------------------------------------------------------+