你好。
在costum指标中,WindowScreenShot工作得很好。
在5分钟内创建一个图片,例如:10:15,10:20,等等。
还有
一段时间后 (随机的) 就 不工作了。不能写入文件。
为什么?
.... WindowScreenShot(filename, X_pixels, Y_pixels); int error=GetLastError(); if (error!=0) Alert(TimeToStr(TimeCurrent(),TIME_SECONDS)," trade_mode:", trade_mode, " T_ScreenShot FileWrite0 error: (",Symbol()," ",error,"): ",ErrorDescription(error)); int handle = FileOpen(filename, FILE_BIN|FILE_READ); if (handle>-1) { error=GetLastError(); if (error!=0) Alert(TimeToStr(TimeCurrent(),TIME_SECONDS)," trade_mode:", trade_mode, " T_ScreenShot FileWrite1 error: (",Symbol()," ",error,"): ",ErrorDescription(error)); FileClose(handle); } int lasterror=GetLastError(); if (lasterror!=0) Alert(TimeToStr(TimeCurrent(),TIME_SECONDS)," trade_mode:", trade_mode," T_ScreenShot, Schoted file open error: (",Symbol()," ",lasterror,"): ",ErrorDescription(lasterror));
这是因为你的代码,我们无法看到,被破坏了。 因为我们看不到你的代码,所以我们无法告诉你哪里出了问题。
错误=0
和lasterror =4103,无法打开文件
为什么?
错误=0
和lasterror =4103,无法打开文件
为什么?
文件名 是唯一的还是你重复使用的文件名?
唯一的
独特的
除非存在错误,否则不要调用GetLastError()。 WindowScreenShot(filename, X_pixels, Y_pixels); int error=GetLastError(); if (error!=0) Alert(TimeToStr(TimeCurrent(),TIME_SECONDS
什么是函数的返回值?我如何使用它们?- MQL4论坛 if( !WindowScreenShot(filename, X_pixels, Y_pixels) ){ int error=GetLastError(); Alert(TimeToStr(TimeCurrent(),TIME_SECONDS ... }
int handle = FileOpen(filename, FILE_BIN|FILE_READ); if (handle>-1) { error=GetLastError();
如果FileOpen 失败,handle == -1。你在没有错误时发出警报,在有错误时继续。
你如何使它们变得独特?
string timestamp = TimeToStr(TimeCurrent(),TIME_SECONDS); filename = filename + "_" + timestamp + ".gif";
在我看来,你最大的问题是你的错误处理,正如WHRoeder 已经提到的,你在报告错误方面做得很差,当/如果他们发生的话。 例如,你甚至没有检查WindowsScreenShot()是否工作......按照WHRoeder 的建议进行修改并再次测试。 你的文件名是不唯一的。你使用的是当前时间的hh:mm:ss,所以每天都有可能覆盖前一天的文件,如果该文件当时是打开的,这可能会导致4103错误。
相反 ......
string timestamp = TimeToStr(TimeCurrent(), TIME_DATE|TIME_SECONDS); filename = filename + "_" + timestamp + ".gif";
...将日期添加到文件名中。
在我看来,你最大的问题是你的错误处理,正如WHRoeder 已经提到的,当/如果发生错误时,你在报告错误方面做的很差。 例如,你甚至没有检查WindowsScreenShot()是否工作......按照WHRoeder 的建议进行修改并再次测试。 你的文件名是不唯一的。你使用的是当前时间的hh:mm:ss,所以每天都有可能覆盖前一天的文件,如果该文件当时是打开的,这可能会导致4103错误。
相反 ......
.将日期添加到文件名中。
lasterror是4103,继续
错误为0
.....,我退出MT4并重新运行,运行正常。
在 一段(随机)时间后 不起作用。不写文件。但 文件,文件名是唯一的。
为什么?
string timestamp = TimeToStr(TimeCurrent(),TIME_DATE )+"_"+TimeToStr(TimeCurrent(),TIME_SECONDS); for (int i= StringLen(timestamp); i>0; i--) if (StringFind(timestamp,":",i)!=-1 || StringFind(timestamp,".",i)!=-1) timestamp= StringSetChar(timestamp, i, '-'); string filename = mappa + CharToStr(92) + CharToStr(92) + Symbol(); filename = filename + "_" + timestamp + ".gif"; int error; if(!WindowScreenShot(filename, X_pixels, Y_pixels)) { error=GetLastError(); if (error!=0) Alert(TimeToStr(TimeCurrent(),TIME_SECONDS)," trade_mode:", trade_mode, " T_ScreenShot FileWrite0 error: (",Symbol()," ",error,"): ",ErrorDescription(error)); } Alert(filename); int handle = FileOpen(filename, FILE_BIN|FILE_READ); if (handle>-1) { error=GetLastError(); if (error!=0) Alert(TimeToStr(TimeCurrent(),TIME_SECONDS)," trade_mode:", trade_mode, " T_ScreenShot FileWrite1 error: (",Symbol()," ",error,"): ",ErrorDescription(error)); FileClose(handle); } else { int lasterror=GetLastError(); if (lasterror!=0) Alert(TimeToStr(TimeCurrent(),TIME_SECONDS)," trade_mode:", trade_mode," T_ScreenShot, Schoted file open error: (",Symbol()," ",lasterror,"): ",ErrorDescription(lasterror)); }
lasterror是4103,继续
错误为0
.....,我退出MT4并重新运行,运行正常。
一段时间后 (随机) 不工作。不是写文件。但 文件,文件名是唯一的。
为什么?
请显示日志文件中显示错误的部分 . .
你好。
在Costum指标中,WindowScreenShot工作得很好。
在5分钟内创建一个图片,例如:10:15,10:20,等等。
而且
一段时间后 (随机的) 就 不工作了。不能写入文件。
为什么?
GetLastError()不是错误信号。
显然,一切正常。
THX