-
Notifications
You must be signed in to change notification settings - Fork 0
/
restrictions.mq4
145 lines (139 loc) · 6.79 KB
/
restrictions.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
//+------------------------------------------------------------------------------------+
// Initialisation Event Function
//+------------------------------------------------------------------------------------+
int OnInit()
{
// Check Licensing Restrictions
if( boolRestrictOnInit() ) return( INIT_FAILED );
// ...
return( INIT_SUCCEEDED ); // Initialisation complete
}
//+------------------------------------------------------------------------------------+
// Tick Event Function
//+------------------------------------------------------------------------------------+
void OnTick()
{
// Check Licensing Restrictions
if( boolRestrictOnTick() ) return;
/// ...
}
//+------------------------------------------------------------------------------------+
// Function to Test Restrictions during Initialisation
//+------------------------------------------------------------------------------------+
bool boolRestrictOnInit()
{
boolRestrictions =
boolRestrictExpiration ||
boolRestrictAccountNumber ||
boolRestrictAccountName ||
boolRestrictAccountServer ||
boolRestrictAccountCompany ||
boolRestrictDemoAccount ||
boolRestrictSymbols;
if( boolRestrictions )
{
boolRestrictionsUnverified = true;
if( (bool) TerminalInfoInteger( TERMINAL_CONNECTED ) )
{
long longAccountNumber = AccountInfoInteger( ACCOUNT_LOGIN );
if( longAccountNumber > 0 )
{
if( boolRestrictAccountNumber )
{ if( longAccountNumber != longRestrictAccountNumber )
{ return( boolRestrictAlert() ); } }
if( boolRestrictAccountName )
{ if( AccountInfoString( ACCOUNT_NAME ) != strRestrictAccountName )
{ return( boolRestrictAlert() ); } }
if( boolRestrictAccountServer )
{ if( AccountInfoString( ACCOUNT_SERVER ) != strRestrictAccountServer )
{ return( boolRestrictAlert() ); } }
if( boolRestrictAccountCompany )
{ if( AccountInfoString( ACCOUNT_COMPANY ) != strRestrictAccountCompany )
{ return( boolRestrictAlert() ); } }
if( boolRestrictDemoAccount )
{ if( AccountInfoInteger( ACCOUNT_TRADE_MODE ) != ACCOUNT_TRADE_MODE_DEMO )
{ return( boolRestrictAlert() ); } }
if( boolRestrictSymbols() )
{ return( boolRestrictAlert() ); }
boolRestrictionsUnverified = false;
}
}
}
return( false );
}
//+------------------------------------------------------------------------------------+
// Function to Test Variations of Restricted Symbols
//+------------------------------------------------------------------------------------+
bool boolRestrictSymbols()
{
if( boolRestrictSymbols )
{
int intSymbolCount = ArraySize( strRestrictSymbols );
if( intSymbolCount == 0 ) return( false );
for( int i = 0; i < intSymbolCount; i++ )
{
if( StringFind( _Symbol, strRestrictSymbols[i] ) != WRONG_VALUE ) return( false );
int
intLen = StringLen( strRestrictSymbols[i] ),
intHalf = intLen / 2;
string
strLeft = StringSubstr( strRestrictSymbols[i], 0, intHalf ),
strRight = StringSubstr( strRestrictSymbols[i], intHalf, intLen - intHalf );
if( ( StringFind( _Symbol, strLeft ) != WRONG_VALUE ) &&
( StringFind( _Symbol, strRight ) != WRONG_VALUE ) )
return( false );
}
return( true );
}
return( false );
}
//+------------------------------------------------------------------------------------+
// Function to Test Expiration during Tick Events
//+------------------------------------------------------------------------------------+
bool boolRestrictOnTick()
{
if( boolRestrictions )
{
if( boolRestrictionsUnverified )
return( boolRestrictOnInit() );
if( boolRestrictExpiration && ( TimeCurrent() >= dtRestrictExpiration ) )
return( boolRestrictAlert() );
}
return( false );
}
// Function to Alert User of Licensing Restrictions and Remove Code from Execution
bool boolRestrictAlert()
{
if( boolRestrictAlert )
MessageBox( strRestrictAlertMessage, strRestrictAlertCaption, MB_ICONERROR );
ExpertRemove();
return( true );
}
//+------------------------------------------------------------------------------------+
// Variables for Handling of Licensing Restrictions
//+------------------------------------------------------------------------------------+
bool
boolRestrictExpiration = false, // Set to true, to use an Experation Date
boolRestrictAccountNumber = false, // Set to true for Restricting by Account Number
boolRestrictAccountName = false, // Set to true for Restricting by Account Name
boolRestrictAccountServer = false, // Set to true for Restricting by Account Server
boolRestrictAccountCompany = false, // Set to true for Restricting by Account Company
boolRestrictDemoAccount = false, // Set to true, to only allow Demo Accounts
boolRestrictSymbols = false, // Set to true, to only allow certain Symbols
boolRestrictAlert = true, // Display Alert Message when Restrictions apply
boolRestrictionsUnverified = false, // DO NOT CHANGE. For internal use only!
boolRestrictions = false; // DO NOT CHANGE. For internal use only!
datetime
dtRestrictExpiration = D'2017.03.31'; // Restricted by Expration Date
long
longRestrictAccountNumber = 123456789; // Restricted by Account Number
string
strRestrictAccountName = "Client Name", // Restricted by Account Name
strRestrictAccountServer = "Server Name", // Restricted by Account Server
strRestrictAccountCompany = "Company Name", // Restricted by Account Company
strRestrictSymbols[] = { "EURUSD", "GBPJPY", "NZDCAD" }, // Restricted Symbols
strRestrictAlertCaption = "Restrictions", // Alert Message Box Caption
strRestrictAlertMessage =
"ATTENTION! Due to Licensing Restrictions, code execution has been blocked!";
// Message to be used when Restrictions have been detected
//+------------------------------------------------------------------------------------+