How to know a template is fully loaded?

 

Hello everyone.

1. I am trying to attach a template to chart and then take a screenshot.

2. I realized when I use ChartScreenshot too soon the template is not loaded yet and it is not visible in screenshot.

3. I use Sleep function to avoid this. 

I am wondering if there is a better solution?

 
Yashar Seyyedin:

Hello everyone.

1. I am trying to attach a template to chart and then take a screenshot.

2. I realized when I use ChartScreenshot too soon the template is not loaded yet and it is not visible in screenshot.

3. I use Sleep function to avoid this. 

I am wondering if there is a better solution?

If you're trying to do this from a single MQL program, your logic is wrong. When a user or a program is applying a template, all current programs are unloaded and then the template is loaded causing further loading of other MQL programs, if they mentioned in the template. So "screenshotting" can be bound only to an event (OnInit, OnCalculate, OnTimer) in, say, dummy indicator mentioned in the template.

 
Yashar Seyyedin:

Hello everyone.

1. I am trying to attach a template to chart and then take a screenshot.

2. I realized when I use ChartScreenshot too soon the template is not loaded yet and it is not visible in screenshot.

3. I use Sleep function to avoid this. 

I am wondering if there is a better solution?

Sure there is a better solution, but it depends of your needs and if you want it generic or specific. In general, as Stanislav said, use events, I would just prioritize OnChartEvent rather than the others.
 
Alain Verleyen #:
Sure there is a better solution, but it depends of your needs and if you want it generic or specific. In general, as Stanislav said, use events, I would just prioritize OnChartEvent rather than the others.

OnChartEvent is not guaranteed ;-) (something should happen with the chart, like click/resize by user), which is why I suggested OnInit (will be called surely) and OnTimer (will be called if requested in OnInit), also OnCalculate is guaranteed at list once.

 
Stanislav Korotky #:

OnChartEvent is not guaranteed ;-) (something should happen with the chart, like click by user), which is why I suggested OnInit (will be called surely) and OnTimer (will be called if requested in OnInit), also OnCalculate is guaranteed at list once.

What is not guaranteed exactly ? "something should happen with the chart, like click by user" : not at all.

Anyway, if you want to use other events, it's fine for me.

 
Alain Verleyen #:

What is not guaranteed exactly ? "something should happen with the chart, like click by user" : not at all.

Anyway, if you want to use other events, it's fine for me.

I suggested guaranteed event types, not because I want them. OnChartEvent can happen not to fire at all in the newly loaded "screenshotting" program, unless additional actions are taken by user or by other programs.

 

Thanks for the replies. Let me clarify something.

This is the procedure:

1. Open another chart (ChartOpen)

2. Apply template to it.

3. Take screenshot of it.

It is not meant to take screenshot of the current chart that has the EA running. 

 
Yashar Seyyedin #:

Thanks for the replies. Let me clarify something.

This is the procedure:

1. Open another chart (ChartOpen)

2. Apply template to it.

3. Take screenshot of it.

It is not meant to take screenshot of the current chart that has the EA running. 

And what is on this template ?

The best solution is to have some code running on this new chart that will notify the "running EA" of the other chart, or possibly to take the screenshot itself.

 
Alain Verleyen #:

The best solution is to have some code running on this new chart that will notify the "running EA" of the other chart, or possibly to take the screenshot itself.

+1

 
Alain Verleyen #:

And what is on this template ?

The best solution is to have some code running on this new chart that will notify the "running EA" of the other chart, or possibly to take the screenshot itself.

In fact the template is not my choice... It is the users' choice.

 
Yashar Seyyedin #:

In fact the template is not my choice... It is the users' choice.

But it's your EA which manage to open the template ? Using some input from the user ?

Or your EA has to take a screenshot of something done manually by the user ?