- Introduction to Creating a Fibonacci Object (00:00 – 00:12) Introduction to creating a Fibonacci object in MQL5 as requested by a course member.
- Starting in MetaEditor and Creating a New Expert Advisor File (00:12 – 00:24) Instructions on opening MetaEditor and creating a new expert advisor file named “Simple Fibonacci Object.”
- Setting Up the Code Structure (00:24 – 00:34) Deleting unnecessary code above the ‘on tick’ function.
- Creating Variables for Highest and Lowest Candles (00:34 – 00:47) Creating integer variables for the number of the highest and lowest candles.
- Creating Arrays for Highest and Lowest Prices (00:47 – 01:10) Creating and sorting arrays for the highest and lowest prices of candles.
- Filling Arrays with High and Low Values (01:10 – 01:48) Using ‘CopyHigh’ and ‘CopyLow’ to fill arrays with the highest and lowest values for one hundred candles.
- Calculating the Highest and Lowest Candles (01:48 – 02:05) Using ‘ArrayMaximum’ and ‘ArrayMinimum’ to calculate the highest and lowest candles.
- Creating a Price Information Array (02:05 – 02:17) Creating and sorting a price information array for the chart.
- Copying Price Data and Deleting Old Fibonacci Objects (02:17 – 02:50) Copying price data for the chart and using ‘ObjectDelete’ to remove old Fibonacci objects.
- Creating the Fibonacci Object on the Chart (02:50 – 03:45) Using ‘ObjectCreate’ to draw the Fibonacci object on the chart, specifying its properties and borders.
- Compilation and Testing in MetaTrader (03:45 – 04:21) Compiling the code and instructions on testing the expert advisor in MetaTrader using the strategy tester.
- Demonstration of the Fibonacci Object on the Chart (04:21 – 04:30) Demonstrating the Fibonacci object drawn on the chart during a test.
- Calculating and Displaying Fibonacci Values (04:30 – 06:27) Using ‘ObjectGetInteger’ and ‘ObjectGetDouble’ to calculate and display time and price levels of the Fibonacci object on the chart.
In this video we are going to create such a Fibonacci object, this was a request from one of our course members, so let’s find out how to do that with mql5.
To start 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 Fibonacci object, click on continue, continue and finish.
Now you can delete everything above the on tick function and the two comment lines here.
Inside of the on tick function we want to create a few variables for the highest and the lowest candle, these are integer variables because it’s only the number of the highest and lowest candle.
We also create two arrays for the highest and the lowest prices and with array set as series we are going to sort the arrays from the current candle downwards, let’s also do that with the second array and now we can fill the arrays, we are using copy high to fill the high array with the highest prices of those candles, I would like to calculate the values based on one hundred candles.
And for the lowest values in the candles, we use copy low, both for the current symbol on the chart and the currently selected period, we start with candle zero, that’s the current candle and copy the values for one hundred candles in each of the arrays.
Now we can use array maximum to calculate the value for the highest candle in our high array and we use array minimum to calculate the lowest candle in our low array but we also need some price values, so let’s use mql rates to create a price information array, this one also needs to be sorted with array set as series.
Now we copy all the price data for the whole chart by using copy rates for the current symbol on the chart and the currently selected period for all the bars on the chart into our price information array, we use object delete to remove formal Fibonacci objects, we don’t have any objects at the very first time but afterwards, we delete the old object before we draw a new one and now we use object.create to actually create the Fibonacci object on our chart.
For the current symbol on the chart, the name will be Fibonacci, the type of the object is obj underscore fibo, if you mark it and press F1 you will see that we have lots of different object types, this is the one that we are going to use, we want to use the main window to draw the object, the left border will be candle number one hundred, the right border is candle zero, the upper border is where the highest candle price is and the lower border will be drawn on the lowest low of these one hundred candles.
That’s about it.
If you don’t know what all the code here does or if this was too fast for you maybe you want to watch one of the other videos in this basic video series or maybe even the premium course on our website might be interesting for you, for now, please click on the compile button or press F7, you shouldn’t get any errors and if that is the case you can click on the little button here or press F4 to go back to Metatrader.
And in Metatrader, we click on view, strategy tester or press control and r, please pick the new file simple Fibonacci object dot ex5, mark the visual mode here and start a test.
Here we are! Our Fibonacci object is drawn on the chart, now we want to stop the test, let’s calculate some values, this can be done by using object get. In our case, we use object get integer to get the time property for time values and we use object get double to get the object property for the price, if you mark this one and press F1 you will see that each object has lots of properties that can be different for each type of object, you can set a property by using object set, for example, the color or something like that or you can get the property by using object get and now we create a chart output with the comment statement that will output the time stamps and the price levels directly on our chart.
To calculate the price level fifty I have simply added the price level one hundred and the price level zero value and multiplied it by zero point five. Now let’s recompile the code, go back to Metatrader, start another test and here is the object and here are our values, let’s hit the pause button, with a click on the middle mouse button I can check if the calculated values are correct. This is the price level one hundred value, it’s one point four four nine two, that’s exactly what we have calculated here.
So our little expert advisor is working as expected and in this little video you have learned how to code a Fibonacci object and you have coded it yourself with a few lines of mql5 code.