1. Introduction to Chart Events and Mouse Clicks in MQL5 (00:01 – 00:16)
    • Introduction to handling chart events, specifically mouse clicks, in MQL5. Demonstrating that clicking on the chart initially does nothing until the expert advisor is applied.
  2. Applying the ‘Simple Mouse Click’ Expert Advisor (00:16 – 00:52)
    • Dragging the ‘Simple Mouse Click’ expert advisor onto the chart and demonstrating the message box that appears upon clicking the chart, showing mouse coordinates.
  3. Overview of Chart Events and Mouse Coordinates (00:52 – 01:08)
    • Explanation of how the numbers in the message box represent mouse coordinates on the chart.
  4. Opening MetaEditor and Creating a New Expert Advisor File (01:08 – 01:42)
    • Instructions on opening MetaEditor and creating a new expert advisor file named “Simple Mouse Click”.
  5. Setting Up the Code Structure for Chart Events (01:42 – 02:14)
    • Deleting unnecessary code and focusing on the ‘OnChartEvent’ function, which is used for handling chart events like mouse clicks.
  6. Explaining the Parameters of the OnChartEvent Function (02:14 – 03:28)
    • Detailed explanation of the parameters of the ‘OnChartEvent’ function, including event ID, long parameter, double parameter, and string parameter.
  7. Implementing the Mouse Click Event Handling (03:28 – 04:04)
    • Coding to check if the event ID equals ‘CHART_EVENT_CLICK’ and creating a message box output to show the x and y values of the mouse click.
  8. Compiling the Code and Testing in MetaTrader (04:04 – 04:31)
    • Compiling the code in MetaEditor and instructions on testing the expert advisor in MetaTrader by dragging it onto a live chart.
  9. Conclusion and Demonstration of the Mouse Click Event (04:31 – 04:59)
    • Conclusion and demonstration of the expert advisor in action, showing how it captures the position of mouse clicks on the chart.


In this video, we want to talk about chart events, in this case about a mouse click. When I click on the chart nothing happens, now let’s drag the little expert advisor, a simple mouse click on that chart, click on ok and when I click into the chart now I will get this little message box here, it says that the chart was clicked, the x value is two hundred and sixty three, and the y value is three hundred and eleven, let’s close that box and click again in the lower right corner and now you see that the values are much bigger, these numbers here are actually the mouse coordinates, so let’s find out how to fire a chart event with mql5.
To do that, please click on the little button here or press F4, now you should see the Metaeditor window and here you want to click on file, new, expert advisor from template, continue, I will call this file simple mouse click, click on continue, continue, and finish, now you can delete everything above the on tick function and the two comment lines here and most of the time we would do anything inside of the on tick function, this one is also an event, it’s called whenever the price changes on the chart and that’s the most interesting event, but we can also use other events like in our case a mouse click. Actually a mouse click belongs to what is called a chart event because it happens when we click anywhere on the chart and this chart event takes a few parameters.
We use the expression const here for constant or not changeable, the first parameter is an int parameter, it is called id, and it belongs to the event id, the second one is a long parameter – this is not a typo here, it’s actually the way to pass a reference instead of a value – the parameter is called lparam for long parameter, the next one is a reference and this one is called dparam for double parameter, because it’s a double value and the last one is called sparam because it’s a string, that’s basically it.
Now what can we do with the on short event function?
We can check if the id equals something, in our case we want to use chart event click and if that is the case we want to create an output.
This is a message box, it will show the words: chart was clicked, the x value, the y value, this is the title of the message box, and this is the button that we are going to use so let’s compile the code.
If you don’t have any errors here you can now click on the little button here or press F4 to go back to Met trader, and in Metatrader we simply drag the expert advisor on a live chart, click on ok and now when you click you will see the little message box here, so now you know how to get the current position of the mouse click and you have coded it yourself with a few lines of mql5 code.