MQL4 Tutorial Bootcamp – 9 How to create dynamic output on your chart

Okay printing text on a chart is nice, but it doesn’t do anything. I would like to have it a little bit more dynamic so now we are going to change our Expert Advisor.
The Comment function cannot only output text on the chart it can also call other functions. In this case we are calling the Ask function that is included within MQL 4. I will mark that and hit the F1 key to bring up the MetaTrader 4 help and we learn the Ask function will tell us the seller’s price or the Ask price. So now I want my text to be current Ask price is colon followed by the calculated Ask price and if we have done everything right and hit the compiler button we shouldn’t get an error like this one but if we remove the wrong brackets here it should work.

And it does. Looking at the Help file in the example we see okay they also didn’t use brackets because Ask is calculated by another function that is called MarketInfo. MarketInfo has brackets, compile it again zero errors and zero warnings. So we should be able to see the Ask price on our chat now and there we are. The current Ask price is 106.02 and it just changed here, it changes every time a new Tick comes in. So now it’s 106.03. I will now hit the F4 key to go back to the MetaEditor and I would like to see the Bid prize also. So I have added this code here that will also give us a text colon and the current Bid price. Compile it again and when the next Tick comes in we should see the change.
Yes there we are! the current Ask prices 106.01 and the Bid price is 105.98. And now it’s changing. Congratulations now you know how to output dynamic values and text by using the Comment function.