In this video, we are going to create a very simple strategy that will open a trade whenever we have three bullish candles in a row. This is a very simple strategy, but it works actually okay.

So let’s find out how you can create an expert advisor like this one with MQL5.

Let’s take a look at the source code for our expert advisor. We start here with an include command. With this, we import trade.mqh. This is a library that provides simplified trading functions. With this, we can create an instance of the class Ctrade with the name trade. In the function itself, we determine the price using symbol info double for the current currency pair on the chart. We want to determine the ask price and with underscore digits we get in combination with normalized double the correct number of decimal places for the respective currency pair. We repeat the whole thing here again with the bid price. The line is so far identical except for this part where we use symbol underscore bid. We are also interested in the growth balance. We determine this with account info double and here we pass as parameter account_balance. For the net balance called equity, we repeat this again. But in this case we use account underline equity as parameter. After that, we create a price array with the name price info using MQL rates. Using array set as series, we can now sort our price info array from the current candle downward.

And using copy rates, we now fill the price array for the current currency pair and the time unit selected on the chart. We start from candle zero and fill the array with the value for four candles, which we store in our price info array. Why do I use four candles here? Quite simply, in the experiment, you can swap the numbers around here because candle zero is the current candle and the result changes quite a bit if you omit the current candle. For now, we want to find out if the closing price for candle zero in our price info array is greater than the opening price for candle zero. If it is, we have a bullish candle. We then repeat the whole thing again here for the closing prices and the opening prices of candle 1 and candle 2 and immediately, if we have three bullish candles in a row, we want to know if the current number of positions is zero. If it is, then we would like to open a position. To do this, we use trade sell to open a position for 10 micro lot. Finally, we use the comment command to display the value for the balance, that is, the gross balance and the value for the equity on the chart.

That’s about it for the most part. When you’re ready, you can pop up the toolbar here at the top and click compile or press the F7 key. That should work here without any errors. And if it does for you, then you can click on this little icon up here or press F4 to return to Metatrader. Now here we are going to run our new Expert Advisor simple triple bullish candle. If the strategy tester is not displayed, you can show it here via the menu or with the key combination control and R. Let’s start our test. Then you can see here already the first graphical development and you have programmed this yourself with this few lines here in MQL5.

Okay, if everything went well, you should already have the expert advisor running here. I hope it worked for you. If you don’t know what all the MQL5 code means or if this was too fast for you, you maybe want to open one of the other basic videos in our channel, or maybe the premium course on our website might be interesting for you. For now, I would like to say thank you for watching and I will see you in the next video.