Kaynağa Gözat

removed the heart beat calling and inputs re-arranged

WajeehSaqib-MQL 7 ay önce
ebeveyn
işleme
5336487704

BIN
client/localHedgingClientCopierMt5.ex5


+ 24 - 100
client/localHedgingClientCopierMt5.mq5

@@ -114,8 +114,8 @@ enum lot_option
   {
    fix, //Fixed Lot
    mul, //Multiplied Lot
-   Balance, // Balance Base Multiplier
-   slaveLotCal,
+// Balance, // Balance Base Multiplier
+   slaveLotCal,   // Slave Lot formula based
   };
 enum tradeCopy_type
   {
@@ -133,22 +133,19 @@ sinput       string                  string_0                  = "<><><><><><> G
 input        int                     slip                     = 5;               // Master Order Variation in Pips
 input        int                     sec                      = 10;              // Master Order Expired After Seconds
 input        tradeCopy_type          tradeType                = buySell;         // Trades To Copy
-input        lot_option              lotoption                = slaveLotCal;     // Lot Option
-input        double                  mult                     = 1.0;             // Multiplier (for Client)
-input        double                  fixed                    = 0.1;             // Fixed Lot (for Client)
-input        double                  Bmult                    = 1;               // Balance Multiplier (for Client)
-input        double                  recoveryAmount           = 3000;            // Recovery Amount (for Client Lot)
-input        double                  maxDd                    = 8000;            // Max DrawDown (for Client Lot)
 input        string                  suffix                   = "";              // Suffix
 input        string                  symbolExclude            = "";              // Symbol to Exclude
 input        string                  prefix                   = "";              // Prefix
-input        string                  mappingSymbol            = "GOLD,XAUUSD;bitcoin,BTCUSD"; // Mapping Pairs Inp,Out;Inp,Out
+input        string                  mappingSymbol            = "GOLD:XAUUSD,bitcoin:BTCUSD"; // Mapping Pairs Inp:Out,Inp:Out
+
+sinput       string                  string_1                  = "<><><><><><> Lotsize SETTINGS <><><><><><>";   //__
+input        lot_option              lotoption                = mul;             // Lot Option
+input        double                  fixed                    = 0.1;             // Fixed Lot (for Client)
+input        double                  mult                     = 1.0;             // Multiplier (for Client)
+double                  Bmult                    = 1;               // Balance Multiplier (for Client)
+input        double                  recoveryAmount           = 3000;            // Recovery Amount (for Client Lot)
+input        double                  maxDd                    = 8000;            // Max drawdown prop (for Client Lot)
 
-// Heart Beat
-sinput       string                  string_1                  = "<><><><><><> HeartBeat Setting <><><><><><>";   //__
-input        string                  clientServer             = "";              // Master Server
-input        string                  localApiKey              = "U2FsdGVkX18vBY4H1uzQiZwuh8B++8VBtCGJ3yGr2XPII0qCodmfuhjssKu5oug1J4e97bkwPtDQLi4py1OODQ=="; // Local API Key
-input        string                  localHB_req_link         = "http://localhost/api/slastConnected"; // Request Link For LastConnected
 
 //+------------------------------------------------------------------+
 //|                                                                  |
@@ -163,7 +160,7 @@ bool       contractChk   = true;//Contract Checking
 bool doReversal = true; // Reverse Trades
 bool fileLastEmpty=false;
 long accountNumber=AccountInfoInteger(ACCOUNT_LOGIN);
-int counter=0,testCounterVar=0;
+
 order order_array[];
 datetime lastModified1=0;
 long lastFileSize1=0;
@@ -647,18 +644,6 @@ void readData()
          if(lastModified==lastFileModified && fileSize==lastFileSize) // lastModified==lastFileModified && fileSize==lastFileSize
            {
             FileClose(filehandle);
-            if(counter>=count1 && TerminalInfoInteger(TERMINAL_CONNECTED))
-              {
-               if(testCounterVar==testCounter)
-                 {
-                  testCounterVar=0;
-                 }
-               adminHeartBeat();
-               counter=0;
-
-              }
-            counter++;
-            testCounterVar++;
            }
          else
            {
@@ -741,12 +726,15 @@ void readData()
                   if(PositionSelectByTicket(ticket))
                     {
                      if(history_ticket_present(PositionGetInteger(POSITION_MAGIC)))
+                       {
+                        // Print(" inside Array size 1: ",ticket);
                         if(!trade.PositionClose(ticket))
                           {
                            Print(" Order Close Error on No Master Trade: "+IntegerToString(GetLastError()));
                           }
                         else
                            Print(" ------------- Order Close by empty array ------------------ ");
+                       }
                     }
                  }
               }
@@ -1441,11 +1429,11 @@ string getSymbol(string symbol)
    if(mappingSymbol!="")
      {
       string symbollist[];
-      StringSplit(mappingSymbol,';',symbollist);
+      StringSplit(mappingSymbol,',',symbollist);
       for(int i=0; i<ArraySize(symbollist); i++)
         {
          string symbolPairs[];
-         StringSplit(symbollist[i],',',symbolPairs);
+         StringSplit(symbollist[i],':',symbolPairs);
          if(ArraySize(symbolPairs)==2)
            {
             if(symbol==symbolPairs[0])
@@ -1473,16 +1461,16 @@ double getLotSize(string symbol,double masterAccountBalance,double masterLot,int
      {
       lotsize = NormalizeDouble(masterLot*mult,2);
      }
+//else
+//   if(lotoption == Balance)
+//     {
+//      lotsize=((AccountInfoDouble(ACCOUNT_BALANCE)/masterAccountBalance)*masterLot)*Bmult;
+//     }
    else
-      if(lotoption == Balance)
+      if(lotoption == slaveLotCal)
         {
-         lotsize=((AccountInfoDouble(ACCOUNT_BALANCE)/masterAccountBalance)*masterLot)*Bmult;
+         lotsize = masterLot * (recoveryAmount / maxDd);
         }
-      else
-         if(lotoption == slaveLotCal)
-           {
-            lotsize = masterLot * (maxDd / recoveryAmount);
-           }
 
 
    Print("Before Lot Size: ",lotsize);
@@ -1520,71 +1508,7 @@ double getLotSize(string symbol,double masterAccountBalance,double masterLot,int
 
    return lotsize;
   }
-//+------------------------------------------------------------------+
-//|                                                                  |
-//+------------------------------------------------------------------+
-void adminHeartBeat()
-  {
-
-   string headers = "apikey:"+localApiKey+"\r\naccept: */* \r\nContent-Type: application/json\r\nUser-Agent: MetaTraderApi";
 
-   string url =localHB_req_link;// Request_link+(string)accountNumber;
-
-   bool isPost;
-   int timeout = 100000;
-   string lastConnected=TimeToString(TimeCurrent());
-
-   StringReplace(lastConnected,".","-");
-   StringReplace(lastConnected," ","T");
-   string gmtTime=TimeToString(TimeGMT());
-
-   string jsonData="{\"sLogin\":\""+(string)accountNumber+"\",\"sServer\":\""+clientServer+"\",\"sVersion\":\"5\" ,\"sLastConnected\":\""+gmtTime+"\"}";//\",\"url\":"+"\""+url+"\""+headers+"}";
-
-   uchar data[];
-   StringToCharArray(jsonData, data, 0, StringLen(jsonData));
-
-// Print("Making the heart beat request to the local host");
-
-   POST_function(url,headers,timeout,data,isPost);
-
-  }
-//+------------------------------------------------------------------+
-//|                                                                  |
-//+------------------------------------------------------------------+
-bool POST_function(string url, string headers, int timeout, uchar &data[], bool &IsPost)
-  {
-   ResetLastError();              // clear previous error
-   static int lastErrorPrinted = 0;
-   uchar result[];                // use uchar for WebRequest result
-   string resultHeaders;
-
-   int res = WebRequest("POST", url, headers, timeout, data, result, resultHeaders);
-
-   if(res == 200 || res == 201)
-     {
-      Print("***Request success. HTTP response code POST: ", res);
-      string result_string = CharArrayToString(result);
-      Print("content POST: ", result_string);
-      lastErrorPrinted = 0;       // reset remembered error on success
-      IsPost = true;
-      return true;
-     }
-   else
-     {
-      int err = GetLastError();   // read the error once
-      // only print when there's a real error and it's different from last time
-      if(err != 0 && err != lastErrorPrinted)
-        {
-         Print("Get last error: ", err);
-         Print("***Request failed. HTTP response code: ", res);
-         string result_string = CharArrayToString(result);
-         Print("content: ", result_string);
-         lastErrorPrinted = err;  // remember this error so we don't spam it
-        }
-      IsPost = false;
-      return false;
-     }
-  }
 //+------------------------------------------------------------------+
 //|                                                                  |
 //+------------------------------------------------------------------+

BIN
master/localHedgingMasterCopierMt5.ex5


BIN
master/localHedgingMasterCopierMt5.mq5