MQL5 Tutorial - Simple Average True Range Robot with MQL5

MQL5 Tutorial
MQL5 Tutorial
7.4 هزار بار بازدید - 7 سال پیش -
https://mql5tutorial.com/?s=range

With MQL5 for Metatrader5 an Simple Average True Range Robot for the ATR Indicator can be easily created within 5 minutes. The built-in iATR function for MQL5 is easy to use and this indicator will help you to measure the volatility and to decide whether you want to open a new forex trading position...


In this video we are talking about the Average True Range Indicator and we are going to create a little Expert Advisor to calculate if we have a strong or a weak Average True Range value. This is a sideways market and you see that nothing moves, and when nothing moves the ATR value you see here down below has a low value. And here we have bigger movements the ATR value rises, and if you are somebody who wants to get in when the Average True Range is very high you would wait with your trading entry until the value starts to rise because you can expect the markets to make big movements after very slow periods.
And now the ATR value rises and if it rises a little bit more we would see it here on the chart. If it's low it says weak Average True Range value, and if the value is high it would say strong Average True Range value. The Average True Range indicator is also an indicator created by J. Welles Wilder Jr., who created the RSI and the Parabolic SAR indicator. You will find these indicators in other videos of this channel. The ATR indicator will measure the volatility, in our case for fourteen candles. Now how can we create an Expert Advisor for this little indicator? To do that please hit this little button over here to bring up the Meta Editor. And here you want to click on File, New, Expert Advisor from Template, Continue and we will call it Simple Average True Range. Click on Continue, Continue, Finish, and remove everything above the OnTick function. You can also remove these two comment lines and the first thing we need to create is an array that will hold our price data and now we want to define our Expert Advisor by using the iATR function that is built in with MQL 5 for the current symbol on the chart and the selected period on the chart, and we will use fourteen candles because this is what Wilder recommended. And now we would use the function array set as series to sort our price array from the current candle downwards and after that we will use the copy buffer function to fill our price array.
According to our definition we have created here for the first line of the indicator from the current candle zero for three candidates and now we want to get the value of the current candle, that’s candle zero, from the Average True Range value and we will use normalized double to get the five digits we need after the point. And now we need to chart output if the Average True Range value is greater than this we want to output the text strong average range value and the value, and if it's below this value we want to output the text weak Average True Range value and the value, and if it's between this value and this value we don't have a signal so we don't want any text on the chart and we will just output the calculated value here. So let's compile the code and that worked without any errors and any warnings. So let's click this little button over here to change back to Meta Trader and here we want to select View, Strategy Tester and you can also hit the control and the R key. That will bring up the Strategy Tester Panel here and there you want to select the Simple Average True Range.ex5 file. Please mark the visualization option don't here and click on start. And now you should see it running. Please compare the value down here with the calculated value here, it should always match.
Okay now you know how to calculate the Average True Range indicator to use it in one of your Expert Advisors and you did it with a few lines of MQL 5 code.
7 سال پیش در تاریخ 1395/12/02 منتشر شده است.
7,477 بـار بازدید شده
... بیشتر