ScreenShot - Part 2

Hi folks,

In a previous lesson we have studied the ScreenShot function and I promised to show a useful piece of code that puts ScreenShot function to use.

What are we going to do with ScreenShot today?

I was writing an Expert Advisor for one of my clients, the program didn't work as agreed and both of us (me and my client) couldn't catch the error.

The entry point of the Expert Advisor wasn't in accordance with the entry conditions the client demanded and we couldn't catch the error because the color changing of the used indicators and when we view the history chart we find everything is right.
 

I suggested to print the chart every time the Expert Advisor open a new trade but it was bad idea! then what MQL is for?

That's why I added this price of code to get a screen shot of the chart every time the Expert Advisor enter a trade and save it to a unique folder with auto increment number added to the image file name.

Let's give the code a look!

int start()
{
.....
TakeScreenShot("OPEN_BUY");
.....
}

void TakeScreenShot(string type)
{
int count = 1;

if(!GlobalVariableCheck("ssc"))
{
GlobalVariableSet("ssc",1);
count = 1;
}
else
{
count = GlobalVariableGet("ssc") + 1;
GlobalVariableSet("ssc",count);
}
string filename = "MyEA\\" + "MyEA_" + Symbol() + "_" + type + "_" + DoubleToStr(count,0) + ".gif";
ScreenShot(filename,640,480);
}

How does it work?

The piece of code above have two parts; The TakeScreenShot Function and a line to call it. Let's study the function then we are going to know how to use it!

TakeScreenShot Function:

The TakeScreenShot function simply do the following:

1- It remembers the count of previous screen shots have been taken, that's by using Global Variable! Why? to name every new image file with a new name based on the count of images.

2- It takes a screen shot of the current chart whenever you call it.

3- It saves the image file in a folder called "MyEA", the function add to the name the name of the symbol (currency pair) and the type of trade - The type of the trade is a string parameter of the function you supply it and the function will add it to image name for you to identify the image.

How to call the TakeScreenShot function?

Calling the TakeScreenShot function is like calling any custom function you create/use. I mean by the above question when you have to call it.

It depends on the screenshot you want to take. In my above mentioned program that I created to my client I used it every time The program enter a new trade and every time the program close a trade. You can use it too every time the program modify a trade. Don't forget to set the type parameter to distinguish between the images the program take!

I hope you find it a useful article and a useful code!

Coders' Guru