MQL5 TUTORIAL – How to draw arrow symbols on the Chart (explained in 3 min)

 

https://mql5tutorial.com/?arrow

 

In this video, we are going to create an Expert Advisor that places an arrow object on the chart at the medium price between the current Ask and Bid prices. Let’s see how we can do that. We start Metaeditor by clicking the little icon or pressing F4. First, we get the current Ask price using the SymbolInfoDouble function with the SYMBOL_ASK parameter. The NormalizeDouble function is used to format the Ask price to the number of digits specified by _Digits. Next, we get the current Bid price in a similar manner, using the SymbolInfoDouble function with the SYMBOL_BID parameter, and again formatting it with NormalizeDouble. We then calculate the medium price by averaging the Ask and Bid prices. This is done by adding the Ask and Bid prices together and dividing by two. To generate a random number, we initialize the random generator with MathSrand using the current tick count from GetTickCount. We then calculate a random number between 0 and 99 using MathRand and the modulo operator. We create an arrow object named MyObject on the chart using ObjectCreate.

 

The parameters include the symbol, object name, object type (OBJ_ARROW), and the time and price where the object will be placed, which are TimeCurrent and the medium price, respectively. The arrow code for the object is set using ObjectSetInteger with the OBJPROP_ARROWCODE property and the random number generated earlier. We set the size of the arrow object using ObjectSetInteger with the OBJPROP_WIDTH property and a value of 20. The object is moved to the current candle high using ObjectMove, with parameters including the symbol, object name, time, and medium price. Finally, we display a comment on the chart showing the Ask price, Bid price, and medium price using the Comment function. After writing the code, we press F7 to compile it. If this was too fast for you or if you don’t understand what all the code is doing, you may want to check out the Premium course on our website or watch one of the basic videos first.

 

If the compilation works, we go back to MetaTrader by pressing F4 or clicking on the icon. Back in MetaTrader, we press Control and R to start the strategy tester, pick the Expert Advisor that we have just created, enable the visual mode, and start a strategy test. We should see the Expert Advisor on the chart. If you are already a Premium course member and have an idea for a video like this one, you can send us an email. In this video, we have learned how to create an Expert Advisor that places an arrow object on the chart at the medium price between the current Ask and Bid prices with a few lines of MQL code. Thanks for watching, and I will see you in the next video.