How to Save a Chart as an Image Programmatically? (Preferably Not by Screenshot)

 

Hello Everyone,

I have a task that I desire to complete with specific parameters for success. The ultimate goal I have is to create reproducible graphical reports using files like R Markdown or Jupyter Notebook and I have run into the issue of being able to produce and display MT5 graphs in these reproducible documents. To set up the problem, I have a reproducible R Markdown script that will be able to display relevant models and graphics into a knitted output file (PDF/HTML) when it is complete. One of the model types I would like to display are regression models with indicators using trading pair data and I want it to come from the MT5 terminal as that is where most of my analysis is conducted and formulated. The R Markdown file will trigger the execution of a python script that uses an MT5 module to load the data and display the regression chart I specified in the terminal, likely a little redundant to bridge languages like that, but it gets the job done. Python can display the graphs but can't save them to a local directory accessible to my R Markdown script. So I decided to make the effort of trying to use an MQL5 script to simply save the chart that was already on the screen with it's current cosmetics but with not luck as it seems that using MQL5 methods to save charts as PNG/JPG files is non-existent, at least that I have been able to find with the exception of screenshot methods. While I will inevitably use a screenshot method if it comes to that, they are not preferrable because if I have to use a screenshot method then the MT5 terminal will have to be directly open on the computer screen of the person who is trying to run my reproducible R Markdown script trying to obtain the output file rendering it hardly reproducible. I am simply hesitant to implement a solution that would require others trying to run my script to install and interact with a program they have no understanding either in interface or conceptually. This brings me to my point that I would like to know if it is reasonably possible to create an MQL5 script that can save the current chart in the terminal as an image without engaging to terminal interface? I tried my best to explain the problem clearly and concisely so please let me know if I missed something and I'll be happy to clarify, I appreciate any answers you can throw my way even if that answer is "Sorry, but there is no way to feasibly perform this task and you'll need to use a screenshot method."

Thanks again,

HP

 
Hudson Pierce: How to Save a Chart as an Image Programmatically?

Please learn to use the "Search" functionality before posting. A simple search of the MQL5 documentation would have given you the answer very quickly ...

ChartScreenShot

Provides a screenshot of the chart of its current state in a GIF, PNG or BMP format depending on specified extension

Documentation on MQL5: Chart Operations / ChartScreenShot
Documentation on MQL5: Chart Operations / ChartScreenShot
  • www.mql5.com
ChartScreenShot - Chart Operations - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Fernando Carreiro #:

Please learn to use the "Search" functionality before posting. A simple search of the MQL5 documentation would have given you the answer very quickly ...

ChartScreenShot

Provides a screenshot of the chart of its current state in a GIF, PNG or BMP format depending on specified extension

Thank you for your input, I can respectfully assure you that I did my preliminary research before making my post and was aware of the solution you provided before doing so. I had my reasons for proceeding to ask the question anyways due to my unique requirements. However, I understand now that the solution you provided is the answer to my question because it is the only official method for handling this task. Thanks again for confirming the answer, it is appreciated.

 
Hudson Pierce #: Thank you for your input, I can respectfully assure you that I did my preliminary research before making my post and was aware of the solution you provided before doing so. I had my reasons for proceeding to ask the question anyways due to my unique requirements. However, I understand now that the solution you provided is the answer to my question because it is the only official method for handling this task. Thanks again for confirming the answer, it is appreciated.
Your current statement contradicts with your original post, because you stated, and I quote "... it seems that using MQL5 methods to save charts as PNG/JPG files is non-existent,"
 
Please note that for the function question, by "screenshot", it is meant that the chart and only the chart is saved. The rest of the graphical user interface is not included in the "screenshot".
 
Fernando Carreiro #:
Please note that for the function question, by "screenshot", it is meant that the chart and only the chart is saved. The rest of the graphical user interface is not included in the "screenshot".

Just for clarification, the entire sentence read, "... it seems that using MQL5 methods to save charts as PNG/JPG files is non-existent, at least that I have been able to find with the exception of screenshot methods."

I suppose my choice of words were not the most clear, so I apologize for that, but that's not the point because we are on the same page now. It looks like I was mistaken on the underlying function of the "screenshot" method. If its implementation works without disturbing the interface, then the results should be flawless. Thank you for the clarifying information pertaining to the method. I must have overlooked this fact in my research so I'll admit my research was likely not as thorough as I had believed. Either way it's time for me to get to work on it now, thanks again.

 
Hudson Pierce #:

Just for clarification, the entire sentence read, "... it seems that using MQL5 methods to save charts as PNG/JPG files is non-existent, at least that I have been able to find with the exception of screenshot methods."

I suppose my choice of words were not the most clear, so I apologize for that, but that's not the point because we are on the same page now. It looks like I was mistaken on the underlying function of the "screenshot" method. If its implementation works without disturbing the interface, then the results should be flawless. Thank you for the clarifying information pertaining to the method. I must have overlooked this fact in my research so I'll admit my research was likely not as thorough as I had believed. Either way it's time for me to get to work on it now, thanks again.

You can also place logos and watermarks over the chart using the canvas library and that will be saved too saving you editing time.

Reason: