Procházet zdrojové kódy

Ticket: 5133 Dynamic Message Format(Colon & Space)

Huzaifa-MQLDev před 4 měsíci
rodič
revize
7b9e51b858
2 změnil soubory, kde provedl 52 přidání a 9 odebrání
  1. binární
      blTelegramToMT4.ex4
  2. 52 9
      blTelegramToMT4.mq4

binární
blTelegramToMT4.ex4


+ 52 - 9
blTelegramToMT4.mq4

@@ -34,7 +34,7 @@ input       double               lotSize               = 0.1;
34
 //| Expert initialization function                                   |
34
 //| Expert initialization function                                   |
35
 //+------------------------------------------------------------------+
35
 //+------------------------------------------------------------------+
36
 // Global Variables
36
 // Global Variables
37
-string      url1      = "http://myapp.local";///"http://127.0.0.1";
37
+string      url1      = "http://127.0.0.1"; // "http://myapp.local";
38
 string      header    = "Content-Type: application/json\r\nAccept: application/json\r\n";
38
 string      header    = "Content-Type: application/json\r\nAccept: application/json\r\n";
39
 
39
 
40
 string symbolChart[];
40
 string symbolChart[];
@@ -391,20 +391,29 @@ void message(string &result[], string message, int message_id)
391
             if((StringFind(result[i], "sl", 0) != -1))
391
             if((StringFind(result[i], "sl", 0) != -1))
392
               {
392
               {
393
                string tempSl[];
393
                string tempSl[];
394
+               StringReplace(result[i],":", " ");
394
                result[i] = trimString(result[i]);
395
                result[i] = trimString(result[i]);
396
+               result[i] = spaceRemove(result[i]);
395
                //Print(" Sl String: ", result[i]);
397
                //Print(" Sl String: ", result[i]);
396
-               StringSplit(result[i], ':', tempSl);
398
+               StringSplit(result[i], ' ', tempSl);
397
                if(ArraySize(tempSl) >= 2)
399
                if(ArraySize(tempSl) >= 2)
398
                   sl = (double) tempSl[1];
400
                   sl = (double) tempSl[1];
399
                Print("Sl : ", sl);
401
                Print("Sl : ", sl);
400
               }
402
               }
401
             if((StringFind(result[i], "tp", 0) != -1))
403
             if((StringFind(result[i], "tp", 0) != -1))
402
               {
404
               {
403
-               // Print("Tp : ", result[i], " index is: ", i);
405
+               Print("Tp : ", result[i], " index is: ", i);
404
                string tempTp[];
406
                string tempTp[];
407
+               StringReplace(result[i],":", " ");
405
                result[i] = trimString(result[i]);
408
                result[i] = trimString(result[i]);
406
-               StringSplit(result[i], ':', tempTp);
409
+               result[i] = spaceRemove(result[i]);
410
+               Print("Tp After String Replace : ", result[i], " index is: ", i);
411
+               StringSplit(result[i], ' ', tempTp);
407
                //double tp = (double) tempTp[1];
412
                //double tp = (double) tempTp[1];
413
+               for(int j=0 ; j < ArraySize(tempTp); j++)
414
+                 {
415
+                  Print(" Data is: ", tempTp[j]);
416
+                 }
408
                if(ArraySize(tempTp) >= 2)
417
                if(ArraySize(tempTp) >= 2)
409
                   tp = (double) tempTp[1];
418
                   tp = (double) tempTp[1];
410
                Print("Tp : ", tp);
419
                Print("Tp : ", tp);
@@ -491,19 +500,53 @@ void addtoMessageStructure(int message_id,string message)
491
 string trimString(string inputt)
500
 string trimString(string inputt)
492
   {
501
   {
493
 // Remove spaces from the left and right sides
502
 // Remove spaces from the left and right sides
494
-   int start = 0;
503
+   int startt = 0;
495
    int end = StringLen(inputt) - 1;
504
    int end = StringLen(inputt) - 1;
496
 
505
 
497
 // Find the first non-space character
506
 // Find the first non-space character
498
-   while(start <= end && StringGetCharacter(inputt, start) == ' ')
499
-      start++;
507
+   while(startt <= end && StringGetCharacter(inputt, startt) == ' ')
508
+      startt++;
500
 
509
 
501
 // Find the last non-space character
510
 // Find the last non-space character
502
-   while(end >= start && StringGetCharacter(inputt, end) == ' ')
511
+   while(end >= startt && StringGetCharacter(inputt, end) == ' ')
503
       end--;
512
       end--;
504
 
513
 
505
 // Extract the substring without leading or trailing spaces
514
 // Extract the substring without leading or trailing spaces
506
-   return StringSubstr(inputt, start, end - start + 1);
515
+   return StringSubstr(inputt, startt, end - startt + 1);
516
+  }
517
+//+------------------------------------------------------------------+
518
+//|                                                                  |
519
+//+------------------------------------------------------------------+
520
+string spaceRemove(string inputt)
521
+  {
522
+   int len = StringLen(inputt);
523
+   string out = "";
524
+   bool inSpace = false;
525
+
526
+   for(int i = 0; i < len; i++)
527
+     {
528
+      ushort ch = StringGetCharacter(inputt, i);
529
+      // treat space, tab, CR, LF as whitespace
530
+      bool isSpace = (ch == 32 || ch == 9 || ch == 10 || ch == 13);
531
+
532
+      if(isSpace)
533
+        {
534
+         // mark that we are inside a whitespace run, but don't append yet
535
+         inSpace = true;
536
+         continue;
537
+        }
538
+
539
+      // when we hit a non-space after whitespace, add a single space (if out not empty)
540
+      if(inSpace && StringLen(out) > 0)
541
+         out += " ";
542
+
543
+      // append the non-space character (use substr to preserve unicode chars)
544
+      out += StringSubstr(inputt, i, 1);
545
+
546
+      inSpace = false;
547
+     }
548
+
549
+   return(out);
507
   }
550
   }
508
 //+------------------------------------------------------------------+
551
 //+------------------------------------------------------------------+
509
 //|                                                                  |
552
 //|                                                                  |