Hi folks,
Today we are going to study in details a very important MQL4 function; the ScreenShot() function and in the coming article we are going to create a useful expert advisor that ......
Let's start from the beginning and know what screen shots means in MetaTrader?
In MetaTrader it's easy to save any chart you want with all the indicators plotted to it.
Just right-click on the chart you want to save and from the context menu (Figure 1) choose "Save As Picture" option.

This will bring Save As Picture dialog (Figure 2) to choose from it one of three options:
1- Active work space: Choosing this option will save a screen shot with all the MetaTrader program (Toolbar, Menus, Charts and windows). It's very like pressing ALT + Print Screen in Microsoft Window.
2- Active chart (as is): This option will save the chart as it appears in front of you with the same size.
3- Active chart: This option will enable you to set the width and height of the chart you want to save. If you supplied big width, MetaTrader will go through the history of the chart and save it in the picture.
When you choose the option you want and click ok you will get a dialog asking you about the name of the image, where to save it and what the type of the image you want to save (Figure 3). You cab choose one of two formats for the save image: GIF format or JPEG format.
Saving screen shots in MQL4 is a bit harder than the normal MetaTrader method but the best thing it's automated and very faster than the normal method.
To save screen shots in MQL4 you have to know the only function that enables you do that; the ScreenShot function.
Syntax:
| bool ScreenShot( string filename, int size_x, int size_y, int start_bar=-1, int chart_scale=-1, int chart_mode=-1) |
Description:
The ScreenShot function is the one responsible of saving the current chart, you pass to the filename of the saved image with the settings parameters which we will know later.
You have to know two important things about the ScreenShot function that differentiate it than the normal MetaTrader screen shot:
1- Limited saving folder:
While in the normal MetaTrader ScreenShot saving you can choose the folder you want to save the image, the ScreenShot function only uses one of two folders to save the images:
A- terminal_dir\experts\files and its sub folders in the case of forward mode.
B- terminal_dir\tester\files and its sub folders in the case of testing mode.
2- Limited image format:
The normal MetaTrader ScreenShot image can be in GIF or JPG format, while the ScreenShot function will save the image in GIF format only.
Parameters:
string filename:
The file name of the image you want to save, don't forget the .gif extension (see the example)
Note: You can create sub folder by adding this folder before the file name of the image and separating them by "/" sign (see the example).
int size_x:
The width of the image in pixels.
int size_y:
The height of the image in pixels.
int start_bar:
The first bar you want to include in your image, 0 means the first visible bar on the chart.
If this value was negative or omitted the image will start from the end of the chart.
int chart_scale:
The scale (zoom) of the chart, this value range from 0 to 5.
If this parameter omitted or was negative the function will use the current scale of the chart.
int chart_mode:
The displaying mode of the chart you want to apply to your saved image; 0 means Bars Chart, 1 means Candle Chart and 2 means Line Chart.
If this parameter omitted or was negative the function will use the current chart displaying mode.
Example:
| int lasterror=0; |
I hope you enjoyed this lesson and promise this will not be the last lesson about the ScreenShot function. In the coming lesson we are going to write a useful piece of code that puts ScreenShot function to use.
Coders Guru