Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1588

 
Vitaly Muzichenko #But in mt4 ChartScreenShot() works perfectly. It is not logical that it does not work properly in mt5.

Yes, it can feel a bit crazy compared to MT4, but there is a reason for it, the rendering is asynchronous.

 
Miguel Angel Vico Alba #:

Yes, compared to MT4 it may seem a bit odd, but there is a reason for that, the rendering is asynchronous.

We should not look for the cause, but for a solution.

 
Vitaly Muzichenko #We should not look for the cause, but for a solution.

If the asynchronous nature is the cause, then there is no real "fix".

 
Miguel Angel Vico Alba #:

If asynchrony is the cause, there is no real "fix".

The question was about the tester, slip and timer don't work. Reaching even the local comp time is a problem. Return true on execution would be good.
 

From the screenshot

Get the result of the function into a variable, and spin it in while?

Don't forget about IsStopped())

 
Valeriy Yastremskiy #:
The question was about the tester, slip and timer don't work. Reaching even the local comp time is a problem. Return true on execution would be good.
In the tester, the timer does work, the time is simulated (do not use Sleep()), and ChartScreenShot() only makes sense in visual mode, synchronize with OnTimer() plus ChartRedraw(), and verify that the image file in PNG format exists and has size before considering it valid.
 
lynxntech #:

From the screenshot

Get the result of the function into a variable, and spin it in while?

Don't forget about IsStopped())

Yes, a while with IsStopped() can work, but since it is active waiting it can stay at 100% CPU during the wait, in the visual tester it is more efficient and safer to use OnTimer() with several ChartRedraw(), and validate the file to make sure the capture is complete.

Let us remember what we are talking about (It is what I base everything I say on):

Forum on trading, automated trading systems and testing trading strategies

Questions from Beginners MQL5 MT5 MetaTrader 5

Nauris Zukas, 2025.08.13 14:15

Does the ChartScreenShot() function work reliably in MetaTrader 5 Strategy Tester's visual mode? The documentation does not mention any limitations, but I'm getting blank images. Has anyone experienced this or found a solution?


 
Miguel Angel Vico Alba #:

I haven't tried it myself, I only suggested it, I think people had empty files in the tester,

There were empty files in wine, you can search for them.
 
lynxntech #:

From the screenshot.

Get the result of a function into a variable and spin it in while?

Don't forget about IsStopped())

I tried it, while while while is spinning - the programme dies and no screenshot is created.

 
Samuel Bandi Roccatello #:

Hey, everybody,

That's not right.

a_position.Type()

right

a_position.PositionType()