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.