Beating Alpha

iterating towards truth

Uncategorized

Function for screenshot taking in Metatrader 4

Recently I was looking for certain function for taking screenshots of charts in Metatrader.

Here is the sample:

WindowScreenShot("TIMESTAMP_"+Month()+"_D"+Day()+"_H"+Hour()+"_M"+Minute()+"_S"+Seconds()+".gif",1024,768);

Here is the desctiption by Metatrade help library:

bool WindowScreenShot( string filename, int size_x, int size_y, int start_bar=-1, int chart_scale=-1, int chart_mode=-1)

Saves current chart screen shot as a GIF file. Returns FALSE if it fails. To get the error code, one has to use the GetLastError() function.
The screen shot is saved in the terminal_direxpertsfiles (terminal_dirtesterfiles in case of testing) directory or its subdirectories.

Parameters:
filename   –   Screen shot file name.
size_x   –   Screen shot width in pixels.
size_y   –   Screen shot height in pixels.
start_bar   –   Index of the first visible bar in the screen shot. If 0 value is set, the current first visible bar will be shot. If no value or negative value has been set, the end-of-chart screen shot will be produced, indent being taken into consideration.
chart_scale   –   Horizontal chart scale for screen shot. Can be in the range from 0 to 5. If no value or negative value has been set, the current chart scale will be used.
chart_mode   –   Chart displaying mode. It can take the following values: CHART_BAR (0 is a sequence of bars), CHART_CANDLE (1 is a sequence of candlesticks), CHART_LINE (2 is a close prices line). If no value or negative value has been set, the chart will be shown in its current mode.
Sample:
int lasterror=0; //---- tester has closed one or more trades if(IsTesting() && ExtTradesCounter<TradesTotal()) { //---- make WindowScreenShot for further checking if(!WindowScreenShot("shotstester"+ExtShotsCounter+".gif",640,480)) lasterror=GetLastError(); else ExtShotsCounter++; ExtTradesCounter=TradesTotal(); }

Leave a Reply