Browse Source

removed the heart beat calling and inputs re-arranged

WajeehSaqib-MQL 1 month ago
parent
commit
5336487704

BIN
client/localHedgingClientCopierMt5.ex5


+ 24 - 100
client/localHedgingClientCopierMt5.mq5

@@ -114,8 +114,8 @@ enum lot_option
114
   {
114
   {
115
    fix, //Fixed Lot
115
    fix, //Fixed Lot
116
    mul, //Multiplied Lot
116
    mul, //Multiplied Lot
117
-   Balance, // Balance Base Multiplier
118
-   slaveLotCal,
117
+// Balance, // Balance Base Multiplier
118
+   slaveLotCal,   // Slave Lot formula based
119
   };
119
   };
120
 enum tradeCopy_type
120
 enum tradeCopy_type
121
   {
121
   {
@@ -133,22 +133,19 @@ sinput       string                  string_0                  = "<><><><><><> G
133
 input        int                     slip                     = 5;               // Master Order Variation in Pips
133
 input        int                     slip                     = 5;               // Master Order Variation in Pips
134
 input        int                     sec                      = 10;              // Master Order Expired After Seconds
134
 input        int                     sec                      = 10;              // Master Order Expired After Seconds
135
 input        tradeCopy_type          tradeType                = buySell;         // Trades To Copy
135
 input        tradeCopy_type          tradeType                = buySell;         // Trades To Copy
136
-input        lot_option              lotoption                = slaveLotCal;     // Lot Option
137
-input        double                  mult                     = 1.0;             // Multiplier (for Client)
138
-input        double                  fixed                    = 0.1;             // Fixed Lot (for Client)
139
-input        double                  Bmult                    = 1;               // Balance Multiplier (for Client)
140
-input        double                  recoveryAmount           = 3000;            // Recovery Amount (for Client Lot)
141
-input        double                  maxDd                    = 8000;            // Max DrawDown (for Client Lot)
142
 input        string                  suffix                   = "";              // Suffix
136
 input        string                  suffix                   = "";              // Suffix
143
 input        string                  symbolExclude            = "";              // Symbol to Exclude
137
 input        string                  symbolExclude            = "";              // Symbol to Exclude
144
 input        string                  prefix                   = "";              // Prefix
138
 input        string                  prefix                   = "";              // Prefix
145
-input        string                  mappingSymbol            = "GOLD,XAUUSD;bitcoin,BTCUSD"; // Mapping Pairs Inp,Out;Inp,Out
139
+input        string                  mappingSymbol            = "GOLD:XAUUSD,bitcoin:BTCUSD"; // Mapping Pairs Inp:Out,Inp:Out
140
+
141
+sinput       string                  string_1                  = "<><><><><><> Lotsize SETTINGS <><><><><><>";   //__
142
+input        lot_option              lotoption                = mul;             // Lot Option
143
+input        double                  fixed                    = 0.1;             // Fixed Lot (for Client)
144
+input        double                  mult                     = 1.0;             // Multiplier (for Client)
145
+double                  Bmult                    = 1;               // Balance Multiplier (for Client)
146
+input        double                  recoveryAmount           = 3000;            // Recovery Amount (for Client Lot)
147
+input        double                  maxDd                    = 8000;            // Max drawdown prop (for Client Lot)
146
 
148
 
147
-// Heart Beat
148
-sinput       string                  string_1                  = "<><><><><><> HeartBeat Setting <><><><><><>";   //__
149
-input        string                  clientServer             = "";              // Master Server
150
-input        string                  localApiKey              = "U2FsdGVkX18vBY4H1uzQiZwuh8B++8VBtCGJ3yGr2XPII0qCodmfuhjssKu5oug1J4e97bkwPtDQLi4py1OODQ=="; // Local API Key
151
-input        string                  localHB_req_link         = "http://localhost/api/slastConnected"; // Request Link For LastConnected
152
 
149
 
153
 //+------------------------------------------------------------------+
150
 //+------------------------------------------------------------------+
154
 //|                                                                  |
151
 //|                                                                  |
@@ -163,7 +160,7 @@ bool       contractChk   = true;//Contract Checking
163
 bool doReversal = true; // Reverse Trades
160
 bool doReversal = true; // Reverse Trades
164
 bool fileLastEmpty=false;
161
 bool fileLastEmpty=false;
165
 long accountNumber=AccountInfoInteger(ACCOUNT_LOGIN);
162
 long accountNumber=AccountInfoInteger(ACCOUNT_LOGIN);
166
-int counter=0,testCounterVar=0;
163
+
167
 order order_array[];
164
 order order_array[];
168
 datetime lastModified1=0;
165
 datetime lastModified1=0;
169
 long lastFileSize1=0;
166
 long lastFileSize1=0;
@@ -647,18 +644,6 @@ void readData()
647
          if(lastModified==lastFileModified && fileSize==lastFileSize) // lastModified==lastFileModified && fileSize==lastFileSize
644
          if(lastModified==lastFileModified && fileSize==lastFileSize) // lastModified==lastFileModified && fileSize==lastFileSize
648
            {
645
            {
649
             FileClose(filehandle);
646
             FileClose(filehandle);
650
-            if(counter>=count1 && TerminalInfoInteger(TERMINAL_CONNECTED))
651
-              {
652
-               if(testCounterVar==testCounter)
653
-                 {
654
-                  testCounterVar=0;
655
-                 }
656
-               adminHeartBeat();
657
-               counter=0;
658
-
659
-              }
660
-            counter++;
661
-            testCounterVar++;
662
            }
647
            }
663
          else
648
          else
664
            {
649
            {
@@ -741,12 +726,15 @@ void readData()
741
                   if(PositionSelectByTicket(ticket))
726
                   if(PositionSelectByTicket(ticket))
742
                     {
727
                     {
743
                      if(history_ticket_present(PositionGetInteger(POSITION_MAGIC)))
728
                      if(history_ticket_present(PositionGetInteger(POSITION_MAGIC)))
729
+                       {
730
+                        // Print(" inside Array size 1: ",ticket);
744
                         if(!trade.PositionClose(ticket))
731
                         if(!trade.PositionClose(ticket))
745
                           {
732
                           {
746
                            Print(" Order Close Error on No Master Trade: "+IntegerToString(GetLastError()));
733
                            Print(" Order Close Error on No Master Trade: "+IntegerToString(GetLastError()));
747
                           }
734
                           }
748
                         else
735
                         else
749
                            Print(" ------------- Order Close by empty array ------------------ ");
736
                            Print(" ------------- Order Close by empty array ------------------ ");
737
+                       }
750
                     }
738
                     }
751
                  }
739
                  }
752
               }
740
               }
@@ -1441,11 +1429,11 @@ string getSymbol(string symbol)
1441
    if(mappingSymbol!="")
1429
    if(mappingSymbol!="")
1442
      {
1430
      {
1443
       string symbollist[];
1431
       string symbollist[];
1444
-      StringSplit(mappingSymbol,';',symbollist);
1432
+      StringSplit(mappingSymbol,',',symbollist);
1445
       for(int i=0; i<ArraySize(symbollist); i++)
1433
       for(int i=0; i<ArraySize(symbollist); i++)
1446
         {
1434
         {
1447
          string symbolPairs[];
1435
          string symbolPairs[];
1448
-         StringSplit(symbollist[i],',',symbolPairs);
1436
+         StringSplit(symbollist[i],':',symbolPairs);
1449
          if(ArraySize(symbolPairs)==2)
1437
          if(ArraySize(symbolPairs)==2)
1450
            {
1438
            {
1451
             if(symbol==symbolPairs[0])
1439
             if(symbol==symbolPairs[0])
@@ -1473,16 +1461,16 @@ double getLotSize(string symbol,double masterAccountBalance,double masterLot,int
1473
      {
1461
      {
1474
       lotsize = NormalizeDouble(masterLot*mult,2);
1462
       lotsize = NormalizeDouble(masterLot*mult,2);
1475
      }
1463
      }
1464
+//else
1465
+//   if(lotoption == Balance)
1466
+//     {
1467
+//      lotsize=((AccountInfoDouble(ACCOUNT_BALANCE)/masterAccountBalance)*masterLot)*Bmult;
1468
+//     }
1476
    else
1469
    else
1477
-      if(lotoption == Balance)
1470
+      if(lotoption == slaveLotCal)
1478
         {
1471
         {
1479
-         lotsize=((AccountInfoDouble(ACCOUNT_BALANCE)/masterAccountBalance)*masterLot)*Bmult;
1472
+         lotsize = masterLot * (recoveryAmount / maxDd);
1480
         }
1473
         }
1481
-      else
1482
-         if(lotoption == slaveLotCal)
1483
-           {
1484
-            lotsize = masterLot * (maxDd / recoveryAmount);
1485
-           }
1486
 
1474
 
1487
 
1475
 
1488
    Print("Before Lot Size: ",lotsize);
1476
    Print("Before Lot Size: ",lotsize);
@@ -1520,71 +1508,7 @@ double getLotSize(string symbol,double masterAccountBalance,double masterLot,int
1520
 
1508
 
1521
    return lotsize;
1509
    return lotsize;
1522
   }
1510
   }
1523
-//+------------------------------------------------------------------+
1524
-//|                                                                  |
1525
-//+------------------------------------------------------------------+
1526
-void adminHeartBeat()
1527
-  {
1528
-
1529
-   string headers = "apikey:"+localApiKey+"\r\naccept: */* \r\nContent-Type: application/json\r\nUser-Agent: MetaTraderApi";
1530
 
1511
 
1531
-   string url =localHB_req_link;// Request_link+(string)accountNumber;
1532
-
1533
-   bool isPost;
1534
-   int timeout = 100000;
1535
-   string lastConnected=TimeToString(TimeCurrent());
1536
-
1537
-   StringReplace(lastConnected,".","-");
1538
-   StringReplace(lastConnected," ","T");
1539
-   string gmtTime=TimeToString(TimeGMT());
1540
-
1541
-   string jsonData="{\"sLogin\":\""+(string)accountNumber+"\",\"sServer\":\""+clientServer+"\",\"sVersion\":\"5\" ,\"sLastConnected\":\""+gmtTime+"\"}";//\",\"url\":"+"\""+url+"\""+headers+"}";
1542
-
1543
-   uchar data[];
1544
-   StringToCharArray(jsonData, data, 0, StringLen(jsonData));
1545
-
1546
-// Print("Making the heart beat request to the local host");
1547
-
1548
-   POST_function(url,headers,timeout,data,isPost);
1549
-
1550
-  }
1551
-//+------------------------------------------------------------------+
1552
-//|                                                                  |
1553
-//+------------------------------------------------------------------+
1554
-bool POST_function(string url, string headers, int timeout, uchar &data[], bool &IsPost)
1555
-  {
1556
-   ResetLastError();              // clear previous error
1557
-   static int lastErrorPrinted = 0;
1558
-   uchar result[];                // use uchar for WebRequest result
1559
-   string resultHeaders;
1560
-
1561
-   int res = WebRequest("POST", url, headers, timeout, data, result, resultHeaders);
1562
-
1563
-   if(res == 200 || res == 201)
1564
-     {
1565
-      Print("***Request success. HTTP response code POST: ", res);
1566
-      string result_string = CharArrayToString(result);
1567
-      Print("content POST: ", result_string);
1568
-      lastErrorPrinted = 0;       // reset remembered error on success
1569
-      IsPost = true;
1570
-      return true;
1571
-     }
1572
-   else
1573
-     {
1574
-      int err = GetLastError();   // read the error once
1575
-      // only print when there's a real error and it's different from last time
1576
-      if(err != 0 && err != lastErrorPrinted)
1577
-        {
1578
-         Print("Get last error: ", err);
1579
-         Print("***Request failed. HTTP response code: ", res);
1580
-         string result_string = CharArrayToString(result);
1581
-         Print("content: ", result_string);
1582
-         lastErrorPrinted = err;  // remember this error so we don't spam it
1583
-        }
1584
-      IsPost = false;
1585
-      return false;
1586
-     }
1587
-  }
1588
 //+------------------------------------------------------------------+
1512
 //+------------------------------------------------------------------+
1589
 //|                                                                  |
1513
 //|                                                                  |
1590
 //+------------------------------------------------------------------+
1514
 //+------------------------------------------------------------------+

BIN
master/localHedgingMasterCopierMt5.ex5


BIN
master/localHedgingMasterCopierMt5.mq5