(00:00) MQL5 Tutorial – Simple Triple Candle Strategy

  • Introduction to creating a simple strategy in MQL5 that opens a trade after three consecutive bullish candles.

(00:19) Creating an Expert Advisor with MQL5

  • Explanation of how to create an Expert Advisor for this strategy using MQL5.

(00:30) Including Trade.mqh and Initializing CTrade

  • Demonstrating how to include ‘Trade.mqh’ for simplified trading functions and initializing the ‘CTrade’ class.

(00:40) Determining Ask and Bid Prices

  • Calculating the ask and bid prices for the current currency pair using ‘SymbolInfoDouble’ and normalizing them with ‘_Digits’.

(00:59) Calculating Account Balance and Equity

  • Determining the account balance and equity using ‘AccountInfoDouble’ with parameters ‘ACCOUNT_BALANCE’ and ‘ACCOUNT_EQUITY’.

(01:09) Setting Up Price Array

  • Creating and sorting a price array from the current candle downwards using ‘ArraySetAsSeries’.

(01:28) Filling Price Array with Data

  • Filling the price array with data for four candles using ‘CopyRates’.

(01:39) Checking for Bullish Candles

  • Determining if the closing price of the current candle is greater than its opening price to identify a bullish candle.

(01:58) Identifying Three Consecutive Bullish Candles

  • Checking if there are three consecutive bullish candles.

(02:08) Opening a Position

  • Opening a sell position for 10 micro lots if there are no current positions and three bullish candles are identified.

(02:18) Displaying Account Information

  • Using the ‘Comment’ function to display account balance and equity on the chart.

(02:25) Compiling the Expert Advisor

  • Instructions for compiling the Expert Advisor in MetaEditor.

(02:34) Testing the Expert Advisor in MetaTrader

  • Running the newly created Expert Advisor in the MetaTrader Strategy Tester.

(02:54) Observing the Expert Advisor’s Performance

  • Watching the Expert Advisor’s performance in the strategy tester.

(03:07) Additional Learning Resources

  • Suggestion to view other basic videos or consider a premium course for further learning.

(03:20) Conclusion

  • Thanking viewers for watching and inviting them to the next video.


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.