In this video we are going to create a buy button, this is a chart object and when we click on the button we can see that we have a new open position, so let’s find out how to do that with mql5. To get started please click on a little icon here or press F4 on your keyboard, now you should see the Metaeditor window and here you want to click on file, new file, expert advisor from template, continue, I will call this file, simple buy button, click on continue, continue and finish. Now you can delete everything above the ontick function and let’s remove the two comment lines here. We start with an include statement to include the file trade dot mqh, it contains the class ctrade and we are going to create an instance that is called trade, afterwards, we create two variables for the ask price and the bid price because the event handling for the button will be implemented in a separate function. Inside of the ontick function, we start by calculating the ask price and the bid price that is done by using symbol info double for the current symbol on the chart, we use either symbol underscore ask or symbol underscore bid and with normalize double and underscore digits we make sure to automatically calculate the right number of digits behind the dot. Now we want to create a chart object that is done by using object create for the current symbol on the chart, the object name will be buy button, the object type is obj underscore button and if you mark that and press F1 you will see that there are lots of object types that we can draw on the chart. This is the one that we are going to use, you can place a button in front of any chart. Inside of the documentation, you will find lots of examples for dozens of properties and events but we are going to make it very simple. The next parameter is the window, we want the button to appear in the main window where the candles are and the last two parameters here for date time and price point are not required, so we set those values to zero. Let’s define a few properties, we use object set integer for the current symbol on the chart and the object with the name buy button, the property we want to change is the x distance from the border, let’s set the distance to two hundred pixels, I would like to set another property, everything is equal except for the parameter here that’s object property x size and that will change the width of our button. We also want to set the distance from the upper or from the lower border that is done by using object property underscore y distance. Now let’s set the height of the button to fifty pixels and this time it’s obj prop underscore y size, we can pick one of four borders for our object that is done by using obj prop underscore corner so if you change this number your object will appear in a different corner and finally, I would like to change the text on the button – that’s what we do when we use obj prop underscore text – and I would like to have the text buy and that’s it for the button. You could compile the code now but the button wouldn’t do anything so what’s missing is the event handling and we are going to create that now. So let’s create a separate function here, this function is called on chart event, we have four parameters here, the first one is for the chart id and these three parameters here are used to pass some values. Inside of the function, we first want to check if the first parameter here, id, equals chart event object click, so that would be a mouse click on an object. And in the next step we want to check the value for the sparam that is a string value and we will call that clicked object name and now we can check if the sparam equals buy button – that’s the name of the button – and if that is true we want to create a comment statement and output the sparam value to show which button was pressed, in our case we only have one button and if it is the buy button we use trade dot buy to buy ten micro lot.