In this video we are going to create an expert advisor that is able to show account-related information directly on our chart, so let’s find out how to do that with mql4.
To get started please click on a little icon here or press F4 on your keyboard, now you should see the Metaeditor window and here you want to click on file, new file, expert advisor from template, continue, I will call this file, simple account info, click on continue, continue and finish.
Now you can delete everything above the ontick function and the two comment lines here.
We start by getting the account server that is done by using the function account info string, the used parameter is account underscore server, and in my case, it returns the RoboForex ProCent value here.
The next parameter is for the used account currency, you can get that by using account info string account underscore currency and in my case, it’s US dollar.
The next string is for the account name, like before you would use account info string and this parameter account underscore name and in my case, the account name is Raimund Bauer.
The next one is a little bit tricky because the account trade mode is on integer value so it would return a number and whenever I see numbers on the chart that represent something that could be a string value I prefer to use the string value, so let’s create a variable for the readable account trade mode because if you mark that and press F1 you will see that the return type here can either be a demo, a contest or a real account. Demo account equals zero, contest account equals one and the return value two would be a real account. And therefore if the account mode equals zero the readable account trade mode should be demo account. If the return value is one I want to see the text contest account on the chart and in case the value equals two that would be a real account.
Let’s continue with the account info integer value for the account login. If you use account underscore login it will return the account number.
The next one is for account underscore company, this also is a string value and in my case, it returns RoboForex Ltd.
Now let’s get the account leverage, this is account info integer for account underscore leverage and because this is an integer value I see the output five hundred here, actually it would be 1 to 500.
Now let’s get the number of allowed orders and this is a value you can find behind account underscore limit underscore orders. My account allows me to have 200 orders.
We will continue with the free margin, this is the first double value so we use account info double here and it will return the value for account underscore margin underscore free.
The next two values are actually boolean values, so you would probably expect that we use something like account info bool but actually it’s account info integer. Account underscore trade underscore allowed will give us the return value if we are allowed to trade at all and account underscore trade underscore expert will return the value if we are allowed to trade with an expert advisor, in my case both values here return a one and if you mark bool and press F1 you will see that it can return true or false and the numeric representation is one for true and zero for false, so I’m allowed to trade manually and with expert advisors.
Now we have all the values and we want to see them on the chart, so we use a comment statement and create a formatted output here.
Please keep in mind to use the readable account trade mode here and that’s about it.
Well, if this was too fast for you or if you have no idea what all the code here does maybe you want to watch one of the other videos in this basic video series or maybe even the premium course on our website might be interesting for you, for now, please click on the compile button here or press F7 on your keyboard, you shouldn’t get any errors and if this is true please click on a little button here or press F4 to go back to Metatrader.
And in Metatrader we use a clean chart, please open the Navigator window, find the new file with the name, simple account info and drag it on the chart and now you should see your own values here on the chart.
Now let’s change the account number here and now you see that all the values have changed, so our little expert advisor works as designed and in this little video you have learned how to create an expert advisor that is able to output all the account related information on your chart and you have coded it yourself with a few lines of mql4 code.