forked from vzhomeexperiments/WatchDog
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWatchDog.mq4
96 lines (80 loc) · 2.31 KB
/
WatchDog.mq4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//+------------------------------------------------------------------+
//| WatchDog.mq4 |
//| Copyright, Kirill |
//| http://www.ForexBoat.com |
//+------------------------------------------------------------------+
#property copyright "Copyright, Kirill"
#property link "http://www.ForexBoat.com"
#property version "1.00"
#property strict
extern int AccountRow = 1;
extern int DelayMinutes = 5;
// AccountRow - Your favourites account number
// DelayMinutes - Delay in minutes, has to be greater than the chart timeframe
#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
datetime Old_Time=0;
bool is_reconect = true;
void OnInit()
{
Old_Time=iTime(NULL,0,0);
OnTick();
}
void OnTick()
{
if (!IsDllsAllowed())
{
Alert("Watchdog: DLLs not alllowed!");
return;
}
while (!IsStopped())
{
RefreshRates();
if (Old_Time == iTime(NULL,0,0)) is_reconect=true;
else is_reconect=false;
Old_Time=iTime(NULL,0,0);
if (is_reconect)
{
Print("Watchdog: The chart has not been updated in " + string(DelayMinutes) + " minutes. Initating reconnection procedure...");
Login(AccountRow);
}
Sleep(DelayMinutes*60*1000);
}
return;
}
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;
}