Download MetaTrader 5

WindowScreenShot problem

To add comments, please log in or register
Have you just installed MetaTrader 5? Learn it in details!
ttechnik
256
ttechnik 2014.01.18 11:57 

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

Simon Gniadkowski
Moderator
18001
Simon Gniadkowski 2014.01.18 13:11  
ttechnik:

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?

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.
ttechnik
256
ttechnik 2014.01.18 14:58  
  ....
  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));
  
RaptorUK:
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?

Simon Gniadkowski
Moderator
18001
Simon Gniadkowski 2014.01.18 15:09  
ttechnik:

error=0

and lasterror =4103, connot open file

why?

Is filename unique or do you re-use filenames ?
ttechnik
256
ttechnik 2014.01.18 15:23  
RaptorUK:
Is filename unique or do you re-use filenames ?


unique
Simon Gniadkowski
Moderator
18001
Simon Gniadkowski 2014.01.18 15:33  
ttechnik:

unique
How do you make them unique ?
whroeder1
14532
whroeder1 2014.01.18 15:35  
  1. 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 ...
    }

  2.   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.
ttechnik
256
ttechnik 2014.01.18 15:51  
RaptorUK:
How do you make them unique ?



string timestamp = TimeToStr(TimeCurrent(),TIME_SECONDS);
filename = filename + "_" + timestamp +  ".gif";
Simon Gniadkowski
Moderator
18001
Simon Gniadkowski 2014.01.18 16:07  
ttechnik:


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.

ttechnik
256
ttechnik 2014.01.18 16:50  
RaptorUK:

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));
   }
Simon Gniadkowski
Moderator
18001
Simon Gniadkowski 2014.01.18 18:26  
ttechnik:

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 . . .
1234
To add comments, please log in or register