Download MetaTrader 5

Chart screenshot indicator

To add comments, please log in or register
Do you have Mac OS? Find out how to install MetaTrader on it!
szatek
22
szatek 2013.10.25 12:58 

Hi All,

I created an indicator which takes a chart screenshot and saves it. The name of the saved file includes symbol together with time when the screenshot was taken:

ChartScreenShot(0,_Symbol + " @ " + (string)stm.hour + (string)stm.min+".gif",WIDTH,HEIGHT,ALIGN_RIGHT);

What I want to then achieve is to tell the platform to send me an email with the screenshot.

I understand that the SendMail () command is limited to subject and some text only so I created a vbs script which sends me an email.

The question is how can I take the parameters from the ChartScreenShot function and use them to open that vbs script. The vbs script is working ok. It's the mql5 bit I'm missing.

I tried using FileOpen and ShellExecuteW with imported shell32.dll but it doesn't work unfortunately or I'm doing something wrong.

Any help much appreciated.

Best regards,

Documentation on MQL5: Chart Operations / ChartScreenShot
Documentation on MQL5: Chart Operations / ChartScreenShot
  • www.mql5.com
Chart Operations / ChartScreenShot - Documentation on MQL5
Alain Verleyen
Moderator
30707
Alain Verleyen 2013.10.25 13:30  
szatek:

Hi All,

I created an indicator which takes a chart screenshot and saves it. The name of the saved file includes symbol together with time when the screenshot was taken:

ChartScreenShot(0,_Symbol + " @ " + (string)stm.hour + (string)stm.min+".gif",WIDTH,HEIGHT,ALIGN_RIGHT);

What I want to then achieve is to tell the platform to send me an email with the screenshot.

I understand that the SendMail () command is limited to subject and some text only so I created a vbs script which sends me an email.

The question is how can I take the parameters from the ChartScreenShot function and use them to open that vbs script. The vbs script is working ok. It's the mql5 bit I'm missing.

I tried using FileOpen and ShellExecuteW with imported shell32.dll but it doesn't work unfortunately or I'm doing something wrong.

Any help much appreciated.

Best regards,

Can you show your attempt with ShellExecuteW, please post all relevant code.
Jian Chen
Moderator
3618
Jian Chen 2013.10.25 13:31  

I think that the "ShellExecuteW" way should work.

But you should not use your vbs file name as the "lpFile" parameter of the ShellExecuteW function. Instead, you should use "WScript.exe".

For example:

ShellExecuteW(0, "open", "WScript.exe", "yourvbs.vbs parameter1 parameter2", "your directory", SW_HIDE);

If the above code doesn't work, the problem could be the directory settings, you may try using absolute path. 

szatek
22
szatek 2013.10.25 13:50  

Thank you very much for prompt reply. The command I was trying to use was:

ShellExecuteW(0,"Open","C:\\temp\\email.vbs","_Symbol (string)stm.hour (string)stm.min","","");

I will try forex2start's suggestion and let you know.

Best regards,

szatek
22
szatek 2013.10.25 15:23  

Hi Guys,

I configured two new variables in my mql5 file:

   string Hours = (string)stm.hour;
   string Minutes = (string)stm.min;

I thought that maybe it doesn't like to pass the parameters for some reason.

Here is the ShellExecuteW command:

ShellExecuteW(0,"open","WScript.exe","email.vbs _Period Hours Minutes","C:\\Users\\...\\MQL5\\Files","SW_HIDE");

I think the problem is that when it launches the vbs script it's actually not using the values for Hours Minutes and _Period but it's actually passing those words as parameters.

I'm really not sure if there is a way of working around this problem. Is there any special character which would paste the values like & or something like that ?

Best regards,

szatek
22
szatek 2013.10.25 15:28  
As a side note. When I try to run the vbs script manually with parameters it works ok so it has to be related to the mql5.
Jian Chen
Moderator
3618
Jian Chen 2013.10.25 15:35  
szatek:

Hi Guys,

I configured two new variables in my mql5 file:


I thought that maybe it doesn't like to pass the parameters for some reason.

Here is the ShellExecuteW command:

I think the problem is that when it launches the vbs script it's actually not using the values for Hours Minutes and _Period but it's actually passing those words as parameters.

I'm really not sure if there is a way of working around this problem. Is there any special character which would paste the values like & or something like that ?

Best regards,

Your code should be written like this:

ShellExecuteW(0,"open","WScript.exe","email.vbs "+_Period+" "+Hours+" "+Minutes,"C:\\Users\\...\\MQL5\\Files",0);

 SW_HIDE is a constant macro definition which equals to 0.

szatek
22
szatek 2013.10.25 15:51  
forex2start:

Your code should be written like this:

 SW_HIDE is a constant macro definition which equals to 0.

That worked like a charm. Thank you very much for your help.

Best regards,

Jian Chen
Moderator
3618
Jian Chen 2013.10.26 05:12  
szatek:

That worked like a charm. Thank you very much for your help.

Best regards,

You are welcome :)
To add comments, please log in or register