|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+//+------------------------------------------------------------------+
|
|
|
2
|
+//| CribMarketEA.mq5 |
|
|
|
3
|
+//| Copyright 2025, MQL Development |
|
|
|
4
|
+//| https://www.mqldevelopment.com/ |
|
|
|
5
|
+//+------------------------------------------------------------------+
|
|
|
6
|
+#property copyright "Copyright 2025, MQL Development"
|
|
|
7
|
+#property link "https://www.mqldevelopment.com/"
|
|
|
8
|
+#property version "1.00"
|
|
|
9
|
+
|
|
|
10
|
+#include <Trade\Trade.mqh>
|
|
|
11
|
+CTrade trade;
|
|
|
12
|
+
|
|
|
13
|
+
|
|
|
14
|
+input string Settings = " ------------- General Settings ------------- "; //_
|
|
|
15
|
+input int magicNo = 333; // Magic no
|
|
|
16
|
+input double lotSize = 0.1; // Lot Size
|
|
|
17
|
+
|
|
|
18
|
+
|
|
|
19
|
+string goldPairs[];
|
|
|
20
|
+int totalGoldPairs = 0;
|
|
|
21
|
+
|
|
|
22
|
+//+------------------------------------------------------------------+
|
|
|
23
|
+//| Expert initialization function |
|
|
|
24
|
+//+------------------------------------------------------------------+
|
|
|
25
|
+int OnInit()
|
|
|
26
|
+ {
|
|
|
27
|
+//---
|
|
|
28
|
+
|
|
|
29
|
+ trade.SetExpertMagicNumber(magicNo);
|
|
|
30
|
+ trade.SetDeviationInPoints(10);
|
|
|
31
|
+ trade.SetTypeFilling(ORDER_FILLING_IOC);
|
|
|
32
|
+ trade.LogLevel(LOG_LEVEL_ALL);
|
|
|
33
|
+ trade.SetAsyncMode(false);
|
|
|
34
|
+
|
|
|
35
|
+ getGoldPairsFromMarketWatch();
|
|
|
36
|
+
|
|
|
37
|
+
|
|
|
38
|
+//---
|
|
|
39
|
+ return(INIT_SUCCEEDED);
|
|
|
40
|
+ }
|
|
|
41
|
+//+------------------------------------------------------------------+
|
|
|
42
|
+//| Expert deinitialization function |
|
|
|
43
|
+//+------------------------------------------------------------------+
|
|
|
44
|
+void OnDeinit(const int reason)
|
|
|
45
|
+ {
|
|
|
46
|
+//---
|
|
|
47
|
+
|
|
|
48
|
+ }
|
|
|
49
|
+//+------------------------------------------------------------------+
|
|
|
50
|
+//| Expert tick function |
|
|
|
51
|
+//+------------------------------------------------------------------+
|
|
|
52
|
+void OnTick()
|
|
|
53
|
+ {
|
|
|
54
|
+//---
|
|
|
55
|
+
|
|
|
56
|
+ }
|
|
|
57
|
+//+------------------------------------------------------------------+
|
|
|
58
|
+//| |
|
|
|
59
|
+//+------------------------------------------------------------------+
|
|
|
60
|
+bool newBar()
|
|
|
61
|
+ {
|
|
|
62
|
+ static datetime lastbar;
|
|
|
63
|
+ datetime curbar = iTime(Symbol(), PERIOD_CURRENT, 0);
|
|
|
64
|
+ if(lastbar != curbar)
|
|
|
65
|
+ {
|
|
|
66
|
+ lastbar = curbar;
|
|
|
67
|
+ Print(" ---------------------- New Bar :: ---------------------- ",lastbar);
|
|
|
68
|
+ return (true);
|
|
|
69
|
+ }
|
|
|
70
|
+ else
|
|
|
71
|
+ {
|
|
|
72
|
+ return (false);
|
|
|
73
|
+ }
|
|
|
74
|
+ }
|
|
|
75
|
+//+------------------------------------------------------------------+
|
|
|
76
|
+//| |
|
|
|
77
|
+//+------------------------------------------------------------------+
|
|
|
78
|
+void placeBuyTrade(string symbol)
|
|
|
79
|
+ {
|
|
|
80
|
+ double ask = SymbolInfoDouble(symbol, SYMBOL_ASK);
|
|
|
81
|
+ double buySL = 0, buyTP = 0;
|
|
|
82
|
+
|
|
|
83
|
+ if(trade.PositionOpen(symbol, ORDER_TYPE_BUY, lotSize, ask, buySL, buyTP, "Buy Trade Placed"))
|
|
|
84
|
+ {
|
|
|
85
|
+ Print("Buy Trade Placed on ", symbol, trade.ResultOrder());
|
|
|
86
|
+ }
|
|
|
87
|
+ else
|
|
|
88
|
+ {
|
|
|
89
|
+ Print("Buy Failed on ", symbol, " Error: ", GetLastError());
|
|
|
90
|
+ }
|
|
|
91
|
+ }
|
|
|
92
|
+//+------------------------------------------------------------------+
|
|
|
93
|
+//| |
|
|
|
94
|
+//+------------------------------------------------------------------+
|
|
|
95
|
+void placeSellTrade(string symbol)
|
|
|
96
|
+ {
|
|
|
97
|
+ double bid = SymbolInfoDouble(symbol, SYMBOL_BID);
|
|
|
98
|
+ double sellSL = 0, sellTP = 0;
|
|
|
99
|
+
|
|
|
100
|
+ if(trade.PositionOpen(symbol, ORDER_TYPE_SELL, lotSize, bid, sellSL, sellTP, "Sell Trade Placed"))
|
|
|
101
|
+ {
|
|
|
102
|
+ Print("Sell Trade Placed on ", symbol, trade.ResultOrder());
|
|
|
103
|
+ }
|
|
|
104
|
+ else
|
|
|
105
|
+ {
|
|
|
106
|
+ Print("Sell Failed on ", symbol, " Error: ", GetLastError());
|
|
|
107
|
+ }
|
|
|
108
|
+ }
|
|
|
109
|
+//+------------------------------------------------------------------+
|
|
|
110
|
+//| |
|
|
|
111
|
+//+------------------------------------------------------------------+
|
|
|
112
|
+void getGoldPairsFromMarketWatch()
|
|
|
113
|
+ {
|
|
|
114
|
+ int totalSymbols = SymbolsTotal(true);
|
|
|
115
|
+ ArrayResize(goldPairs, totalSymbols);
|
|
|
116
|
+
|
|
|
117
|
+ for(int i = 0; i < totalSymbols; i++)
|
|
|
118
|
+ {
|
|
|
119
|
+ string symbolName = SymbolName(i, true);
|
|
|
120
|
+ if(StringFind(symbolName, "GOLD") != -1 || StringFind(symbolName, "XAU") != -1)
|
|
|
121
|
+ {
|
|
|
122
|
+ goldPairs[totalGoldPairs] = symbolName;
|
|
|
123
|
+ totalGoldPairs++;
|
|
|
124
|
+ }
|
|
|
125
|
+ }
|
|
|
126
|
+
|
|
|
127
|
+ ArrayResize(goldPairs, totalGoldPairs);
|
|
|
128
|
+ Print("Found ", totalGoldPairs, " gold pairs in Market Watch");
|
|
|
129
|
+ }
|
|
|
130
|
+//+------------------------------------------------------------------+
|
|
|
131
|
+//| |
|
|
|
132
|
+//+------------------------------------------------------------------+
|
|
|
133
|
+string getSymbolWithLowestAsk()
|
|
|
134
|
+ {
|
|
|
135
|
+
|
|
|
136
|
+ if(totalGoldPairs == 0)
|
|
|
137
|
+ return NULL;
|
|
|
138
|
+
|
|
|
139
|
+ string lowestSymbol = goldPairs[0];
|
|
|
140
|
+ double lowestAsk = SymbolInfoDouble(lowestSymbol, SYMBOL_ASK);
|
|
|
141
|
+
|
|
|
142
|
+ for(int i = 1; i < totalGoldPairs; i++)
|
|
|
143
|
+ {
|
|
|
144
|
+ double currentAsk = SymbolInfoDouble(goldPairs[i], SYMBOL_ASK);
|
|
|
145
|
+ if(currentAsk < lowestAsk)
|
|
|
146
|
+ {
|
|
|
147
|
+ lowestAsk = currentAsk;
|
|
|
148
|
+ lowestSymbol = goldPairs[i];
|
|
|
149
|
+ }
|
|
|
150
|
+ }
|
|
|
151
|
+
|
|
|
152
|
+ return lowestSymbol;
|
|
|
153
|
+ }
|
|
|
154
|
+
|
|
|
155
|
+//+------------------------------------------------------------------+
|
|
|
156
|
+//| |
|
|
|
157
|
+//+------------------------------------------------------------------+
|
|
|
158
|
+string getSymbolWithHighestBid()
|
|
|
159
|
+ {
|
|
|
160
|
+
|
|
|
161
|
+ if(totalGoldPairs == 0)
|
|
|
162
|
+ return NULL;
|
|
|
163
|
+
|
|
|
164
|
+ string highestSymbol = goldPairs[0];
|
|
|
165
|
+ double highestBid = SymbolInfoDouble(highestSymbol, SYMBOL_BID);
|
|
|
166
|
+
|
|
|
167
|
+ for(int i = 1; i < totalGoldPairs; i++)
|
|
|
168
|
+ {
|
|
|
169
|
+ double currentBid = SymbolInfoDouble(goldPairs[i], SYMBOL_BID);
|
|
|
170
|
+ if(currentBid > highestBid)
|
|
|
171
|
+ {
|
|
|
172
|
+ highestBid = currentBid;
|
|
|
173
|
+ highestSymbol = goldPairs[i];
|
|
|
174
|
+ }
|
|
|
175
|
+ }
|
|
|
176
|
+
|
|
|
177
|
+ return highestSymbol;
|
|
|
178
|
+ }
|
|
|
179
|
+//+------------------------------------------------------------------+
|