In this video, we want to create a file for the entry signal of this interesting indicator with the little dots here. This one is called the parabolic SAR. So let’s find out how we can calculate that with MQL5.
This time we want to create an entry signal for an indicator that is painted right above or below the candles.
It is called the parabolic SAR and you will see little dots above or below the current price.
To get started, we want to create a new file called CheckEntry_SAR and save it in the same directory where the other files for the system are located.
The file uses one function called CheckEntry to calculate the signal which will be returned to the main file at the end of the function.
First we use MQLRates to create a price array.
Then we use Array set as series to sort that price array from the current candle downwards.
And with copy rates we fill the price array with data for the currently selected symbol on the chart and the period that we have selected on that chart.
We want to start with candle 0, that is the current candle and copy price data for 3 candles.
The price array will hold that data.
So let’s create a signal variable that can hold text values, but don’t assign any values at this stage.
And we need a second array for the indicator data.
We use the function i-SAR for the symbol on the chart and the selected period for parameter 1 and 2.
Parameter 3 is a so-called step value and parameter 4 is a maximum value.
You will see the values 0.02 and 0.2 when you drag the Parabolic SAR indicator onto any of your charts.
Now we use array set as series to sort the SAR array from the current candle downwards.
And with copy buffer we fill the array according to the SAR definition that we have already created.
We do that for buffer 0, starting from candle 0 for 3 candles.
Now we can extract values from our array.
In this case we are interested to get the value for candle 1.
That will calculate the last value of the indicator.
With NormalizeDouble and the number 5 we can format our output to show 5 digits behind the dot.
And if the last SAR value was below the value for the lowest price of candle 1 in our price array, we want to buy and assign the word buy to our signal.
Otherwise, if the last SAR value was above the value for the highest price of candle 1 in our price array, we want to sell and assign the word sell to our signal.
Finally we use the return function to return the calculated value to our main file.
Now please don’t forget to save the file.
Afterwards please switch to the main file and find the part with the include statement for the entry signal.
You can outcomment other entries by adding two slashes at the start of the line.
Please add the include statement for our new file named CheckEntry_SAR and press F7 or click on the compile button to compile both files.
You might see some warnings, but you shouldn’t get any errors.
If you do, please consider watching one of the basic video tutorials first, or maybe the Premium course on our website might also be interesting for you.
I hope that the compilation process was okay. The parabolic SAR indicator is interesting for people who like to watch charts. But now you should have a working function. That’s it for this video. Thank you and I will see you in the next one.