MQL5 Chart Screenshots

 

Good day, 

I have this simple EA that screenshots a chart on every tick(Code below). I was wondering if there is a better way of taking chart screenshots dating back from a year from now till recent?. I tried running the EA on the strategy tester and it does not save the screenshots in my Files directory. Thank you.


//+------------------------------------------------------------------+

//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   string name = "Screenshot " + IntegerToString(TimeCurrent()) + ".PNG";
   
   if(ChartScreenShot(0,name,Chart_Width,Chart_Height))
      {
         Print("Screenshot saved ", name);
      }
  }
 
Masilive Sifanele:

I tried running the EA on the strategy tester and it does not save the screenshots in my Files directory. 

no screenshot on tester

 
Mohamad Zulhairi Baba:

no screenshot on tester

It doesn't, but if you run it on start debugging on real data it will. I want to take screenshots starting from a week ago until now. Think of a rolling window. Thanks for your reply.


 

This does the trick.

//+------------------------------------------------------------------+
//|                                                      ProjectName |
//|                                      Copyright 2020, CompanyName |
//|                                       http://www.companyname.net |
//+------------------------------------------------------------------+
#property description "The Expert Advisor demonstrates how to create a series of screenshots of the current"
#property description "chart using the ChartScreenShot() function. For convenience, the file name is"
#property description "shown on the chart. The height and width of images is defined through macros."

#define        WIDTH  1200        // Image width to call ChartScreenShot()
#define        HEIGHT 600        // Image height to call ChartScreenShot()

//--- input parameters
input int      pictures=100;     // The number of images in the series
int            mode=1;           // -1 denotes a shift to the right edge of the chart, 1 - to the left
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
void OnInit()
  {
//--- create timer
   EventSetTimer(60);
//--- Disable chart autoscroll
   ChartSetInteger(0,CHART_AUTOSCROLL,false);
//--- Set the shift of the right edge of the chart
   ChartSetInteger(0,CHART_SHIFT,false);
//--- Show a candlestick chart
   ChartSetInteger(0,CHART_MODE,CHART_CANDLES);
//---
   Print("Preparation of the Expert Advisor is completed");

   GenerateTrainingData();
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---

  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void GenerateTrainingData()
  {
//--- Operation with the left chart edge

   for(int pos=16; pos<pictures; pos+=1)
     {
      //--- Scroll the chart to the left edge
      ChartNavigate(0,CHART_BEGIN,pos);

      //--- Give the user time to look at the new part of the chart
      Sleep(10);

      //--- Prepare a text to show on the chart and a file name
      string name = Symbol() + " " + IntegerToString(pos + 1) + ".PNG";

      //--- Save the chart screenshot in a file in the terminal_directory\MQL5\Files\
      if(ChartScreenShot(0,name,WIDTH,HEIGHT,ALIGN_LEFT))
        {
         Print("Screenshot saved as ",name);
         Comment(name);
        }

     }
  }
//+------------------------------------------------------------------+
 
Masilive Sifanele:

This does the trick.


I  have been looking for some way to do this for a couple of days now . 
thank you very much for sharing this