MQL5 TUTORIAL BASICS – 88 SIMPLE ALLIGATOR INDICATOR

video
play-sharp-fill

In this video, we are going to calculate the values for the alligator jaw, the alligator teeth and the alligator lips. This is an indicator that was created by Bill Williams, 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 alligator, click on continue, continue and finish.
Now you can delete everything above the ontick function and the two comment lines here.
To calculate the alligator we need to have three different arrays, one is for the so-called jaw, one is for the teeth and one is for the lips.
To be honest I’m not a big fan of the alligator indicator but this was a suggestion from one of the premium course members and if you are already a premium course member and have an idea for a video like this one please let me know but let’s continue!
We now need to define the alligator expert advisor, I do it in a different way because I would like to actually check the current values. The original version is using shift values but I would like to check if the calculation for the current value is correct, so let’s get started.
And to do that we use the included function called ialligator, if you mark that and press F1 you will see that it needs a lot of parameters.
The first parameter is for the current symbol on the chart, in our case, it’s a currency pair, the second parameter is for the period on that chart, for example, a one-minute chart or thirty-minute chart.
Underscore period is going to calculate the current one, the next parameter is a so-called jaw period if you right-click on the indicator and click properties of alligator you will see the jaws period is thirteen candles, teeth period is eight candles and the lips period is five candles.
In the original version they also use shift values but I have set those to zero to make it easier to check the current values here, so we use zero for the jaw shift value, the teeth period is eight, the shift value for the teeth also is zero, the lips period is five, the shift value for the lips is also zero, the mode in my case is mode underscore sma, you could also use ema for exponential moving average or smma that’s the original one that they use for the original alligator.
I would like to calculate the values based on the close price, here you can use whatever you want, the original alligator is using the median price and that’s it for the alligator definition.
Now we need to calculate the jaw, the teeth, and the lips.
We start by using array set as series for the jaw array to sort it from the current candle downwards and as you might have guessed we repeat that for the teeth array and for the lips array and now we use copy buffer to fill the jaw array according to the alligator definition that we have created here.
For the jaw, we are using buffer zero and we want to copy the values from the current candle zero for three candles and store them in the jaw array.
For the teeth array it’s basically the same but this time we are going to use buffer one because in the reference we learn that buffer zero is the jaw, buffer one is the teeth and buffer two is the lips value.
So let’s repeat that!
And this time we are using buffer two for the lips array and now we can calculate our values by simply looking into candle zero of the jaw array, I use normalize double and five to create an output with five digits behind the dot because this is what we see when we point the mouse on one of the three indicator lines.
We repeat it and do it for the alligator teeth value, everything is similar except for the fact that we are now looking at candle zero in the teeth array and as you might have guessed it’s the same for the lips array.
Finally, we want to add a comment statement to output the values, we are not going to actually trade this indicator but we want to see the alligator jaw, the alligator teeth, and the alligator lips values on our chart.
This one belongs to the end of the source code and basically, that’s it.
Well, if this was too fast for you or if you have no idea what all the code here does maybe you want to watch one of the other videos in the basic video series or maybe even the premium course on our website might be interesting for you, for now, please click on view, toolbar and click on the compile button or press F7. I don’t have 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 you need to open a new chart, click on insert, indicators, Bill Williams, alligator, we want to calculate the indicator for thirteen candles for the jaws, eight candles for the teeth and five candles for the lips, please set the shift values to zero, in my case the method is simple and we want to calculate the values based on the close price.
Afterwards, please click on okay. Now you should see the indicator on the chart, now right-click, select templates, 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 current one.
Now let’s click on view, strategy tester or press control and r, pick the new file, simple alligator dot ex5, mark the option for the visual mode here and start a test.
Here we are!
The alligator is calculated, let’s stop it, point your mouse on one of the alligator lines, in my case the jaws value here is one hundred nine dot two o four, that’s the rounded value of the result that we have calculated, the value for the teeth is one hundred nine dot two two three, that’s also okay and the lips value is one hundred nine dot two three seven and that’s the rounded version of our result, so our expert advisor works as designed and in this little video you have learned how to calculate the alligator indicator and you have coded it yourself with a few lines of mql5 code.