MQL5 Tutorial – Simple Buy Trade with MQL5


We want to create a simple buy trade.
If you look over here you can see that hedging is now possible with MQL 5 and we want to use this type of account to create not only one, but more positions.
So let’s start by hitting this little button here (or the F4 key) to bring up the Meta Editor.
This is how to open a buy order in Netting Mode, you have to create a trading request, you will get a trading result afterwards.
Before you open the trade you have to “zeromemory” the request that means basically you empty the memory from old data that you might have used before to open another trade.
Now we would like to use the simplified version so we click on new Expert Advisor and we will call that simple buy trade.
Please click next, next, ready and you can delete all the stuff above the OnTick function.
This is a comment and this can also be deleted. Before we can open our buy trade, we need to know the ask price.
This is how we can get it in MQL 5.
We would also like to see how our equity and our balance looks, so let’s get the balance and the equity of our account, all these are double values.
Double is used for floating point values and that’s actually what we need.
Now we will say “IF” equity is equal or greater our balance, we want to open a buy trade.
Let’s compile that or we have to change this one to greater or equal.
And we will get an error because I have forgotten to import something; we need to include a library and to declare a CTrade.
This is called trade and here we are going to use it to buy.
So now it compiles without any errors.
Let’s see if it works. Let’s change this value to 2016 and start the test.
And here we are, it bought.
Let’s speed it up a little bit, and when the equity becomes greater than the balance that means we are making a profit.
It actually starts to open more trades, so this is full speed and here are all trades we have opened.
We made a net profit of 894 bucks, and this is the graph of our testing.

Download “MQL5 Simple Buy Trade Expert Advisor from MQL5 Tutorial”

SimpleBuyTrade.txt – Downloaded 723 times – 360.00 B