Skip to content

Commit ff6b28e

Browse files
committed
adjust status and logfile names
1 parent 9ba86bb commit ff6b28e

File tree

7 files changed

+48
-53
lines changed

7 files changed

+48
-53
lines changed

mql40/experts/ZigZag EA.mq4

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ extern double Lots = 0.1;
137137
#include <rsf/experts/instance/RestoreInstance.mqh>
138138
#include <rsf/experts/instance/SetInstanceId.mqh>
139139

140-
#include <rsf/experts/log/GetLogFilename.mqh>
140+
#include <rsf/experts/log/GetLogFileName.mqh>
141141

142142
#include <rsf/experts/metric/GetMT4SymbolDefinition.mqh>
143143
#include <rsf/experts/metric/RecordMetrics.mqh>
@@ -154,8 +154,8 @@ extern double Lots = 0.1;
154154
#include <rsf/experts/status/StatusDescription.mqh>
155155

156156
#include <rsf/experts/status/file/FindStatusFile.mqh>
157-
#include <rsf/experts/status/file/GetStatusFilename.mqh>
158-
#include <rsf/experts/status/file/SetStatusFilename.mqh>
157+
#include <rsf/experts/status/file/GetStatusFileName.mqh>
158+
#include <rsf/experts/status/file/SetStatusFileName.mqh>
159159
#include <rsf/experts/status/file/ReadStatus.General.mqh>
160160
#include <rsf/experts/status/file/ReadStatus.HistoryRecord.mqh>
161161
#include <rsf/experts/status/file/ReadStatus.OpenPosition.mqh>
@@ -997,7 +997,7 @@ bool SaveStatus() {
997997
}
998998
else if (IsTestInstance()) return(true); // don't modify the status file of a finished test
999999

1000-
string section="", separator="", file=GetStatusFilename();
1000+
string section="", separator="", file=GetStatusFileName();
10011001
bool fileExists = IsFile(file, MODE_SYSTEM);
10021002
if (!fileExists) separator = CRLF; // an empty line separator
10031003
SS.All(); // update trade stats and global string representations
@@ -1065,7 +1065,7 @@ bool ReadStatus() {
10651065
if (IsLastError()) return(false);
10661066
if (!instance.id) return(!catch("ReadStatus(1) "+ instance.name +" illegal value of instance.id: "+ instance.id, ERR_ILLEGAL_STATE));
10671067

1068-
string section="", file=GetStatusFilename();
1068+
string section="", file=GetStatusFileName();
10691069
if (file == "") return(!catch("ReadStatus(2) "+ instance.name +" status file not found", ERR_RUNTIME_ERROR));
10701070
if (!IsFile(file, MODE_SYSTEM)) return(!catch("ReadStatus(3) "+ instance.name +" file \""+ file +"\" not found", ERR_FILE_NOT_FOUND));
10711071

@@ -1215,16 +1215,6 @@ bool SynchronizeStatus() {
12151215
}
12161216

12171217

1218-
/**
1219-
* Return a distinctive instance detail to be inserted in the status/log filename.
1220-
*
1221-
* @return string
1222-
*/
1223-
string GetStatusFilenameData() {
1224-
return("P="+ ZigZag.Periods);
1225-
}
1226-
1227-
12281218
/**
12291219
* Whether the specified ticket exists in the local history of closed positions.
12301220
*

mql40/include/rsf/experts/init.mqh

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ int onInit() {
2323
int onInitUser() {
2424
if (ValidateInputs.ID()) { // TRUE: a valid instance id was specified
2525
if (RestoreInstance()) { // try to reload the given instance
26-
logInfo("onInitUser(1) "+ instance.name +" restored in status \""+ StatusDescription(instance.status) +"\" from file \""+ GetStatusFilename(true) +"\"");
26+
logInfo("onInitUser(1) "+ instance.name +" restored in status \""+ StatusDescription(instance.status) +"\" from file \""+ GetStatusFileName(true) +"\"");
2727
}
2828
}
2929
else if (StrTrim(Instance.ID) == "") { // no instance id was specified
@@ -34,7 +34,7 @@ int onInitUser() {
3434
instance.created = GetLocalTime(); // local system time (also in tester)
3535
instance.started = TimeServer(); // trade server time (modeled in tester)
3636
instance.status = ifInt(__isTesting, STATUS_WAITING, STATUS_STOPPED);
37-
SetStatusFilename();
37+
SetStatusFileName();
3838
logInfo("onInitUser(2) instance "+ instance.name +" created");
3939
SaveStatus();
4040
}
@@ -88,7 +88,7 @@ int onInitSymbolChange() {
8888
int onInitTemplate() {
8989
if (RestoreVolatileStatus()) { // an instance id was found and restored
9090
if (RestoreInstance()) { // the instance was restored
91-
logInfo("onInitTemplate(1) "+ instance.name +" restored in status \""+ StatusDescription(instance.status) +"\" from file \""+ GetStatusFilename(true) +"\"");
91+
logInfo("onInitTemplate(1) "+ instance.name +" restored in status \""+ StatusDescription(instance.status) +"\" from file \""+ GetStatusFileName(true) +"\"");
9292
}
9393
return(last_error);
9494
}
@@ -104,7 +104,7 @@ int onInitTemplate() {
104104
int onInitRecompile() {
105105
if (RestoreVolatileStatus()) { // same as for onInitTemplate()
106106
if (RestoreInstance()) {
107-
logInfo("onInitRecompile(1) "+ instance.name +" restored in status \""+ StatusDescription(instance.status) +"\" from file \""+ GetStatusFilename(true) +"\"");
107+
logInfo("onInitRecompile(1) "+ instance.name +" restored in status \""+ StatusDescription(instance.status) +"\" from file \""+ GetStatusFileName(true) +"\"");
108108
}
109109
return(last_error);
110110
}
@@ -119,7 +119,7 @@ int onInitRecompile() {
119119
*/
120120
int afterInit() {
121121
if (__isTesting || !IsTestInstance()) { // open the log file (flushes the log buffer) except if in a finished test
122-
string filename = GetLogFilename();
122+
string filename = GetLogFileName();
123123
if (filename == "") return(last_error);
124124
if (!SetLogfile(filename)) return(catch("afterInit(1)"));
125125
}
@@ -132,8 +132,3 @@ int afterInit() {
132132
StoreVolatileStatus(); // store the instance id for template reload/restart/recompilation etc.
133133
return(catch("afterInit(2)"));
134134
}
135-
136-
137-
#import "rsfMT4Expander.dll"
138-
string GetStatusFilenameData(); // A no-op in the Expander allows the user to optionally provide his own data.
139-
#import

mql40/include/rsf/experts/log/GetLogFilename.mqh renamed to mql40/include/rsf/experts/log/GetLogFileName.mqh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
*
44
* @return string - filename or an empty string in case of errors
55
*/
6-
string GetLogFilename() {
7-
string name = GetStatusFilename();
6+
string GetLogFileName() {
7+
string name = GetStatusFileName();
88
if (name == "") return("");
99
return(StrLeftTo(name, ".", -1) +".log");
1010
}

mql40/include/rsf/experts/status/file/FindStatusFile.mqh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
/**
2-
* Find an existing status file for the specified instance.
2+
* Find an existing status file for the specified instance id. Finds any file matching
3+
*
4+
* "<program-name>, <symbol>,* id=<instance-id>.set" (no matter what the custom name is)
5+
*
6+
* but doesn't scan subdirectories. The EA will use whatever was found for status and logfile.
7+
* A more strict pattern is used for name generation in SetStatusFileName().
38
*
49
* @param int instanceId - instance id
510
* @param bool isTest - whether the instance is a test instance
@@ -13,7 +18,7 @@ string FindStatusFile(int instanceId, bool isTest) {
1318

1419
string sandboxDir = GetMqlSandboxPath() +"\\";
1520
string statusDir = "presets\\"+ ifString(isTest, "Tester", GetAccountCompanyId()) +"\\";
16-
string basePattern = ProgramName() +", "+ Symbol() +",* id="+ StrPadLeft(""+ instanceId, 3, "0") +".set"; // matches files with and w/o user-specified data in the name
21+
string basePattern = ProgramName() +", "+ Symbol() +",* id="+ StrPadLeft(""+ instanceId, 3, "0") +".set"; // matches files with custom names
1722
string pathPattern = sandboxDir + statusDir + basePattern;
1823

1924
string result[];

mql40/include/rsf/experts/status/file/GetStatusFilename.mqh renamed to mql40/include/rsf/experts/status/file/GetStatusFileName.mqh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
*
77
* @return string - filename or an empty string in case of errors
88
*/
9-
string GetStatusFilename(bool relative = false) {
9+
string GetStatusFileName(bool relative = false) {
1010
relative = relative!=0;
1111

1212
if (status.filename == "") {
13-
status.filename = FindStatusFile(instance.id, instance.isTest); // intentionally trigger an error if instance.id is not set
13+
status.filename = FindStatusFile(instance.id, instance.isTest);
1414
if (status.filename == "") return("");
1515
}
1616

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* Generates and initializes the name of the status file. Requires 'instance.id' and 'instance.created' to be set.
3+
*
4+
* If the expert implements GetStatusFileNameData() the returned string will be inserted into the resulting
5+
* filename. This can be used to insert custom data into the name (e.g. SL/TP vars or trading modes).
6+
*
7+
* @return bool - success status
8+
*/
9+
bool SetStatusFileName() {
10+
if (status.filename != "") return(!catch("SetStatusFileName(1) "+ instance.name +" cannot modify an already set status filename: \""+ status.filename +"\"", ERR_ILLEGAL_STATE));
11+
if (!instance.id) return(!catch("SetStatusFileName(2) "+ instance.name +" illegal value of instance.id: 0", ERR_ILLEGAL_STATE));
12+
if (!instance.created) return(!catch("SetStatusFileName(3) "+ instance.name +" cannot create status filename (instance.created not set)", ERR_ILLEGAL_STATE));
13+
14+
string userData = StrTrim(GetStatusFileNameData());
15+
if (userData != "") userData = userData +", ";
16+
17+
string directory = "presets\\"+ ifString(IsTestInstance(), "Tester", GetAccountCompanyId()) +"\\";
18+
string baseName = ProgramName() +", "+ Symbol() +","+ PeriodDescription() +" "+ userData + GmtTimeFormat(instance.created, "%Y.%m.%d %H.%M") +", id="+ StrPadLeft(instance.id, 3, "0") +".set";
19+
status.filename = directory + baseName;
20+
21+
return(!catch("SetStatusFileName(4)"));
22+
}
23+
24+
25+
#import "rsfMT4Expander.dll"
26+
string GetStatusFileNameData(); // a no-op in the Expander allows optional override in MQL
27+
#import

mql40/include/rsf/experts/status/file/SetStatusFilename.mqh

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)