MQL4 TUTORIAL BASICS – 88 SIMPLE ALLIGATOR INDICATOR

video

In this video we are going to create an expert advisor to calculate this indicator, it is called alligator and it is an indicator created by Bill Williams, so let’s find out how to do that with mql4.
To get started please click on the 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 alligator, click on continue, continue and finish.
Now you can delete everything above the ontick function and the two comment lines here.
The alligator indicator has three different lines that we need to calculate and to do that we use the included function called ialligator, it comes with mql4 and we need to define a lot of parameters here, so let’s go through the values one by one.
The first parameter here is for the current symbol or currency pair on the chart, the second one underscore period will automatically find the current period on that chart for example thirty minutes or one-hour charts.
Parameter three is the jaw period, we use thirteen candles here and when you right-click on the alligator properties you will see those values thirteen, eight and five.
These are the number of candles for the jaws period, the teeth period and the lips period, all those values also have a shift value. The original ialligator is using shift values here but I have set it to zero because it will make it possible to check the current values by comparing them for the current candle.
The next parameter is the teeth period, this is calculated based on eight candles, I also don’t use a shift value for this one.
The next parameter is for the lips period, this is calculated based on five candles and once again we are not going to use a shift value here.
The following parameter is for the moving average method, I’m using mode underscore sma for simple moving average, if you mark that and press F1 you will see that you can choose one of these methods here, this one is the original one, we want to calculate the results based on the close price, if you mark that and press F1 you will see that there are other options available I think this one was the one that Bill Williams used.
The next parameter is for one of the three available values, mode underscore gator jaw will calculate the jaw value. Here comes another shift value, once again we use zero to calculate the values for the current candle and that’s about it, so let’s close the ialligator definition here.
And now we need to repeat the whole thing two more times, the only difference is that we change the parameter from mode underscore gator jaw to mode underscore gator teeth to calculate the alligator teeth.
And to calculate the alligator lips you need to change the particular parameter to mode underscore gator lips, please all in capital letters.
Finally, I would like to create an output by using the comment statement, this will output the calculated values directly on our chart.
In this video we are not going to do automated trades, we will just output the values and that’s about it.
Well, if you have no idea 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.
This worked without any errors and if that is the case you can click on a little button here or press F4 to go back to Metatrader.
And in Metatrader we need to open an empty chart and click on insert, indicators, alligator, please pick thirteen candles for the jaws period, eight candles for the teeth period, five candles for the lips period, the method is simple, we want to calculate the values based on the close price and we have set every shift value to zero here.
Now please click on okay! Here is the alligator indicator, now please right-click into the chart, select template, save template and save it as tester dot tpl because this is the template that we are going to see in the strategy tester, you can override the old one. If you don’t see the strategy tester, please click on view strategy tester or press ctrl and r, and here we need to pick the new file, simple alligator dot ex4, please mark the visual mode here and start your test.
Here we are!
The expert advisor is running, let’s fast forward and stop it!
And now we want to point the mouse on the jaw line here we have a value that says we have one point one three five o four, our calculated value is one point one three five so this is correct.
The teeth value is one point one three four nine one, this is also correct.
And the lips value is one point one three four six four, this is also what we have calculated, so our little expert advisor works as expected and in this little video you have learned how to create an expert advisor that is able to calculate the values for the alligator indicator by Bill Williams and you have coded it yourself with a few lines of mql4 code.