ChartScreenShot() always saves the latest position of the chart

 

Hey guys,


I have a problem with ChartScreenShot(). I want to save screenshots from a specific time. I use ChartNavigate(), it works fine, I can see visually in MetaTrader5 that the chart is shifting, the EA takes the screenshots as well, however, when I look at the pictures, they always show the last position of the chart (as if I enabled AutoScroll and then took a picture). Autoscroll is off, everything is working fine, except the ChartScreenShot() doesn't take the picture of the visible chart but one that is shifted all the way to the newest bar. Any ideas?


Thanks in advance.


Robert


PS: actually the problem is the same one discussed here: https://www.mql5.com/en/forum/23940. When I left-align the ChartScreenShot(), it works as intended.


The below code supposed to take 5 pictures from the startTime specified, shifting 1 bar at the time.

bool createImageDataset(datetime startTime)
{
   int shift = iBarShift(Symbol(), Period(), startTime);
   int chWidth = ChartGetInteger(ChartID(), CHART_WIDTH_IN_PIXELS);
   int chHeight = ChartGetInteger(ChartID(), CHART_HEIGHT_IN_PIXELS);
  
   for (int i = -shift; i < (-shift + 5); i++)
   {     
      string filename = IntegerToString(-i) + "-0.png";

      ChartNavigate(ChartID(), CHART_END, i);


      Sleep(1000);


      bool chScrShootSucc = ChartScreenShot(ChartID(), filename, chWidth, chHeight, ALIGN_RIGHT);
   }
  
   return true;
}
Documentation on MQL5: Chart Operations / ChartNavigate
Documentation on MQL5: Chart Operations / ChartNavigate
  • www.mql5.com
[in]  Number of bars to shift the chart. Positive value means the right shift (to the end of chart), negative value means the left shift (to the beginning of chart). The zero shift can be used to navigate to the beginning or end of chart.
 

Trying putting ALIGN_LEFT into your ChartScreenShot usage like this:


ChartScreenShot(0,filename,1920,1080,ALIGN_LEFT); 
\


This worked for me.