소스 검색

Ticket: 5133 Dynamic Message Format(Colon & Space)

Huzaifa-MQLDev 4 달 전
부모
커밋
7b9e51b858
2개의 변경된 파일52개의 추가작업 그리고 9개의 파일을 삭제
  1. BIN
      blTelegramToMT4.ex4
  2. 52 9
      blTelegramToMT4.mq4

BIN
blTelegramToMT4.ex4


+ 52 - 9
blTelegramToMT4.mq4

@@ -34,7 +34,7 @@ input       double               lotSize               = 0.1;
34 34
 //| Expert initialization function                                   |
35 35
 //+------------------------------------------------------------------+
36 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 38
 string      header    = "Content-Type: application/json\r\nAccept: application/json\r\n";
39 39
 
40 40
 string symbolChart[];
@@ -391,20 +391,29 @@ void message(string &result[], string message, int message_id)
391 391
             if((StringFind(result[i], "sl", 0) != -1))
392 392
               {
393 393
                string tempSl[];
394
+               StringReplace(result[i],":", " ");
394 395
                result[i] = trimString(result[i]);
396
+               result[i] = spaceRemove(result[i]);
395 397
                //Print(" Sl String: ", result[i]);
396
-               StringSplit(result[i], ':', tempSl);
398
+               StringSplit(result[i], ' ', tempSl);
397 399
                if(ArraySize(tempSl) >= 2)
398 400
                   sl = (double) tempSl[1];
399 401
                Print("Sl : ", sl);
400 402
               }
401 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 406
                string tempTp[];
407
+               StringReplace(result[i],":", " ");
405 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 412
                //double tp = (double) tempTp[1];
413
+               for(int j=0 ; j < ArraySize(tempTp); j++)
414
+                 {
415
+                  Print(" Data is: ", tempTp[j]);
416
+                 }
408 417
                if(ArraySize(tempTp) >= 2)
409 418
                   tp = (double) tempTp[1];
410 419
                Print("Tp : ", tp);
@@ -491,19 +500,53 @@ void addtoMessageStructure(int message_id,string message)
491 500
 string trimString(string inputt)
492 501
   {
493 502
 // Remove spaces from the left and right sides
494
-   int start = 0;
503
+   int startt = 0;
495 504
    int end = StringLen(inputt) - 1;
496 505
 
497 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 510
 // Find the last non-space character
502
-   while(end >= start && StringGetCharacter(inputt, end) == ' ')
511
+   while(end >= startt && StringGetCharacter(inputt, end) == ' ')
503 512
       end--;
504 513
 
505 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
 //|                                                                  |