s-ReConnect

Download script
Author: Copyright � 2009, Talex
s-ReConnect

This script is designed to act as an automated "watchdog" for your trading platform. Its primary purpose is to monitor your internet connection and ensure that your trading account remains active by automatically attempting to reconnect whenever a disconnection is detected.

Core Functionality

The tool works in a continuous loop, constantly checking the status of your connection to the server. If it detects that you are offline, it initiates a multi-step recovery process to bring your trading session back online without requiring manual intervention.

How It Works Step-by-Step

1. Continuous Monitoring The script runs in the background, periodically "pinging" the system to see if the connection is stable. As long as you are connected, it remains idle and does not interfere with your trading.

2. Automatic Troubleshooting If the connection drops, the script triggers a sequence of automated actions:

  • Server Rescan: It first attempts to refresh the server list to see if the platform can re-establish a handshake with the broker's server.
  • Account Reconnection: If a simple rescan doesn't work, the script takes a more proactive approach. It identifies the "Favorites" window within your trading terminal and simulates keyboard commands (like pressing "Home" and "Enter") to automatically select your primary account and attempt a fresh login.

3. Status Updates To keep you informed of its activity, the script provides real-time visual feedback directly on your chart:

  • It displays messages indicating when a connection is lost.
  • It provides updates during the "Rescan" and "Reconnection" phases.
  • Once the connection is successfully restored, it notifies you with a confirmation message including the current time.

4. Intelligent Timing To prevent the script from overwhelming your computer or the server with constant requests, it includes built-in delays (pauses) between each attempt. This ensures that the reconnection attempts happen at a steady, logical pace, increasing the likelihood of a successful recovery.

Summary for the User

Think of this script as an automated assistant that watches your connection 24/7. If your internet flickers or your account gets disconnected, the script automatically "reboots" your connection by refreshing the servers and relogging you into your favorite account, allowing you to maintain a stable trading environment with minimal effort.

10 Views
0 Downloads
0 Favorites
s-ReConnect
//+------------------------------------------------------------------+
//|                                                  s-ReConnect.mq4 |
//|                                          Copyright © 2009, Talex |
//|                                      talex.kaliningrad@gmail.com |
//+------------------------------------------------------------------+
//
// ÂÍÈÌÀÍÈÅ!!!
// Ïåðåïîäêëþ÷àåìûé ñ÷åò äîëæåí áûòü â îêíå "Èçáðàííîå", ñàìûì âåðõíèì
#property copyright "Copyright © 2009, Talex"
#property link      "talex.kaliningrad@gmail.com"
#import "user32.dll"
   int GetAncestor (int hWnd, int gaFlags);
   int GetDlgItem (int hDlg, int nIDDlgItem);
   int GetLastActivePopup (int hWndOwner);
   int PostMessageA (int hWnd, int Msg, int wParam, int lParam);
#import
#define WM_COMMAND         0x0111
#define WM_KEYDOWN         0x0100
#define VK_HOME            0x24
#define VK_ENTER           0x0D

int Pause=15000;                                    // ïàóçà 15 ñåêóíä
//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
void start() {
   bool flag=true;
//------------------------------------
   while(!IsStopped()) {
      Comment("ReConnect");
      if(!flag) {
         Print("Ñîåäèíåíèå âîññòàíîâëåíî. Âðåìÿ ÄÖ: ",TimeToStr(TimeCurrent()));
         Comment("ReConnect\nÑîåäèíåíèå âîññòàíîâëåíî.\nÂðåìÿ ÄÖ: ",TimeToStr(TimeCurrent()));
         flag=true;
      }
      while(!IsConnected()&&!IsStopped()) {         // åñëè ñîåäèíåíèÿ íåò
         if(flag) {
            Print("Íåò ñîåäèíåíèÿ ñ ñåðâåðîì. Âðåìÿ ÄÖ: ",TimeToStr(TimeCurrent()));
            Comment("ReConnect\nÍåò ñîåäèíåíèÿ ñ ñåðâåðîì.\nÂðåìÿ ÄÖ: ",TimeToStr(TimeCurrent()));
            flag=false;
         }
         Rescan();                                  // ïåðåñêàíèðóåì ñåðâåðû
         Sleep(Pause);                              // ïîäîæäåì êîííåêòà
         if(!IsConnected()) {                       // åñëè ñîåäèíåíèÿ íåò
            Reconnect();                            // ïåðåïîäêëþ÷àåì ñ÷åò
            Sleep(Pause);                           // ïîäîæäåì êîííåêòà
         }
      }
      Sleep(60000);
   }
   Comment("");
   return;
}
//+------------------------------------------------------------------+
//-----------------------------------------------------------------------+
// Ôóíêöèÿ ïîçâîëÿåò ïåðåñêàíèðîâàòü ñåðâåðû                             +
//-----------------------------------------------------------------------+
void Rescan() {
   int hwindow=GetAncestor(WindowHandle(Symbol(),Period()),2);// ïîëó÷àåì õåíäë ãëàâíîãî îêíà
//-----------------------------------
   Comment("ReConnect\n...ïåðåñêàíèðóåì ñåðâåðû");
	if(hwindow!=0) {                                 // íàøëè ãëàâíîå îêíî
	   PostMessageA(hwindow,WM_COMMAND,37400,0);     // ïîñûëàåì ñîîáùåíèå "ïåðåñêàíèðîâàòü ñåðâåðû" 
	}
	else Print("Rescan Error:",GetLastError());
	return;
}
//-----------------------------------------------------------------------+
//-----------------------------------------------------------------------+
// Ôóíêöèÿ ïîçâîëÿåò ïåðåïîäêëþ÷èòüñÿ ê ñ÷åòó                            +
//-----------------------------------------------------------------------+
void Reconnect() {
   int hwindow=WindowHandle(Symbol(),Period()),     // ïîëó÷àåì õåíäë îêíà ãðàôèêà
       hterminal=GetAncestor(hwindow,2);            // ïîëó÷àåì õåíäë ãëàâíîãî îêíà
//---------------------------- 
   Comment("ReConnect\n...ïåðåïîäêëþ÷àåì àêêàóíò");
   if(hterminal!=0) {                               // íàøëè ãëàâíîå îêíî
      hwindow=GetDlgItem(hterminal,0xE81C);
      hwindow=GetDlgItem(hwindow,0x52);
      hwindow=GetDlgItem(hwindow,0x8A70);           // íàøëè Èçáðàííîå îêíà Íàâèãàòîð
      PostMessageA(hwindow,WM_KEYDOWN,VK_HOME,0);   // âåðõíÿÿ ñòðî÷êà çàêëàäêè Èçáðàííîå îêíà Íàâèãàòîð
      PostMessageA(hwindow,WM_KEYDOWN,VK_ENTER,0);  // íàæàëè ëîãèí
      Sleep(1000);                                  // âûæäàëè
      hwindow=GetLastActivePopup(hterminal);        // íàøëè ôîðìó ëîãèíà
      PostMessageA(hwindow,WM_KEYDOWN,VK_ENTER,0);  // çàëîãèíèëèñü
   }
   else Print("Reconnect Error:",GetLastError());
   return;
}
//-----------------------------------------------------------------------+

Comments