Przeglądaj źródła

Ticket : 4797 Multi Pair Entry Bot

1) Basket TP Fixed
2) Same Symbol check Added
3) Max Combinations check Added
faiz ali 6 miesięcy temu
rodzic
commit
c07fa56b56
2 zmienionych plików z 33 dodań i 59 usunięć
  1. BIN
      V2/CribMarketEAV2.ex5
  2. 33 59
      V2/CribMarketEAV2.mq5

BIN
V2/CribMarketEAV2.ex5


+ 33 - 59
V2/CribMarketEAV2.mq5

@@ -101,21 +101,21 @@ void OnTimer()
101 101
    int buyTickett = -1, sellTickett = -1;
102 102
 //Print(" Symbol to Buy is: ", symbolToBuy, " Symbol to Sell: ", symbolToSell);
103 103
 
104
-   if(canTradeSymbol(symbolToBuy, symbolToSell, POSITION_TYPE_BUY, POSITION_TYPE_SELL))
104
+   if(noOfActiveCombinations() < maxOpenPositions)
105 105
      {
106
-      if(noOfActiveOrdersOfType(POSITION_TYPE_BUY) < maxOpenPositions)
106
+      if(canTradeSymbol(symbolToBuy, symbolToSell, POSITION_TYPE_BUY, POSITION_TYPE_SELL))
107 107
         {
108
-         if(symbolToBuy != NULL && symbolToBuy != "")
108
+         if(symbolToBuy != symbolToSell)
109 109
            {
110
-            buyTickett = placeBuyTrade(symbolToBuy);
111
-           }
112
-        }
110
+            if(symbolToBuy != NULL && symbolToBuy != "")
111
+              {
112
+               buyTickett = placeBuyTrade(symbolToBuy);
113
+              }
113 114
 
114
-      if(noOfActiveOrdersOfType(POSITION_TYPE_SELL) < maxOpenPositions)
115
-        {
116
-         if(symbolToSell != NULL && symbolToSell != "")
117
-           {
118
-            sellTickett = placeSellTrade(symbolToSell);
115
+            if(symbolToSell != NULL && symbolToSell != "")
116
+              {
117
+               sellTickett = placeSellTrade(symbolToSell);
118
+              }
119 119
            }
120 120
         }
121 121
      }
@@ -271,21 +271,14 @@ string getSymbolWithHighestBid()
271 271
 //+------------------------------------------------------------------+
272 272
 //|                                                                  |
273 273
 //+------------------------------------------------------------------+
274
-int noOfActiveOrdersOfType(ENUM_POSITION_TYPE type)
274
+int noOfActiveCombinations()
275 275
   {
276 276
    int count = 0;
277
-
278
-   for(int i= PositionsTotal()-1; i>=0; i--)
277
+   for(int i = 0; i < MaxOrders; i++)
279 278
      {
280
-      ulong ticket = PositionGetTicket(i);
281
-      if(PositionSelectByTicket(ticket))
279
+      if(newTradeStore[i].buyTicket != -1 && newTradeStore[i].sellTicket != -1)
282 280
         {
283
-         if(PositionGetInteger(POSITION_MAGIC)    == magicNo
284
-            && (PositionGetInteger(POSITION_TYPE) == type)
285
-            && isGoldPair(PositionGetString(POSITION_SYMBOL)))
286
-           {
287
-            count++;
288
-           }
281
+         count++;
289 282
         }
290 283
      }
291 284
    return count;
@@ -295,52 +288,33 @@ int noOfActiveOrdersOfType(ENUM_POSITION_TYPE type)
295 288
 //+------------------------------------------------------------------+
296 289
 void checkBasketTakeProfit()
297 290
   {
298
-   double netProfit = 0;
299
-
300
-   for(int i = PositionsTotal() - 1; i >= 0; i--)
291
+   for(int i = 0; i < MaxOrders; i++)
301 292
      {
302
-      ulong ticket = PositionGetTicket(i);
303
-      if(PositionSelectByTicket(ticket))
293
+      if(newTradeStore[i].buyTicket != -1 && newTradeStore[i].sellTicket != -1)
304 294
         {
305
-         if(isGoldPair(PositionGetString(POSITION_SYMBOL)) &&
306
-            PositionGetInteger(POSITION_MAGIC) == magicNo)
295
+         double combinationProfit = 0;
296
+
297
+         if(PositionSelectByTicket(newTradeStore[i].buyTicket))
307 298
            {
308
-            netProfit += PositionGetDouble(POSITION_PROFIT)+PositionGetDouble(POSITION_SWAP);
299
+            combinationProfit += PositionGetDouble(POSITION_PROFIT) + PositionGetDouble(POSITION_SWAP);
309 300
            }
310
-        }
311
-     }
312 301
 
313
-   if(netProfit >= basketTakeProfit)
314
-     {
315
-      Print("Basket TP hit: Closing all trades. Profit = ", netProfit);
316
-      closeAllActiveOrders();
317
-     }
318
-  }
319
-//+------------------------------------------------------------------+
320
-//|                                                                  |
321
-//+------------------------------------------------------------------+
322
-void closeAllActiveOrders()
323
-  {
324
-   for(int i=PositionsTotal()-1; i >=0 ; i--)
325
-     {
326
-      ulong ticket = PositionGetTicket(i);
327
-      if(PositionSelectByTicket(ticket))
328
-        {
329
-         if(PositionGetInteger(POSITION_MAGIC) == magicNo &&
330
-            isGoldPair(PositionGetString(POSITION_SYMBOL)))
302
+         if(PositionSelectByTicket(newTradeStore[i].sellTicket))
331 303
            {
332
-            if(trade.PositionClose(ticket))
333
-              {
334
-               Print("Position closed ", ticket);
335
-              }
336
-            else
337
-              {
338
-               Print("Cannot close order: ",GetLastError());
339
-              }
304
+            combinationProfit += PositionGetDouble(POSITION_PROFIT) + PositionGetDouble(POSITION_SWAP);
305
+           }
306
+
307
+         if(combinationProfit >= basketTakeProfit)
308
+           {
309
+            Print("Combination TP hit: Closing trades. Profit = ", combinationProfit);
310
+
311
+            trade.PositionClose(newTradeStore[i].buyTicket);
312
+            Print("Buy Trade Closed: ", newTradeStore[i].buyTicket);
313
+            trade.PositionClose(newTradeStore[i].sellTicket);
314
+            Print("Sell Trade Closed: ", newTradeStore[i].sellTicket);
340 315
            }
341 316
         }
342 317
      }
343
-
344 318
   }
345 319
 //+------------------------------------------------------------------+
346 320
 //|                                                                  |