[ Ссылка ]
In this video we are going to create an expert advisor that is going to trade the Parabolic SAR signal and we are also using the Stochastic Oscillator as a signal filter. So let's find out how to do that with MQL5. To get started, please click on the little button here or press F4 on your keyboard. Now you should see the MetaEditor window. And here we have a precoded version for this expert advisor. We start with an include statement to import the file Trade Mqh. This one comes with MQL5 and we will use it to open positions later on. Let's continue with two more include statements. The first one is for the Check entry module for the Parabolic SAR. That is this module here. And the second one is for the stochastic. We are going to use the stochastic as a filter. And now we want to calculate the ask price and the bid price. That is done by using Symbol info double for the current symbol on the chart.
We use either symbol underscore Ask or symbol underscore bid and with normalize double and underscore digits we make sure to calculate the right number of digits behind the dot. Let's continue and create an instance of the class C trade that will be called Trade. In the on tick function we use MQL rates to create an array called price info. With array set as series we need to sort our Price Info array from the current candle downwards. And now we can use copy rates for the current symbol on the chart and the currently selected period. Starting from candle zero for three candles, we want to store the data in our price info array. And that makes it possible to calculate the current price by looking at the close price for candle zero in our price Info array. Now let's define a trading signal and a filter. And to get the trading signal we will call a function called Check Entry SAR. For the filter it is called Check Entry Stochastic. And if our trading signal equals buy and the filter also equals buy, we want to check if positions total equals zero. That would be the case when we have no open positions. And when this is true and we have a buy signal, we want to use Trade Buy to open a new buy trade for ten microlot for the current symbol on the chart.
In the other case, if the trading signal equals sell, and if the filter also says that we should sell and if we have no open positions, we use trade sell to sell ten microlots. Finally, we use a comment statement to output the trading signal for the parabolic SAR and the filter for the stochastic on our chart. So far so good. But to use this function we need to create the second module. It is called Check Entry SAR. Before we can go to the second module, we need to cut out this part and use it here in the upper part as a global declaration. And the reason is we need the price info array also in our second module here. This one is called Check entry SAR. So is the function here and it will return a string value. Therefore we define a string variable called signal here. We also need to define an array for our SAR signal. And now we can use the Isar function that is included in MQL5.
For the current symbol on the chart and the currently selected period on the chart. These are the standard values that you will see when you drag the parabolic SAR indicator on your chart. And now we use array set as series for our array to sort it from the current candle downwards. And with copy buffer, we can fill our SAR array according to the definition that we have created here. We do that for buffer zero, starting from the current candle zero for three candles. And now we can calculate the last SAR value by looking into our SAR array. We do that for candle one and with normalize double and the value five, we make sure that we create a value that has five digits behind the dot. For this video, I have outcommented the second part. That would make it possible to find crossover values. But for now you can ignore that. For the buy signal we want to check if the last SAR value was below the low price for candle one in our price info array. If that is true, we want to buy. So we assign the word buy to our signal. And for the sell signal we want to check if the last SAR value was bigger than the high price for candle one in our price info array.
![](https://i.ytimg.com/vi/AehyWlNRIXc/maxresdefault.jpg)