This time we are talking about an indicator that is called the Demarker indicator.
This indicator is also simple to understand.
You have two levels; one level is at 0.3, that’s the lower line here and if the index line is below the lower line, you have a weak trend.
The other line is at a level at 0.7, that’s the upper line here and if the indicator line is above the upper line you have a strong trend.
So if the indicator line is above and crosses the upper line the trend may be over. That is what happened here.
And now we want to create an Expert Advisor that uses the Demarker indicator to tell us if we have a strong trend.
Now how can we do that? First of all please click on the little button over here or hit the F4 key your keyboard.
That will bring up the Meta Editor. And here you want to click on File, New, Expert Advisor from template, Continue and we will call the Expert Advisor Simple Demarker.
Now click on Continue, Continue, Finish, and delete everything above the Ontick function.
I will also remove the two comment lines here and now I need an array that can hold several prices and I call it my price array.
And it’s not necessary to define the properties for the Demarker EA by using the iDemarker function that is included with MQL 5.
It’s a very easy indicator because it only needs the symbol, the period and the period for the Demarker EA.
So we will use underscore symbol for the current chart. Underscore period for the selected time frame on your chart and we want to calculate the Demarker value for fourteen candles, because if you click on Insert, Indicators, Oscillators, Demarker, you will see that fourteen candles is the standard value.
After we have done that we want to use the arraysetasseries function to sort our prices in the array from the current candle downwards.
And then we use copy buffer and the Demarker definition we have created here.
Our indicator has just one line so that’s the first zero here and we need the current candle that’s the second zero, and we want to copy the values of three candles that’s the three here and store our result in our price array.
And now that we have done all this, we want to get the value of the candle zero, that’s the current candle of our price array and store the result in the variable called Demarker value.
And the next thing we need is the chart output depending on the value.
If our Demarker value is above 0.7, we have a strong trend so we use the comment function to output this text on our chart.
And if it is below the lower line, and that would be the case if the Demarker value is below 0.3, we want the text “Weak Trend” on our chart.
And if our value is between the two lines, we don’t have any signal so we will create an empty output.
Okay that’s it, now please hit the compile button here or press the F7 key and you should get zero errors and no warnings here and if everything went right please click on the little button here or press F4 to go back to MetaTrader.
In Meta Trader you want to click on View, Strategy Tester or press control and R on your keyboard to get the Strategy Tester panel up and running and here you want to select the Simple Demarker.ex5 file.
Please don’t forget to enable the visualization mode, pick any period and currency here, and click on start.
And now you can see that our Expert Advisor is working. We have a weak trend because the line is below the lower line here and when we have a strong trend, you see that the line is above the upper line here.
Okay, now you know how to create an Expert Advisor in MQL 5 that uses the Demarker indicator to tell you if a trend is strong or weak and you have created it yourself with a few lines of MQL 5 code.
Download “MQL5 Simple Demarker Trading Robot from MQL5 Tutorial”SimpleDemarker.txt – Downloaded 346 times – 1,004.00 B