Hello,
In costum indicator WindowScreenShot is working prfectly.
Create an pictures at 5 minutes eg: 10:15,10:20, etc...
And
After a period(random) of time does not work. Not write the file.
Why?
.... 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));
It's because your code, which we cannot see, is broken. As we cannot see your code we can not tell you where it is broken.
error=0
and lasterror =4103, connot open file
why?
error=0
and lasterror =4103, connot open file
why?
Is filename unique or do you re-use filenames ?
unique
unique
Do NOT call GetLastError() unless there IS an error. WindowScreenShot(filename, X_pixels, Y_pixels); int error=GetLastError(); if (error!=0) Alert(TimeToStr(TimeCurrent(),TIME_SECONDS
What are Function return values ? How do I use them ? - MQL4 forum 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();
If the FileOpen fails, handle == -1. You are issuing an alert when there is NO error and continuing when there IS.
How do you make them unique ?
string timestamp = TimeToStr(TimeCurrent(),TIME_SECONDS); filename = filename + "_" + timestamp + ".gif";
From what I can see your biggest issue is your error handling, as WHRoeder has already mentioned, you are doing a poor job of reporting the errors when/if they occur. For example you don't even check if WindowsScreenShot() worked or didn't work . . . make the changes that WHRoeder has suggested and test again. Your filename is not unique . . . you use the hh:mm:ss from the current time, so each day it is possible to overwrite a file from a previous day, if that file is open at the time this might cause a 4103 error.
Instead . . .
string timestamp = TimeToStr(TimeCurrent(), TIME_DATE|TIME_SECONDS); filename = filename + "_" + timestamp + ".gif";
. . . to add the date into the filename.
From what I can see your biggest issue is your error handling, as WHRoeder has already mentioned, you are doing a poor job of reporting the errors when/if they occur. For example you don't even check if WindowsScreenShot() worked or didn't work . . . make the changes that WHRoeder has suggested and test again. Your filename is not unique . . . you use the hh:mm:ss from the current time, so each day it is possible to overwrite a file from a previous day, if that file is open at the time this might cause a 4103 error.
Instead . . .
. . . to add the date into the filename.
lasterror is 4103, continue
error is 0
.....and I quit the MT4 and re run it, run correctly
After a period(random) of time does not work. Not write the file. But file, filename unique.
why?
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 is 4103, continue
error is 0
.....and I quit the MT4 and re run it, run correctly
After a period(random) of time does not work. Not write the file. But file, filename unique.
why?
Please show the part of the log file showing the errors . . .

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello,
In costum indicator WindowScreenShot is working prfectly.
Create an pictures at 5 minutes eg: 10:15,10:20, etc...
And
After a period(random) of time does not work. Not write the file.
Why?
GetLastError() not signal error.
Apparently all good.
THX