ReConnecter

Download script
Author: Copyright � 2008, komposter
ReConnecter

This script is designed to automate the process of switching between different trading accounts on a MetaTrader platform. It acts as an automated "reconnector" that cycles through your saved accounts at regular intervals, ensuring that your terminal stays active on a specific account and moves to the next one once certain conditions are met.

Core Functionality

The primary purpose of this tool is to handle the repetitive task of logging into different accounts. Instead of a user manually selecting an account from the "Favorites" list every time, the script simulates human keyboard interactions to navigate the software's interface and perform the login actions automatically.

How it Works

The logic follows a specific sequence of events:

  • Continuous Monitoring: The script runs in a continuous loop. It checks your current account history to determine if there are active or completed trades.
  • Automated Navigation: Once the condition is met (or when starting), the script identifies the main navigation window of the trading platform. It then "presses" virtual keys—specifically moving to the top of your Favorites list, navigating down to a specific position, and hitting the "Enter" key to select that account.
  • Login Simulation: After selecting the account from the Favorites menu, the script detects the login pop-up window and sends another "Enter" command to complete the authentication process.
  • Timed Intervals: A user-defined pause (in seconds) is established. After the script successfully logs into an account, it waits for this specific amount of time before initiating the cycle again or moving to the next scheduled account.

Key Requirements for Operation

For this automation to function correctly, the environment requires:

  1. External Permissions: The software must have permission to interact with system-level files (DLLs) to capture and send keyboard commands.
  2. Favorites List: The script relies on your "Favorites" window in the Navigator panel. It navigates based on the numerical position of the accounts saved in that specific list.

In summary, this is a utility for traders who manage multiple accounts and want to automate the transition between them without having to manually click through menus every time a connection needs to be refreshed or swapped.

Orders Execution
Checks for the total of closed orders
Miscellaneous
It issuies visual alerts to the screen
5 Views
0 Downloads
0 Favorites
ReConnecter
//+------------------------------------------------------------------+
//|                                                  ReConnecter.mq4 | Ñêðèïò äëÿ ïåðèîäè÷åñêîãî ïåðåïîäêëþ÷åíèÿ ê ïåðâîìó ñ÷åòó èç "Èçáðàííîãî"
//|                                      Copyright © 2008, komposter | thanks to Getch (http://www.mql4.com/ru/users/getch)
//|                                      mailto:komposterius@mail.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, komposter"
#property link      "mailto:komposterius@mail.ru"

#property show_inputs
 
extern int Pause_sec = 600;	// ïàóçà ìåæäó ïåðåïîäêëþ÷åíèÿìè â ñåêóíäàõ

#include <WinUser32.mqh>
#import "user32.dll"
  int GetParent( int hWnd );
  int GetDlgItem( int hDlg, int nIDDlgItem );
  int GetLastActivePopup( int hWnd );
#import

#define VK_HOME 0x24
#define VK_DOWN 0x28
#define VK_ENTER 0x0D

#define PAUSE 1000

void init()
{
	start();
}

void start()
{
	if ( !IsDllsAllowed() )
	{
		Alert( "DLLs not alllowed!" );
		return;
	}

	while ( !IsStopped() )
	{
		Login(1);
		while ( !IsStopped() )
		{
			if ( OrdersHistoryTotal() > 0 ) break;
			Sleep(1000);
		}
		Print( "Óñïåøíîå ïîäêëþ÷åíèå ê ñ÷åòó #", AccountNumber(), "! Ñëåäóþùåå áóäåò ÷åðåç ", Pause_sec/60, " ìèíóò..." );

		Sleep(Pause_sec*1000);
	}
	return;
}

// Ïîäêëþ÷àåòñÿ ê ñ÷åòó, ðàñïîëîæåííîìó â ñòðî÷êå íîìåð Num â çàêëàäêå Èçáðàííîå îêíà Íàâèãàòîð
void Login( int Num )
{
   int hwnd = WindowHandle(Symbol(), Period());
   int hwnd_parent = 0;

   while (!IsStopped())
   {
      hwnd = GetParent(hwnd);
      if (hwnd == 0) break;
      hwnd_parent = hwnd;
   }

   if (hwnd_parent != 0)  // íàøëè ãëàâíîå îêíî
   {
     hwnd = GetDlgItem(hwnd_parent, 0xE81C); // íàøëè Èçáðàííîå îêíà Íàâèãàòîð
     hwnd = GetDlgItem(hwnd, 0x52);
     hwnd = GetDlgItem(hwnd, 0x8A70);

     PostMessageA(hwnd, WM_KEYDOWN, VK_HOME,0); // âåðõíÿÿ ñòðî÷êà çàêëàäêè Èçáðàííîå îêíà Íàâèãàòîð

     while (Num > 1)  
     {
       PostMessageA(hwnd, WM_KEYDOWN,VK_DOWN, 0); // ñìåñòèëèñü íà íóæíóþ ñòðî÷êó
       Num--;
     }

     PostMessageA(hwnd, WM_KEYDOWN, VK_ENTER, 0);  // ëîãèí
     Sleep(PAUSE);                                 // âûæäàëè

     hwnd = GetLastActivePopup(hwnd_parent);  // íàøëè ôîðìó ëîãèíà
     PostMessageA(hwnd, WM_KEYDOWN, VK_ENTER, 0); // çàëîãèíèëèñü
   }

	return;
}

Comments