mql4-scripts

MQL4 Scripts: The Secret in MetaTrader

The professional traders use MQL4 Scripts. You need it as well

MQL4 scripts, EAs, and trading platform is the first important step in algo trading! My name is Petko Aleksandrov from Trading Academy. And in this video, I will show you exactly how to export the Data for EA Studio (the professional strategy builder).

mql4 scripts to download from EA Studio

Because this is very important when you’re creating strategies over there, and you export them in MetaTrader, to have the same results in MetaTrader backtest, and the same results in your EA studio. Also, I’ll update all previous courses with this video that I am using EA Studio.

Get the MQL4 scripts data for free from us!

MQL4 scripts
The code to export the Historical data

Once you have the MQL4 scripts and you need to copy it. And you need to go to file, open data folder, and you go to MQL4, you go to scripts, and then you paste it. Close the folder, go to scripts, and refresh.

After that, it will show over here. Let’s make it just a little bigger, and I click the plus. This is the script that we are using for EA Studio – EA Studio data export.

That is the script that will export your Forex Data. What you need to do is you click the right button of your mouse, you go to modify, and here you will see all the settings for the EA Studio.

Here are the maximum bars that you would like to export. Here is the spread, and here is the Commission.

These are the three most important things that you need to set up. Now I will minimise that, I will go for example to EURUSD, and I will click right button, and I will click on the spread. Now, you can see the spread for all of your instruments going up and down.

What do you need to do?

trading chart
Variety of instruments with MetaTrader.

Since most of the brokers are having floating spread, as you can see at the moment is 3, is changing to 4, 5 sometimes it’s coming lowered two and to 1. That’s why EA Studio by default it comes with 10. So, the strategies that we will be building, will be skeptical with the highest spread in the data.

This is the worst-case scenario for the spread.

Meaning that the strategies that we will create in EA studio, they will be with the higher spread of 10 and in the normal situation on the average market after that, you will have less spread. Of course, you can set it precisely if your range is stable, but what I suggest to you?

Give it always a little bit bigger. So, the results in the EA studio will be the worst-case scenario for the spread. When you put the Expert Advisor after that in your MetaTrader, you will be expecting better results, because the range will be less. This way, we will have skeptical data.

 The Commission in the MQL4 scripts.

As you see in the account history of this account I have for 0.01 lot size I have 0.06 as a commission. The commission comes from the broker. Not all brokers have commissions. Mostly the ECN brokers have commissions.

But if you have it, you should put it as well in your script. So, you will have precise results. As you can see here what it says in the code is that commission in currency per lot.

So, what I have to write over here is 6. Because 0.06 I have for 0.01, so for 0.1 it will be 0.6 and for one lot size trading, it will be 6. And the other thing again is the spread. If you have the floating spread 5, 6, 7, going to 10, as you can see here the most traded currency they have spread below 10, this is in points. So, I will leave it to 10. And as well I will put the maximum bar to 200.

So once again, you need to set up only the values in red:

  • the maximum bars for the MQL4 scripts
  • the spread
  • the commission
MQL4 scripts
Compile the script with the details filled

After that, you click on compile and your EA studio data export script is ready. So, what I will do? I will click on the EA studio data export, I will drag it over the chart and as you can see all the bars were exported on your EURUSD M1 I have 200 000 bars, and for the others, I have more.

So basically, what you need to do before that, actually if you download it your MetaTrader and you just installed your MetaTrader.

You need to go to all time frames, and you need to press the HOME key of your keyboard.

So you are on M1, press the HOME key, and the chart will be loaded over here. And until the maximum Forex data, you can have from your broker, then you go to M5, and you press the HOME key again. Then go to M15, you press the HOME key, M30, I have already done that.

That’s why it’s not loading anymore, but this is the thing you need to do every time in the beginning. And of course, you need to do it for the rest of the currencies that you want to trade or any other instruments that you wish to trade.

Keep in mind that some pairs have a higher spread. So, if you are trading, for example, these over here, you should be placing at least spread of 20. Or if you have some currency as AUDCHF for instance, I don’t think anybody would be trading AUDCHF, but if you are, you should have spread even above 20. So, after that you go to file, open data folder, you go to MQL4 and to file.

MQL4 scripts
Organise your work in folders

This is the recent EURUSD that we have exported with the MQL4 scripts. So, I will copy that, and I will leave them in a file called Forex data. But you can copy this in any way you wish.

Just collect your data in one folder and after that, guys, what you need to do is actually to test if everything you set is correctly and if you will be receiving the

Same results in your EA studio and the MetaTrader back tester when using the MQL4 scripts.

Forex Historical data import
Import the most recent data to work on

I will go now to EA studio I will click on tools and in data import is where you need to import your data from the folder. These files over here what you need to do, is you select them and you drag them over here in this field. As you can see your data is uploaded over here first is imported then is uploaded. But I see here now a limitation of 100,000. This comes from EA studio. When you go to the data horizon, you can change the maximum data bars to 200,000.

This is the maximum you can have in Expert Advisor Studio. From over here is if you want to use start date limit or use and day limit. And now again I will be importing just the data for M1 and M5 because these were bigger than 100,000.

I will put this one over here, and I will drag this one over here. As you can see on M1, I have 200,000, and on M5 I have 175,578. So, after that I will go to the Generator I have some strategies here in the Collection.

I will remove them, and I will go to the Generator, you select your broker. For this video, I’m using the JFD broker in the demo. And here you choose the currency that you wish, now we import it, let’s see precisely this is the time.

And what I will do right now to show you how essential this Data is?

MQL4 scripts
The generation is a quick process

I will click start, and I wish the generator to create just some strategy. Doesn’t matter what is it, as you can see I have already in the collection some strategy. So, I will stop the generator, and I will click on this strategy. It doesn’t matter what entry conditions it has or exit conditions.

All you need to do is now to export this strategy(not by using MQL4 scripts, but from the EA Studio itself). And I will save it in the folder where is my data, for example.

I will open, and I will copy this strategy, then I will go to my MetaTrader. I’m going again to file, open data folder, I go to MQL4, and I go to experts. Then I will be pasting this strategy over there.

I have a lot of strategies here testing at the moment. So, this is the strategy of M15 ending. Now, I will rename it to make sure I don’t miss taking it. So, I will say just test strategy.

I will close this folder, I will go to experts right over here on the Navigator menu, and I will click on refresh.

Compile Expert Advisors just like compile MQL4 scripts

Once it’s ready I will look for it, let’s make it a little bit bigger. So, I can see where is this test strategy, it’s right over here, but this is on M15, so I go to M15 and

I will put this strategy over the chart to trade

strategies over chart
Drag and drop the strategies over the chart

The first thing you need to see that everything is working. You have the smiley face over here, and of course, you need to wait a little bit to see if your MetaTrader will open the positions. But if you have done everything correctly, it should open them.

And then what you need to do? You click right button, you go to Expert Advisors, and then you go to strategy tester. So, right over here I will select, it’s already there actually. Because I choose it from the chart, it’s your strategy. It’s EURUSD.

The model you need to choose, guys, open price only.

Forex historical data backtest
Open prices are the only trusted model for backtesting.

Every tick model it’s not real from MetaTrader, it’s a great thing to talk about. But I don’t want to speak in this video about it. It’s just the best thing you can do is to test by open prices only. And spread you need to do it the same way that you select it to do it in your script. So, I will choose ten, and I will press Start.

Using the MQL4 scripts properly, allows you to have the same results.

Let’s see what the result is. I think this is very similar to what I had actually in the EA Studio. It’s hard to say because it’s just up and down; this was just the first strategy that we selected. But to make sure we have the same results, I will click on the balance chart and then I will go to the journal.

This is where you see all the results from the strategy. And I will look as well in results over here. This is where you see also the results from MetaTrader. Once again I will open it right over here

Let’s make it the way that we can see both.

the data should match
Results should match

This is in EA studio. As you can see we have the very same results – 52.6. And we have effect after that 71.64. Let’s see lower – 52.36. Is just the same thing.

What you can see sometimes is a difference in the very first trade that you have. Here is 68.33 and here is… Let’s see how much it is. It’s again, -52. This comes because MetaTrader is designed to start the backtesting from the 101 bar. No matter what is the first date on the first bar of your final test. It will just begin to calculating from the 101.

That’s why EA studio back tester is more precise.

Because it starts calculating immediately, but as you can see after that we have the same results. Let’s compare the date, and the time, I will leave it this way.

We ignore the first trade over here, and we focus on the second one. On the second trade, you can see this is 2014, 6th of October 2014, 6th of October at 7:00 hours. So, it’s a short position as you can see the price 125.92, stop loss everything is the same.

All right, guys, this is very important to be done before you start doing anything with your EA studio. So, if you miss entering the Commission here, I would be having the difference of this 0.60 which is precisely actually the Commission in this case with 0.1 and 0.06, as we said if your entry lot is 0.01.

I hope everything is clear. Make sure you set in your EA Studio script exactly the spread and the commission and the maximum bars that you want to export. But once again this video is proof of how good is Expert Advisor Studio as a strategy creator because it shows precisely the same, same entries and exits.

And MetaTrader meaning that the strategies that you are creating, the portfolios that we are doing are the very same thing that has happened. You see immediately here the balance chart, the statistics. After you do this check, you can be sure that the strategies that you create with EA studio, with the Expert Advisor studio are realistic and you can trade on your MetaTrader.

If you have any questions about how to use MQL4 scripts data, you can always write in the support Forum.

Shopping Cart